diff options
47 files changed, 6603 insertions, 6279 deletions
diff --git a/Documentation/blockdev/drbd/data-structure-v9.txt b/Documentation/blockdev/drbd/data-structure-v9.txt new file mode 100644 index 000000000000..1e52a0e32624 --- /dev/null +++ b/Documentation/blockdev/drbd/data-structure-v9.txt | |||
@@ -0,0 +1,38 @@ | |||
1 | This describes the in kernel data structure for DRBD-9. Starting with | ||
2 | Linux v3.14 we are reorganizing DRBD to use this data structure. | ||
3 | |||
4 | Basic Data Structure | ||
5 | ==================== | ||
6 | |||
7 | A node has a number of DRBD resources. Each such resource has a number of | ||
8 | devices (aka volumes) and connections to other nodes ("peer nodes"). Each DRBD | ||
9 | device is represented by a block device locally. | ||
10 | |||
11 | The DRBD objects are interconnected to form a matrix as depicted below; a | ||
12 | drbd_peer_device object sits at each intersection between a drbd_device and a | ||
13 | drbd_connection: | ||
14 | |||
15 | /--------------+---------------+.....+---------------\ | ||
16 | | resource | device | | device | | ||
17 | +--------------+---------------+.....+---------------+ | ||
18 | | connection | peer_device | | peer_device | | ||
19 | +--------------+---------------+.....+---------------+ | ||
20 | : : : : : | ||
21 | : : : : : | ||
22 | +--------------+---------------+.....+---------------+ | ||
23 | | connection | peer_device | | peer_device | | ||
24 | \--------------+---------------+.....+---------------/ | ||
25 | |||
26 | In this table, horizontally, devices can be accessed from resources by their | ||
27 | volume number. Likewise, peer_devices can be accessed from connections by | ||
28 | their volume number. Objects in the vertical direction are connected by double | ||
29 | linked lists. There are back pointers from peer_devices to their connections a | ||
30 | devices, and from connections and devices to their resource. | ||
31 | |||
32 | All resources are in the drbd_resources double-linked list. In addition, all | ||
33 | devices can be accessed by their minor device number via the drbd_devices idr. | ||
34 | |||
35 | The drbd_resource, drbd_connection, and drbd_device objects are reference | ||
36 | counted. The peer_device objects only serve to establish the links between | ||
37 | devices and connections; their lifetime is determined by the lifetime of the | ||
38 | device and connection which they reference. | ||
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c index eb3950113e42..125d84505738 100644 --- a/drivers/block/DAC960.c +++ b/drivers/block/DAC960.c | |||
@@ -6411,12 +6411,12 @@ static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller, | |||
6411 | .ScatterGatherSegments[0] | 6411 | .ScatterGatherSegments[0] |
6412 | .SegmentByteCount = | 6412 | .SegmentByteCount = |
6413 | CommandMailbox->ControllerInfo.DataTransferSize; | 6413 | CommandMailbox->ControllerInfo.DataTransferSize; |
6414 | DAC960_ExecuteCommand(Command); | 6414 | while (1) { |
6415 | while (Controller->V2.NewControllerInformation->PhysicalScanActive) | 6415 | DAC960_ExecuteCommand(Command); |
6416 | { | 6416 | if (!Controller->V2.NewControllerInformation->PhysicalScanActive) |
6417 | DAC960_ExecuteCommand(Command); | 6417 | break; |
6418 | sleep_on_timeout(&Controller->CommandWaitQueue, HZ); | 6418 | msleep(1000); |
6419 | } | 6419 | } |
6420 | DAC960_UserCritical("Discovery Completed\n", Controller); | 6420 | DAC960_UserCritical("Discovery Completed\n", Controller); |
6421 | } | 6421 | } |
6422 | } | 6422 | } |
@@ -7035,18 +7035,16 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request, | |||
7035 | ErrorCode = -EFAULT; | 7035 | ErrorCode = -EFAULT; |
7036 | break; | 7036 | break; |
7037 | } | 7037 | } |
7038 | while (Controller->V2.HealthStatusBuffer->StatusChangeCounter | 7038 | ErrorCode = wait_event_interruptible_timeout(Controller->HealthStatusWaitQueue, |
7039 | == HealthStatusBuffer.StatusChangeCounter && | 7039 | !(Controller->V2.HealthStatusBuffer->StatusChangeCounter |
7040 | Controller->V2.HealthStatusBuffer->NextEventSequenceNumber | 7040 | == HealthStatusBuffer.StatusChangeCounter && |
7041 | == HealthStatusBuffer.NextEventSequenceNumber) | 7041 | Controller->V2.HealthStatusBuffer->NextEventSequenceNumber |
7042 | { | 7042 | == HealthStatusBuffer.NextEventSequenceNumber), |
7043 | interruptible_sleep_on_timeout(&Controller->HealthStatusWaitQueue, | 7043 | DAC960_MonitoringTimerInterval); |
7044 | DAC960_MonitoringTimerInterval); | 7044 | if (ErrorCode == -ERESTARTSYS) { |
7045 | if (signal_pending(current)) { | 7045 | ErrorCode = -EINTR; |
7046 | ErrorCode = -EINTR; | 7046 | break; |
7047 | break; | 7047 | } |
7048 | } | ||
7049 | } | ||
7050 | if (copy_to_user(GetHealthStatus.HealthStatusBuffer, | 7048 | if (copy_to_user(GetHealthStatus.HealthStatusBuffer, |
7051 | Controller->V2.HealthStatusBuffer, | 7049 | Controller->V2.HealthStatusBuffer, |
7052 | sizeof(DAC960_V2_HealthStatusBuffer_T))) | 7050 | sizeof(DAC960_V2_HealthStatusBuffer_T))) |
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 0e30c6e5492a..96b629e1f0c9 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c | |||
@@ -68,6 +68,8 @@ | |||
68 | #include <linux/init.h> | 68 | #include <linux/init.h> |
69 | #include <linux/blkdev.h> | 69 | #include <linux/blkdev.h> |
70 | #include <linux/mutex.h> | 70 | #include <linux/mutex.h> |
71 | #include <linux/completion.h> | ||
72 | #include <linux/wait.h> | ||
71 | 73 | ||
72 | #include <asm/atafd.h> | 74 | #include <asm/atafd.h> |
73 | #include <asm/atafdreg.h> | 75 | #include <asm/atafdreg.h> |
@@ -301,7 +303,7 @@ module_param_array(UserSteprate, int, NULL, 0); | |||
301 | /* Synchronization of FDC access. */ | 303 | /* Synchronization of FDC access. */ |
302 | static volatile int fdc_busy = 0; | 304 | static volatile int fdc_busy = 0; |
303 | static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); | 305 | static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); |
304 | static DECLARE_WAIT_QUEUE_HEAD(format_wait); | 306 | static DECLARE_COMPLETION(format_wait); |
305 | 307 | ||
306 | static unsigned long changed_floppies = 0xff, fake_change = 0; | 308 | static unsigned long changed_floppies = 0xff, fake_change = 0; |
307 | #define CHECK_CHANGE_DELAY HZ/2 | 309 | #define CHECK_CHANGE_DELAY HZ/2 |
@@ -608,7 +610,7 @@ static void fd_error( void ) | |||
608 | if (IsFormatting) { | 610 | if (IsFormatting) { |
609 | IsFormatting = 0; | 611 | IsFormatting = 0; |
610 | FormatError = 1; | 612 | FormatError = 1; |
611 | wake_up( &format_wait ); | 613 | complete(&format_wait); |
612 | return; | 614 | return; |
613 | } | 615 | } |
614 | 616 | ||
@@ -650,9 +652,8 @@ static int do_format(int drive, int type, struct atari_format_descr *desc) | |||
650 | DPRINT(("do_format( dr=%d tr=%d he=%d offs=%d )\n", | 652 | DPRINT(("do_format( dr=%d tr=%d he=%d offs=%d )\n", |
651 | drive, desc->track, desc->head, desc->sect_offset )); | 653 | drive, desc->track, desc->head, desc->sect_offset )); |
652 | 654 | ||
655 | wait_event(fdc_wait, cmpxchg(&fdc_busy, 0, 1) == 0); | ||
653 | local_irq_save(flags); | 656 | local_irq_save(flags); |
654 | while( fdc_busy ) sleep_on( &fdc_wait ); | ||
655 | fdc_busy = 1; | ||
656 | stdma_lock(floppy_irq, NULL); | 657 | stdma_lock(floppy_irq, NULL); |
657 | atari_turnon_irq( IRQ_MFP_FDC ); /* should be already, just to be sure */ | 658 | atari_turnon_irq( IRQ_MFP_FDC ); /* should be already, just to be sure */ |
658 | local_irq_restore(flags); | 659 | local_irq_restore(flags); |
@@ -706,7 +707,7 @@ static int do_format(int drive, int type, struct atari_format_descr *desc) | |||
706 | ReqSide = desc->head; | 707 | ReqSide = desc->head; |
707 | do_fd_action( drive ); | 708 | do_fd_action( drive ); |
708 | 709 | ||
709 | sleep_on( &format_wait ); | 710 | wait_for_completion(&format_wait); |
710 | 711 | ||
711 | redo_fd_request(); | 712 | redo_fd_request(); |
712 | return( FormatError ? -EIO : 0 ); | 713 | return( FormatError ? -EIO : 0 ); |
@@ -1229,7 +1230,7 @@ static void fd_writetrack_done( int status ) | |||
1229 | goto err_end; | 1230 | goto err_end; |
1230 | } | 1231 | } |
1231 | 1232 | ||
1232 | wake_up( &format_wait ); | 1233 | complete(&format_wait); |
1233 | return; | 1234 | return; |
1234 | 1235 | ||
1235 | err_end: | 1236 | err_end: |
@@ -1497,8 +1498,7 @@ repeat: | |||
1497 | void do_fd_request(struct request_queue * q) | 1498 | void do_fd_request(struct request_queue * q) |
1498 | { | 1499 | { |
1499 | DPRINT(("do_fd_request for pid %d\n",current->pid)); | 1500 | DPRINT(("do_fd_request for pid %d\n",current->pid)); |
1500 | while( fdc_busy ) sleep_on( &fdc_wait ); | 1501 | wait_event(fdc_wait, cmpxchg(&fdc_busy, 0, 1) == 0); |
1501 | fdc_busy = 1; | ||
1502 | stdma_lock(floppy_irq, NULL); | 1502 | stdma_lock(floppy_irq, NULL); |
1503 | 1503 | ||
1504 | atari_disable_irq( IRQ_MFP_FDC ); | 1504 | atari_disable_irq( IRQ_MFP_FDC ); |
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index 036e8ab86c71..73894ca33956 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c | |||
@@ -4092,11 +4092,9 @@ static void cciss_interrupt_mode(ctlr_info_t *h) | |||
4092 | if (err > 0) { | 4092 | if (err > 0) { |
4093 | dev_warn(&h->pdev->dev, | 4093 | dev_warn(&h->pdev->dev, |
4094 | "only %d MSI-X vectors available\n", err); | 4094 | "only %d MSI-X vectors available\n", err); |
4095 | goto default_int_mode; | ||
4096 | } else { | 4095 | } else { |
4097 | dev_warn(&h->pdev->dev, | 4096 | dev_warn(&h->pdev->dev, |
4098 | "MSI-X init failed %d\n", err); | 4097 | "MSI-X init failed %d\n", err); |
4099 | goto default_int_mode; | ||
4100 | } | 4098 | } |
4101 | } | 4099 | } |
4102 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) { | 4100 | if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) { |
diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c index a9b13f2cc420..90ae4ba8f9ee 100644 --- a/drivers/block/drbd/drbd_actlog.c +++ b/drivers/block/drbd/drbd_actlog.c | |||
@@ -95,34 +95,36 @@ struct __packed al_transaction_on_disk { | |||
95 | 95 | ||
96 | struct update_odbm_work { | 96 | struct update_odbm_work { |
97 | struct drbd_work w; | 97 | struct drbd_work w; |
98 | struct drbd_device *device; | ||
98 | unsigned int enr; | 99 | unsigned int enr; |
99 | }; | 100 | }; |
100 | 101 | ||
101 | struct update_al_work { | 102 | struct update_al_work { |
102 | struct drbd_work w; | 103 | struct drbd_work w; |
104 | struct drbd_device *device; | ||
103 | struct completion event; | 105 | struct completion event; |
104 | int err; | 106 | int err; |
105 | }; | 107 | }; |
106 | 108 | ||
107 | 109 | ||
108 | void *drbd_md_get_buffer(struct drbd_conf *mdev) | 110 | void *drbd_md_get_buffer(struct drbd_device *device) |
109 | { | 111 | { |
110 | int r; | 112 | int r; |
111 | 113 | ||
112 | wait_event(mdev->misc_wait, | 114 | wait_event(device->misc_wait, |
113 | (r = atomic_cmpxchg(&mdev->md_io_in_use, 0, 1)) == 0 || | 115 | (r = atomic_cmpxchg(&device->md_io_in_use, 0, 1)) == 0 || |
114 | mdev->state.disk <= D_FAILED); | 116 | device->state.disk <= D_FAILED); |
115 | 117 | ||
116 | return r ? NULL : page_address(mdev->md_io_page); | 118 | return r ? NULL : page_address(device->md_io_page); |
117 | } | 119 | } |
118 | 120 | ||
119 | void drbd_md_put_buffer(struct drbd_conf *mdev) | 121 | void drbd_md_put_buffer(struct drbd_device *device) |
120 | { | 122 | { |
121 | if (atomic_dec_and_test(&mdev->md_io_in_use)) | 123 | if (atomic_dec_and_test(&device->md_io_in_use)) |
122 | wake_up(&mdev->misc_wait); | 124 | wake_up(&device->misc_wait); |
123 | } | 125 | } |
124 | 126 | ||
125 | void wait_until_done_or_force_detached(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, | 127 | void wait_until_done_or_force_detached(struct drbd_device *device, struct drbd_backing_dev *bdev, |
126 | unsigned int *done) | 128 | unsigned int *done) |
127 | { | 129 | { |
128 | long dt; | 130 | long dt; |
@@ -134,15 +136,15 @@ void wait_until_done_or_force_detached(struct drbd_conf *mdev, struct drbd_backi | |||
134 | if (dt == 0) | 136 | if (dt == 0) |
135 | dt = MAX_SCHEDULE_TIMEOUT; | 137 | dt = MAX_SCHEDULE_TIMEOUT; |
136 | 138 | ||
137 | dt = wait_event_timeout(mdev->misc_wait, | 139 | dt = wait_event_timeout(device->misc_wait, |
138 | *done || test_bit(FORCE_DETACH, &mdev->flags), dt); | 140 | *done || test_bit(FORCE_DETACH, &device->flags), dt); |
139 | if (dt == 0) { | 141 | if (dt == 0) { |
140 | dev_err(DEV, "meta-data IO operation timed out\n"); | 142 | drbd_err(device, "meta-data IO operation timed out\n"); |
141 | drbd_chk_io_error(mdev, 1, DRBD_FORCE_DETACH); | 143 | drbd_chk_io_error(device, 1, DRBD_FORCE_DETACH); |
142 | } | 144 | } |
143 | } | 145 | } |
144 | 146 | ||
145 | static int _drbd_md_sync_page_io(struct drbd_conf *mdev, | 147 | static int _drbd_md_sync_page_io(struct drbd_device *device, |
146 | struct drbd_backing_dev *bdev, | 148 | struct drbd_backing_dev *bdev, |
147 | struct page *page, sector_t sector, | 149 | struct page *page, sector_t sector, |
148 | int rw, int size) | 150 | int rw, int size) |
@@ -150,10 +152,10 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev, | |||
150 | struct bio *bio; | 152 | struct bio *bio; |
151 | int err; | 153 | int err; |
152 | 154 | ||
153 | mdev->md_io.done = 0; | 155 | device->md_io.done = 0; |
154 | mdev->md_io.error = -ENODEV; | 156 | device->md_io.error = -ENODEV; |
155 | 157 | ||
156 | if ((rw & WRITE) && !test_bit(MD_NO_FUA, &mdev->flags)) | 158 | if ((rw & WRITE) && !test_bit(MD_NO_FUA, &device->flags)) |
157 | rw |= REQ_FUA | REQ_FLUSH; | 159 | rw |= REQ_FUA | REQ_FLUSH; |
158 | rw |= REQ_SYNC; | 160 | rw |= REQ_SYNC; |
159 | 161 | ||
@@ -163,69 +165,69 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev, | |||
163 | err = -EIO; | 165 | err = -EIO; |
164 | if (bio_add_page(bio, page, size, 0) != size) | 166 | if (bio_add_page(bio, page, size, 0) != size) |
165 | goto out; | 167 | goto out; |
166 | bio->bi_private = &mdev->md_io; | 168 | bio->bi_private = &device->md_io; |
167 | bio->bi_end_io = drbd_md_io_complete; | 169 | bio->bi_end_io = drbd_md_io_complete; |
168 | bio->bi_rw = rw; | 170 | bio->bi_rw = rw; |
169 | 171 | ||
170 | if (!(rw & WRITE) && mdev->state.disk == D_DISKLESS && mdev->ldev == NULL) | 172 | if (!(rw & WRITE) && device->state.disk == D_DISKLESS && device->ldev == NULL) |
171 | /* special case, drbd_md_read() during drbd_adm_attach(): no get_ldev */ | 173 | /* special case, drbd_md_read() during drbd_adm_attach(): no get_ldev */ |
172 | ; | 174 | ; |
173 | else if (!get_ldev_if_state(mdev, D_ATTACHING)) { | 175 | else if (!get_ldev_if_state(device, D_ATTACHING)) { |
174 | /* Corresponding put_ldev in drbd_md_io_complete() */ | 176 | /* Corresponding put_ldev in drbd_md_io_complete() */ |
175 | dev_err(DEV, "ASSERT FAILED: get_ldev_if_state() == 1 in _drbd_md_sync_page_io()\n"); | 177 | drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in _drbd_md_sync_page_io()\n"); |
176 | err = -ENODEV; | 178 | err = -ENODEV; |
177 | goto out; | 179 | goto out; |
178 | } | 180 | } |
179 | 181 | ||
180 | bio_get(bio); /* one bio_put() is in the completion handler */ | 182 | bio_get(bio); /* one bio_put() is in the completion handler */ |
181 | atomic_inc(&mdev->md_io_in_use); /* drbd_md_put_buffer() is in the completion handler */ | 183 | atomic_inc(&device->md_io_in_use); /* drbd_md_put_buffer() is in the completion handler */ |
182 | if (drbd_insert_fault(mdev, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD)) | 184 | if (drbd_insert_fault(device, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD)) |
183 | bio_endio(bio, -EIO); | 185 | bio_endio(bio, -EIO); |
184 | else | 186 | else |
185 | submit_bio(rw, bio); | 187 | submit_bio(rw, bio); |
186 | wait_until_done_or_force_detached(mdev, bdev, &mdev->md_io.done); | 188 | wait_until_done_or_force_detached(device, bdev, &device->md_io.done); |
187 | if (bio_flagged(bio, BIO_UPTODATE)) | 189 | if (bio_flagged(bio, BIO_UPTODATE)) |
188 | err = mdev->md_io.error; | 190 | err = device->md_io.error; |
189 | 191 | ||
190 | out: | 192 | out: |
191 | bio_put(bio); | 193 | bio_put(bio); |
192 | return err; | 194 | return err; |
193 | } | 195 | } |
194 | 196 | ||
195 | int drbd_md_sync_page_io(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, | 197 | int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bdev, |
196 | sector_t sector, int rw) | 198 | sector_t sector, int rw) |
197 | { | 199 | { |
198 | int err; | 200 | int err; |
199 | struct page *iop = mdev->md_io_page; | 201 | struct page *iop = device->md_io_page; |
200 | 202 | ||
201 | D_ASSERT(atomic_read(&mdev->md_io_in_use) == 1); | 203 | D_ASSERT(device, atomic_read(&device->md_io_in_use) == 1); |
202 | 204 | ||
203 | BUG_ON(!bdev->md_bdev); | 205 | BUG_ON(!bdev->md_bdev); |
204 | 206 | ||
205 | dev_dbg(DEV, "meta_data io: %s [%d]:%s(,%llus,%s) %pS\n", | 207 | drbd_dbg(device, "meta_data io: %s [%d]:%s(,%llus,%s) %pS\n", |
206 | current->comm, current->pid, __func__, | 208 | current->comm, current->pid, __func__, |
207 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", | 209 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", |
208 | (void*)_RET_IP_ ); | 210 | (void*)_RET_IP_ ); |
209 | 211 | ||
210 | if (sector < drbd_md_first_sector(bdev) || | 212 | if (sector < drbd_md_first_sector(bdev) || |
211 | sector + 7 > drbd_md_last_sector(bdev)) | 213 | sector + 7 > drbd_md_last_sector(bdev)) |
212 | dev_alert(DEV, "%s [%d]:%s(,%llus,%s) out of range md access!\n", | 214 | drbd_alert(device, "%s [%d]:%s(,%llus,%s) out of range md access!\n", |
213 | current->comm, current->pid, __func__, | 215 | current->comm, current->pid, __func__, |
214 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ"); | 216 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ"); |
215 | 217 | ||
216 | /* we do all our meta data IO in aligned 4k blocks. */ | 218 | /* we do all our meta data IO in aligned 4k blocks. */ |
217 | err = _drbd_md_sync_page_io(mdev, bdev, iop, sector, rw, 4096); | 219 | err = _drbd_md_sync_page_io(device, bdev, iop, sector, rw, 4096); |
218 | if (err) { | 220 | if (err) { |
219 | dev_err(DEV, "drbd_md_sync_page_io(,%llus,%s) failed with error %d\n", | 221 | drbd_err(device, "drbd_md_sync_page_io(,%llus,%s) failed with error %d\n", |
220 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", err); | 222 | (unsigned long long)sector, (rw & WRITE) ? "WRITE" : "READ", err); |
221 | } | 223 | } |
222 | return err; | 224 | return err; |
223 | } | 225 | } |
224 | 226 | ||
225 | static struct bm_extent *find_active_resync_extent(struct drbd_conf *mdev, unsigned int enr) | 227 | static struct bm_extent *find_active_resync_extent(struct drbd_device *device, unsigned int enr) |
226 | { | 228 | { |
227 | struct lc_element *tmp; | 229 | struct lc_element *tmp; |
228 | tmp = lc_find(mdev->resync, enr/AL_EXT_PER_BM_SECT); | 230 | tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT); |
229 | if (unlikely(tmp != NULL)) { | 231 | if (unlikely(tmp != NULL)) { |
230 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); | 232 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
231 | if (test_bit(BME_NO_WRITES, &bm_ext->flags)) | 233 | if (test_bit(BME_NO_WRITES, &bm_ext->flags)) |
@@ -234,47 +236,48 @@ static struct bm_extent *find_active_resync_extent(struct drbd_conf *mdev, unsig | |||
234 | return NULL; | 236 | return NULL; |
235 | } | 237 | } |
236 | 238 | ||
237 | static struct lc_element *_al_get(struct drbd_conf *mdev, unsigned int enr, bool nonblock) | 239 | static struct lc_element *_al_get(struct drbd_device *device, unsigned int enr, bool nonblock) |
238 | { | 240 | { |
239 | struct lc_element *al_ext; | 241 | struct lc_element *al_ext; |
240 | struct bm_extent *bm_ext; | 242 | struct bm_extent *bm_ext; |
241 | int wake; | 243 | int wake; |
242 | 244 | ||
243 | spin_lock_irq(&mdev->al_lock); | 245 | spin_lock_irq(&device->al_lock); |
244 | bm_ext = find_active_resync_extent(mdev, enr); | 246 | bm_ext = find_active_resync_extent(device, enr); |
245 | if (bm_ext) { | 247 | if (bm_ext) { |
246 | wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags); | 248 | wake = !test_and_set_bit(BME_PRIORITY, &bm_ext->flags); |
247 | spin_unlock_irq(&mdev->al_lock); | 249 | spin_unlock_irq(&device->al_lock); |
248 | if (wake) | 250 | if (wake) |
249 | wake_up(&mdev->al_wait); | 251 | wake_up(&device->al_wait); |
250 | return NULL; | 252 | return NULL; |
251 | } | 253 | } |
252 | if (nonblock) | 254 | if (nonblock) |
253 | al_ext = lc_try_get(mdev->act_log, enr); | 255 | al_ext = lc_try_get(device->act_log, enr); |
254 | else | 256 | else |
255 | al_ext = lc_get(mdev->act_log, enr); | 257 | al_ext = lc_get(device->act_log, enr); |
256 | spin_unlock_irq(&mdev->al_lock); | 258 | spin_unlock_irq(&device->al_lock); |
257 | return al_ext; | 259 | return al_ext; |
258 | } | 260 | } |
259 | 261 | ||
260 | bool drbd_al_begin_io_fastpath(struct drbd_conf *mdev, struct drbd_interval *i) | 262 | bool drbd_al_begin_io_fastpath(struct drbd_device *device, struct drbd_interval *i) |
261 | { | 263 | { |
262 | /* for bios crossing activity log extent boundaries, | 264 | /* for bios crossing activity log extent boundaries, |
263 | * we may need to activate two extents in one go */ | 265 | * we may need to activate two extents in one go */ |
264 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); | 266 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); |
265 | unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); | 267 | unsigned last = i->size == 0 ? first : (i->sector + (i->size >> 9) - 1) >> (AL_EXTENT_SHIFT-9); |
266 | 268 | ||
267 | D_ASSERT((unsigned)(last - first) <= 1); | 269 | D_ASSERT(device, (unsigned)(last - first) <= 1); |
268 | D_ASSERT(atomic_read(&mdev->local_cnt) > 0); | 270 | D_ASSERT(device, atomic_read(&device->local_cnt) > 0); |
269 | 271 | ||
270 | /* FIXME figure out a fast path for bios crossing AL extent boundaries */ | 272 | /* FIXME figure out a fast path for bios crossing AL extent boundaries */ |
271 | if (first != last) | 273 | if (first != last) |
272 | return false; | 274 | return false; |
273 | 275 | ||
274 | return _al_get(mdev, first, true); | 276 | return _al_get(device, first, true); |
275 | } | 277 | } |
276 | 278 | ||
277 | bool drbd_al_begin_io_prepare(struct drbd_conf *mdev, struct drbd_interval *i) | 279 | static |
280 | bool drbd_al_begin_io_prepare(struct drbd_device *device, struct drbd_interval *i) | ||
278 | { | 281 | { |
279 | /* for bios crossing activity log extent boundaries, | 282 | /* for bios crossing activity log extent boundaries, |
280 | * we may need to activate two extents in one go */ | 283 | * we may need to activate two extents in one go */ |
@@ -283,20 +286,20 @@ bool drbd_al_begin_io_prepare(struct drbd_conf *mdev, struct drbd_interval *i) | |||
283 | unsigned enr; | 286 | unsigned enr; |
284 | bool need_transaction = false; | 287 | bool need_transaction = false; |
285 | 288 | ||
286 | D_ASSERT(first <= last); | 289 | D_ASSERT(device, first <= last); |
287 | D_ASSERT(atomic_read(&mdev->local_cnt) > 0); | 290 | D_ASSERT(device, atomic_read(&device->local_cnt) > 0); |
288 | 291 | ||
289 | for (enr = first; enr <= last; enr++) { | 292 | for (enr = first; enr <= last; enr++) { |
290 | struct lc_element *al_ext; | 293 | struct lc_element *al_ext; |
291 | wait_event(mdev->al_wait, | 294 | wait_event(device->al_wait, |
292 | (al_ext = _al_get(mdev, enr, false)) != NULL); | 295 | (al_ext = _al_get(device, enr, false)) != NULL); |
293 | if (al_ext->lc_number != enr) | 296 | if (al_ext->lc_number != enr) |
294 | need_transaction = true; | 297 | need_transaction = true; |
295 | } | 298 | } |
296 | return need_transaction; | 299 | return need_transaction; |
297 | } | 300 | } |
298 | 301 | ||
299 | static int al_write_transaction(struct drbd_conf *mdev, bool delegate); | 302 | static int al_write_transaction(struct drbd_device *device, bool delegate); |
300 | 303 | ||
301 | /* When called through generic_make_request(), we must delegate | 304 | /* When called through generic_make_request(), we must delegate |
302 | * activity log I/O to the worker thread: a further request | 305 | * activity log I/O to the worker thread: a further request |
@@ -310,58 +313,58 @@ static int al_write_transaction(struct drbd_conf *mdev, bool delegate); | |||
310 | /* | 313 | /* |
311 | * @delegate: delegate activity log I/O to the worker thread | 314 | * @delegate: delegate activity log I/O to the worker thread |
312 | */ | 315 | */ |
313 | void drbd_al_begin_io_commit(struct drbd_conf *mdev, bool delegate) | 316 | void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate) |
314 | { | 317 | { |
315 | bool locked = false; | 318 | bool locked = false; |
316 | 319 | ||
317 | BUG_ON(delegate && current == mdev->tconn->worker.task); | 320 | BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task); |
318 | 321 | ||
319 | /* Serialize multiple transactions. | 322 | /* Serialize multiple transactions. |
320 | * This uses test_and_set_bit, memory barrier is implicit. | 323 | * This uses test_and_set_bit, memory barrier is implicit. |
321 | */ | 324 | */ |
322 | wait_event(mdev->al_wait, | 325 | wait_event(device->al_wait, |
323 | mdev->act_log->pending_changes == 0 || | 326 | device->act_log->pending_changes == 0 || |
324 | (locked = lc_try_lock_for_transaction(mdev->act_log))); | 327 | (locked = lc_try_lock_for_transaction(device->act_log))); |
325 | 328 | ||
326 | if (locked) { | 329 | if (locked) { |
327 | /* Double check: it may have been committed by someone else, | 330 | /* Double check: it may have been committed by someone else, |
328 | * while we have been waiting for the lock. */ | 331 | * while we have been waiting for the lock. */ |
329 | if (mdev->act_log->pending_changes) { | 332 | if (device->act_log->pending_changes) { |
330 | bool write_al_updates; | 333 | bool write_al_updates; |
331 | 334 | ||
332 | rcu_read_lock(); | 335 | rcu_read_lock(); |
333 | write_al_updates = rcu_dereference(mdev->ldev->disk_conf)->al_updates; | 336 | write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates; |
334 | rcu_read_unlock(); | 337 | rcu_read_unlock(); |
335 | 338 | ||
336 | if (write_al_updates) | 339 | if (write_al_updates) |
337 | al_write_transaction(mdev, delegate); | 340 | al_write_transaction(device, delegate); |
338 | spin_lock_irq(&mdev->al_lock); | 341 | spin_lock_irq(&device->al_lock); |
339 | /* FIXME | 342 | /* FIXME |
340 | if (err) | 343 | if (err) |
341 | we need an "lc_cancel" here; | 344 | we need an "lc_cancel" here; |
342 | */ | 345 | */ |
343 | lc_committed(mdev->act_log); | 346 | lc_committed(device->act_log); |
344 | spin_unlock_irq(&mdev->al_lock); | 347 | spin_unlock_irq(&device->al_lock); |
345 | } | 348 | } |
346 | lc_unlock(mdev->act_log); | 349 | lc_unlock(device->act_log); |
347 | wake_up(&mdev->al_wait); | 350 | wake_up(&device->al_wait); |
348 | } | 351 | } |
349 | } | 352 | } |
350 | 353 | ||
351 | /* | 354 | /* |
352 | * @delegate: delegate activity log I/O to the worker thread | 355 | * @delegate: delegate activity log I/O to the worker thread |
353 | */ | 356 | */ |
354 | void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i, bool delegate) | 357 | void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate) |
355 | { | 358 | { |
356 | BUG_ON(delegate && current == mdev->tconn->worker.task); | 359 | BUG_ON(delegate && current == first_peer_device(device)->connection->worker.task); |
357 | 360 | ||
358 | if (drbd_al_begin_io_prepare(mdev, i)) | 361 | if (drbd_al_begin_io_prepare(device, i)) |
359 | drbd_al_begin_io_commit(mdev, delegate); | 362 | drbd_al_begin_io_commit(device, delegate); |
360 | } | 363 | } |
361 | 364 | ||
362 | int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i) | 365 | int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i) |
363 | { | 366 | { |
364 | struct lru_cache *al = mdev->act_log; | 367 | struct lru_cache *al = device->act_log; |
365 | /* for bios crossing activity log extent boundaries, | 368 | /* for bios crossing activity log extent boundaries, |
366 | * we may need to activate two extents in one go */ | 369 | * we may need to activate two extents in one go */ |
367 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); | 370 | unsigned first = i->sector >> (AL_EXTENT_SHIFT-9); |
@@ -370,7 +373,7 @@ int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i) | |||
370 | unsigned available_update_slots; | 373 | unsigned available_update_slots; |
371 | unsigned enr; | 374 | unsigned enr; |
372 | 375 | ||
373 | D_ASSERT(first <= last); | 376 | D_ASSERT(device, first <= last); |
374 | 377 | ||
375 | nr_al_extents = 1 + last - first; /* worst case: all touched extends are cold. */ | 378 | nr_al_extents = 1 + last - first; /* worst case: all touched extends are cold. */ |
376 | available_update_slots = min(al->nr_elements - al->used, | 379 | available_update_slots = min(al->nr_elements - al->used, |
@@ -385,7 +388,7 @@ int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i) | |||
385 | /* Is resync active in this area? */ | 388 | /* Is resync active in this area? */ |
386 | for (enr = first; enr <= last; enr++) { | 389 | for (enr = first; enr <= last; enr++) { |
387 | struct lc_element *tmp; | 390 | struct lc_element *tmp; |
388 | tmp = lc_find(mdev->resync, enr/AL_EXT_PER_BM_SECT); | 391 | tmp = lc_find(device->resync, enr/AL_EXT_PER_BM_SECT); |
389 | if (unlikely(tmp != NULL)) { | 392 | if (unlikely(tmp != NULL)) { |
390 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); | 393 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
391 | if (test_bit(BME_NO_WRITES, &bm_ext->flags)) { | 394 | if (test_bit(BME_NO_WRITES, &bm_ext->flags)) { |
@@ -401,14 +404,14 @@ int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i) | |||
401 | * this has to be successful. */ | 404 | * this has to be successful. */ |
402 | for (enr = first; enr <= last; enr++) { | 405 | for (enr = first; enr <= last; enr++) { |
403 | struct lc_element *al_ext; | 406 | struct lc_element *al_ext; |
404 | al_ext = lc_get_cumulative(mdev->act_log, enr); | 407 | al_ext = lc_get_cumulative(device->act_log, enr); |
405 | if (!al_ext) | 408 | if (!al_ext) |
406 | dev_info(DEV, "LOGIC BUG for enr=%u\n", enr); | 409 | drbd_info(device, "LOGIC BUG for enr=%u\n", enr); |
407 | } | 410 | } |
408 | return 0; | 411 | return 0; |
409 | } | 412 | } |
410 | 413 | ||
411 | void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i) | 414 | void drbd_al_complete_io(struct drbd_device *device, struct drbd_interval *i) |
412 | { | 415 | { |
413 | /* for bios crossing activity log extent boundaries, | 416 | /* for bios crossing activity log extent boundaries, |
414 | * we may need to activate two extents in one go */ | 417 | * we may need to activate two extents in one go */ |
@@ -418,19 +421,19 @@ void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i) | |||
418 | struct lc_element *extent; | 421 | struct lc_element *extent; |
419 | unsigned long flags; | 422 | unsigned long flags; |
420 | 423 | ||
421 | D_ASSERT(first <= last); | 424 | D_ASSERT(device, first <= last); |
422 | spin_lock_irqsave(&mdev->al_lock, flags); | 425 | spin_lock_irqsave(&device->al_lock, flags); |
423 | 426 | ||
424 | for (enr = first; enr <= last; enr++) { | 427 | for (enr = first; enr <= last; enr++) { |
425 | extent = lc_find(mdev->act_log, enr); | 428 | extent = lc_find(device->act_log, enr); |
426 | if (!extent) { | 429 | if (!extent) { |
427 | dev_err(DEV, "al_complete_io() called on inactive extent %u\n", enr); | 430 | drbd_err(device, "al_complete_io() called on inactive extent %u\n", enr); |
428 | continue; | 431 | continue; |
429 | } | 432 | } |
430 | lc_put(mdev->act_log, extent); | 433 | lc_put(device->act_log, extent); |
431 | } | 434 | } |
432 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 435 | spin_unlock_irqrestore(&device->al_lock, flags); |
433 | wake_up(&mdev->al_wait); | 436 | wake_up(&device->al_wait); |
434 | } | 437 | } |
435 | 438 | ||
436 | #if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT) | 439 | #if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT) |
@@ -460,13 +463,13 @@ static unsigned int rs_extent_to_bm_page(unsigned int rs_enr) | |||
460 | (BM_EXT_SHIFT - BM_BLOCK_SHIFT)); | 463 | (BM_EXT_SHIFT - BM_BLOCK_SHIFT)); |
461 | } | 464 | } |
462 | 465 | ||
463 | static sector_t al_tr_number_to_on_disk_sector(struct drbd_conf *mdev) | 466 | static sector_t al_tr_number_to_on_disk_sector(struct drbd_device *device) |
464 | { | 467 | { |
465 | const unsigned int stripes = mdev->ldev->md.al_stripes; | 468 | const unsigned int stripes = device->ldev->md.al_stripes; |
466 | const unsigned int stripe_size_4kB = mdev->ldev->md.al_stripe_size_4k; | 469 | const unsigned int stripe_size_4kB = device->ldev->md.al_stripe_size_4k; |
467 | 470 | ||
468 | /* transaction number, modulo on-disk ring buffer wrap around */ | 471 | /* transaction number, modulo on-disk ring buffer wrap around */ |
469 | unsigned int t = mdev->al_tr_number % (mdev->ldev->md.al_size_4k); | 472 | unsigned int t = device->al_tr_number % (device->ldev->md.al_size_4k); |
470 | 473 | ||
471 | /* ... to aligned 4k on disk block */ | 474 | /* ... to aligned 4k on disk block */ |
472 | t = ((t % stripes) * stripe_size_4kB) + t/stripes; | 475 | t = ((t % stripes) * stripe_size_4kB) + t/stripes; |
@@ -475,11 +478,11 @@ static sector_t al_tr_number_to_on_disk_sector(struct drbd_conf *mdev) | |||
475 | t *= 8; | 478 | t *= 8; |
476 | 479 | ||
477 | /* ... plus offset to the on disk position */ | 480 | /* ... plus offset to the on disk position */ |
478 | return mdev->ldev->md.md_offset + mdev->ldev->md.al_offset + t; | 481 | return device->ldev->md.md_offset + device->ldev->md.al_offset + t; |
479 | } | 482 | } |
480 | 483 | ||
481 | static int | 484 | static int |
482 | _al_write_transaction(struct drbd_conf *mdev) | 485 | _al_write_transaction(struct drbd_device *device) |
483 | { | 486 | { |
484 | struct al_transaction_on_disk *buffer; | 487 | struct al_transaction_on_disk *buffer; |
485 | struct lc_element *e; | 488 | struct lc_element *e; |
@@ -489,31 +492,31 @@ _al_write_transaction(struct drbd_conf *mdev) | |||
489 | unsigned crc = 0; | 492 | unsigned crc = 0; |
490 | int err = 0; | 493 | int err = 0; |
491 | 494 | ||
492 | if (!get_ldev(mdev)) { | 495 | if (!get_ldev(device)) { |
493 | dev_err(DEV, "disk is %s, cannot start al transaction\n", | 496 | drbd_err(device, "disk is %s, cannot start al transaction\n", |
494 | drbd_disk_str(mdev->state.disk)); | 497 | drbd_disk_str(device->state.disk)); |
495 | return -EIO; | 498 | return -EIO; |
496 | } | 499 | } |
497 | 500 | ||
498 | /* The bitmap write may have failed, causing a state change. */ | 501 | /* The bitmap write may have failed, causing a state change. */ |
499 | if (mdev->state.disk < D_INCONSISTENT) { | 502 | if (device->state.disk < D_INCONSISTENT) { |
500 | dev_err(DEV, | 503 | drbd_err(device, |
501 | "disk is %s, cannot write al transaction\n", | 504 | "disk is %s, cannot write al transaction\n", |
502 | drbd_disk_str(mdev->state.disk)); | 505 | drbd_disk_str(device->state.disk)); |
503 | put_ldev(mdev); | 506 | put_ldev(device); |
504 | return -EIO; | 507 | return -EIO; |
505 | } | 508 | } |
506 | 509 | ||
507 | buffer = drbd_md_get_buffer(mdev); /* protects md_io_buffer, al_tr_cycle, ... */ | 510 | buffer = drbd_md_get_buffer(device); /* protects md_io_buffer, al_tr_cycle, ... */ |
508 | if (!buffer) { | 511 | if (!buffer) { |
509 | dev_err(DEV, "disk failed while waiting for md_io buffer\n"); | 512 | drbd_err(device, "disk failed while waiting for md_io buffer\n"); |
510 | put_ldev(mdev); | 513 | put_ldev(device); |
511 | return -ENODEV; | 514 | return -ENODEV; |
512 | } | 515 | } |
513 | 516 | ||
514 | memset(buffer, 0, sizeof(*buffer)); | 517 | memset(buffer, 0, sizeof(*buffer)); |
515 | buffer->magic = cpu_to_be32(DRBD_AL_MAGIC); | 518 | buffer->magic = cpu_to_be32(DRBD_AL_MAGIC); |
516 | buffer->tr_number = cpu_to_be32(mdev->al_tr_number); | 519 | buffer->tr_number = cpu_to_be32(device->al_tr_number); |
517 | 520 | ||
518 | i = 0; | 521 | i = 0; |
519 | 522 | ||
@@ -521,8 +524,8 @@ _al_write_transaction(struct drbd_conf *mdev) | |||
521 | * once we set the LC_LOCKED -- from drbd_al_begin_io(), | 524 | * once we set the LC_LOCKED -- from drbd_al_begin_io(), |
522 | * lc_try_lock_for_transaction() --, someone may still | 525 | * lc_try_lock_for_transaction() --, someone may still |
523 | * be in the process of changing it. */ | 526 | * be in the process of changing it. */ |
524 | spin_lock_irq(&mdev->al_lock); | 527 | spin_lock_irq(&device->al_lock); |
525 | list_for_each_entry(e, &mdev->act_log->to_be_changed, list) { | 528 | list_for_each_entry(e, &device->act_log->to_be_changed, list) { |
526 | if (i == AL_UPDATES_PER_TRANSACTION) { | 529 | if (i == AL_UPDATES_PER_TRANSACTION) { |
527 | i++; | 530 | i++; |
528 | break; | 531 | break; |
@@ -530,11 +533,11 @@ _al_write_transaction(struct drbd_conf *mdev) | |||
530 | buffer->update_slot_nr[i] = cpu_to_be16(e->lc_index); | 533 | buffer->update_slot_nr[i] = cpu_to_be16(e->lc_index); |
531 | buffer->update_extent_nr[i] = cpu_to_be32(e->lc_new_number); | 534 | buffer->update_extent_nr[i] = cpu_to_be32(e->lc_new_number); |
532 | if (e->lc_number != LC_FREE) | 535 | if (e->lc_number != LC_FREE) |
533 | drbd_bm_mark_for_writeout(mdev, | 536 | drbd_bm_mark_for_writeout(device, |
534 | al_extent_to_bm_page(e->lc_number)); | 537 | al_extent_to_bm_page(e->lc_number)); |
535 | i++; | 538 | i++; |
536 | } | 539 | } |
537 | spin_unlock_irq(&mdev->al_lock); | 540 | spin_unlock_irq(&device->al_lock); |
538 | BUG_ON(i > AL_UPDATES_PER_TRANSACTION); | 541 | BUG_ON(i > AL_UPDATES_PER_TRANSACTION); |
539 | 542 | ||
540 | buffer->n_updates = cpu_to_be16(i); | 543 | buffer->n_updates = cpu_to_be16(i); |
@@ -543,48 +546,48 @@ _al_write_transaction(struct drbd_conf *mdev) | |||
543 | buffer->update_extent_nr[i] = cpu_to_be32(LC_FREE); | 546 | buffer->update_extent_nr[i] = cpu_to_be32(LC_FREE); |
544 | } | 547 | } |
545 | 548 | ||
546 | buffer->context_size = cpu_to_be16(mdev->act_log->nr_elements); | 549 | buffer->context_size = cpu_to_be16(device->act_log->nr_elements); |
547 | buffer->context_start_slot_nr = cpu_to_be16(mdev->al_tr_cycle); | 550 | buffer->context_start_slot_nr = cpu_to_be16(device->al_tr_cycle); |
548 | 551 | ||
549 | mx = min_t(int, AL_CONTEXT_PER_TRANSACTION, | 552 | mx = min_t(int, AL_CONTEXT_PER_TRANSACTION, |
550 | mdev->act_log->nr_elements - mdev->al_tr_cycle); | 553 | device->act_log->nr_elements - device->al_tr_cycle); |
551 | for (i = 0; i < mx; i++) { | 554 | for (i = 0; i < mx; i++) { |
552 | unsigned idx = mdev->al_tr_cycle + i; | 555 | unsigned idx = device->al_tr_cycle + i; |
553 | extent_nr = lc_element_by_index(mdev->act_log, idx)->lc_number; | 556 | extent_nr = lc_element_by_index(device->act_log, idx)->lc_number; |
554 | buffer->context[i] = cpu_to_be32(extent_nr); | 557 | buffer->context[i] = cpu_to_be32(extent_nr); |
555 | } | 558 | } |
556 | for (; i < AL_CONTEXT_PER_TRANSACTION; i++) | 559 | for (; i < AL_CONTEXT_PER_TRANSACTION; i++) |
557 | buffer->context[i] = cpu_to_be32(LC_FREE); | 560 | buffer->context[i] = cpu_to_be32(LC_FREE); |
558 | 561 | ||
559 | mdev->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION; | 562 | device->al_tr_cycle += AL_CONTEXT_PER_TRANSACTION; |
560 | if (mdev->al_tr_cycle >= mdev->act_log->nr_elements) | 563 | if (device->al_tr_cycle >= device->act_log->nr_elements) |
561 | mdev->al_tr_cycle = 0; | 564 | device->al_tr_cycle = 0; |
562 | 565 | ||
563 | sector = al_tr_number_to_on_disk_sector(mdev); | 566 | sector = al_tr_number_to_on_disk_sector(device); |
564 | 567 | ||
565 | crc = crc32c(0, buffer, 4096); | 568 | crc = crc32c(0, buffer, 4096); |
566 | buffer->crc32c = cpu_to_be32(crc); | 569 | buffer->crc32c = cpu_to_be32(crc); |
567 | 570 | ||
568 | if (drbd_bm_write_hinted(mdev)) | 571 | if (drbd_bm_write_hinted(device)) |
569 | err = -EIO; | 572 | err = -EIO; |
570 | else { | 573 | else { |
571 | bool write_al_updates; | 574 | bool write_al_updates; |
572 | rcu_read_lock(); | 575 | rcu_read_lock(); |
573 | write_al_updates = rcu_dereference(mdev->ldev->disk_conf)->al_updates; | 576 | write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates; |
574 | rcu_read_unlock(); | 577 | rcu_read_unlock(); |
575 | if (write_al_updates) { | 578 | if (write_al_updates) { |
576 | if (drbd_md_sync_page_io(mdev, mdev->ldev, sector, WRITE)) { | 579 | if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) { |
577 | err = -EIO; | 580 | err = -EIO; |
578 | drbd_chk_io_error(mdev, 1, DRBD_META_IO_ERROR); | 581 | drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR); |
579 | } else { | 582 | } else { |
580 | mdev->al_tr_number++; | 583 | device->al_tr_number++; |
581 | mdev->al_writ_cnt++; | 584 | device->al_writ_cnt++; |
582 | } | 585 | } |
583 | } | 586 | } |
584 | } | 587 | } |
585 | 588 | ||
586 | drbd_md_put_buffer(mdev); | 589 | drbd_md_put_buffer(device); |
587 | put_ldev(mdev); | 590 | put_ldev(device); |
588 | 591 | ||
589 | return err; | 592 | return err; |
590 | } | 593 | } |
@@ -593,10 +596,10 @@ _al_write_transaction(struct drbd_conf *mdev) | |||
593 | static int w_al_write_transaction(struct drbd_work *w, int unused) | 596 | static int w_al_write_transaction(struct drbd_work *w, int unused) |
594 | { | 597 | { |
595 | struct update_al_work *aw = container_of(w, struct update_al_work, w); | 598 | struct update_al_work *aw = container_of(w, struct update_al_work, w); |
596 | struct drbd_conf *mdev = w->mdev; | 599 | struct drbd_device *device = aw->device; |
597 | int err; | 600 | int err; |
598 | 601 | ||
599 | err = _al_write_transaction(mdev); | 602 | err = _al_write_transaction(device); |
600 | aw->err = err; | 603 | aw->err = err; |
601 | complete(&aw->event); | 604 | complete(&aw->event); |
602 | 605 | ||
@@ -606,63 +609,64 @@ static int w_al_write_transaction(struct drbd_work *w, int unused) | |||
606 | /* Calls from worker context (see w_restart_disk_io()) need to write the | 609 | /* Calls from worker context (see w_restart_disk_io()) need to write the |
607 | transaction directly. Others came through generic_make_request(), | 610 | transaction directly. Others came through generic_make_request(), |
608 | those need to delegate it to the worker. */ | 611 | those need to delegate it to the worker. */ |
609 | static int al_write_transaction(struct drbd_conf *mdev, bool delegate) | 612 | static int al_write_transaction(struct drbd_device *device, bool delegate) |
610 | { | 613 | { |
611 | if (delegate) { | 614 | if (delegate) { |
612 | struct update_al_work al_work; | 615 | struct update_al_work al_work; |
613 | init_completion(&al_work.event); | 616 | init_completion(&al_work.event); |
614 | al_work.w.cb = w_al_write_transaction; | 617 | al_work.w.cb = w_al_write_transaction; |
615 | al_work.w.mdev = mdev; | 618 | al_work.device = device; |
616 | drbd_queue_work_front(&mdev->tconn->sender_work, &al_work.w); | 619 | drbd_queue_work_front(&first_peer_device(device)->connection->sender_work, |
620 | &al_work.w); | ||
617 | wait_for_completion(&al_work.event); | 621 | wait_for_completion(&al_work.event); |
618 | return al_work.err; | 622 | return al_work.err; |
619 | } else | 623 | } else |
620 | return _al_write_transaction(mdev); | 624 | return _al_write_transaction(device); |
621 | } | 625 | } |
622 | 626 | ||
623 | static int _try_lc_del(struct drbd_conf *mdev, struct lc_element *al_ext) | 627 | static int _try_lc_del(struct drbd_device *device, struct lc_element *al_ext) |
624 | { | 628 | { |
625 | int rv; | 629 | int rv; |
626 | 630 | ||
627 | spin_lock_irq(&mdev->al_lock); | 631 | spin_lock_irq(&device->al_lock); |
628 | rv = (al_ext->refcnt == 0); | 632 | rv = (al_ext->refcnt == 0); |
629 | if (likely(rv)) | 633 | if (likely(rv)) |
630 | lc_del(mdev->act_log, al_ext); | 634 | lc_del(device->act_log, al_ext); |
631 | spin_unlock_irq(&mdev->al_lock); | 635 | spin_unlock_irq(&device->al_lock); |
632 | 636 | ||
633 | return rv; | 637 | return rv; |
634 | } | 638 | } |
635 | 639 | ||
636 | /** | 640 | /** |
637 | * drbd_al_shrink() - Removes all active extents form the activity log | 641 | * drbd_al_shrink() - Removes all active extents form the activity log |
638 | * @mdev: DRBD device. | 642 | * @device: DRBD device. |
639 | * | 643 | * |
640 | * Removes all active extents form the activity log, waiting until | 644 | * Removes all active extents form the activity log, waiting until |
641 | * the reference count of each entry dropped to 0 first, of course. | 645 | * the reference count of each entry dropped to 0 first, of course. |
642 | * | 646 | * |
643 | * You need to lock mdev->act_log with lc_try_lock() / lc_unlock() | 647 | * You need to lock device->act_log with lc_try_lock() / lc_unlock() |
644 | */ | 648 | */ |
645 | void drbd_al_shrink(struct drbd_conf *mdev) | 649 | void drbd_al_shrink(struct drbd_device *device) |
646 | { | 650 | { |
647 | struct lc_element *al_ext; | 651 | struct lc_element *al_ext; |
648 | int i; | 652 | int i; |
649 | 653 | ||
650 | D_ASSERT(test_bit(__LC_LOCKED, &mdev->act_log->flags)); | 654 | D_ASSERT(device, test_bit(__LC_LOCKED, &device->act_log->flags)); |
651 | 655 | ||
652 | for (i = 0; i < mdev->act_log->nr_elements; i++) { | 656 | for (i = 0; i < device->act_log->nr_elements; i++) { |
653 | al_ext = lc_element_by_index(mdev->act_log, i); | 657 | al_ext = lc_element_by_index(device->act_log, i); |
654 | if (al_ext->lc_number == LC_FREE) | 658 | if (al_ext->lc_number == LC_FREE) |
655 | continue; | 659 | continue; |
656 | wait_event(mdev->al_wait, _try_lc_del(mdev, al_ext)); | 660 | wait_event(device->al_wait, _try_lc_del(device, al_ext)); |
657 | } | 661 | } |
658 | 662 | ||
659 | wake_up(&mdev->al_wait); | 663 | wake_up(&device->al_wait); |
660 | } | 664 | } |
661 | 665 | ||
662 | int drbd_initialize_al(struct drbd_conf *mdev, void *buffer) | 666 | int drbd_initialize_al(struct drbd_device *device, void *buffer) |
663 | { | 667 | { |
664 | struct al_transaction_on_disk *al = buffer; | 668 | struct al_transaction_on_disk *al = buffer; |
665 | struct drbd_md *md = &mdev->ldev->md; | 669 | struct drbd_md *md = &device->ldev->md; |
666 | sector_t al_base = md->md_offset + md->al_offset; | 670 | sector_t al_base = md->md_offset + md->al_offset; |
667 | int al_size_4k = md->al_stripes * md->al_stripe_size_4k; | 671 | int al_size_4k = md->al_stripes * md->al_stripe_size_4k; |
668 | int i; | 672 | int i; |
@@ -673,7 +677,7 @@ int drbd_initialize_al(struct drbd_conf *mdev, void *buffer) | |||
673 | al->crc32c = cpu_to_be32(crc32c(0, al, 4096)); | 677 | al->crc32c = cpu_to_be32(crc32c(0, al, 4096)); |
674 | 678 | ||
675 | for (i = 0; i < al_size_4k; i++) { | 679 | for (i = 0; i < al_size_4k; i++) { |
676 | int err = drbd_md_sync_page_io(mdev, mdev->ldev, al_base + i * 8, WRITE); | 680 | int err = drbd_md_sync_page_io(device, device->ldev, al_base + i * 8, WRITE); |
677 | if (err) | 681 | if (err) |
678 | return err; | 682 | return err; |
679 | } | 683 | } |
@@ -683,32 +687,32 @@ int drbd_initialize_al(struct drbd_conf *mdev, void *buffer) | |||
683 | static int w_update_odbm(struct drbd_work *w, int unused) | 687 | static int w_update_odbm(struct drbd_work *w, int unused) |
684 | { | 688 | { |
685 | struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w); | 689 | struct update_odbm_work *udw = container_of(w, struct update_odbm_work, w); |
686 | struct drbd_conf *mdev = w->mdev; | 690 | struct drbd_device *device = udw->device; |
687 | struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, }; | 691 | struct sib_info sib = { .sib_reason = SIB_SYNC_PROGRESS, }; |
688 | 692 | ||
689 | if (!get_ldev(mdev)) { | 693 | if (!get_ldev(device)) { |
690 | if (__ratelimit(&drbd_ratelimit_state)) | 694 | if (__ratelimit(&drbd_ratelimit_state)) |
691 | dev_warn(DEV, "Can not update on disk bitmap, local IO disabled.\n"); | 695 | drbd_warn(device, "Can not update on disk bitmap, local IO disabled.\n"); |
692 | kfree(udw); | 696 | kfree(udw); |
693 | return 0; | 697 | return 0; |
694 | } | 698 | } |
695 | 699 | ||
696 | drbd_bm_write_page(mdev, rs_extent_to_bm_page(udw->enr)); | 700 | drbd_bm_write_page(device, rs_extent_to_bm_page(udw->enr)); |
697 | put_ldev(mdev); | 701 | put_ldev(device); |
698 | 702 | ||
699 | kfree(udw); | 703 | kfree(udw); |
700 | 704 | ||
701 | if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) { | 705 | if (drbd_bm_total_weight(device) <= device->rs_failed) { |
702 | switch (mdev->state.conn) { | 706 | switch (device->state.conn) { |
703 | case C_SYNC_SOURCE: case C_SYNC_TARGET: | 707 | case C_SYNC_SOURCE: case C_SYNC_TARGET: |
704 | case C_PAUSED_SYNC_S: case C_PAUSED_SYNC_T: | 708 | case C_PAUSED_SYNC_S: case C_PAUSED_SYNC_T: |
705 | drbd_resync_finished(mdev); | 709 | drbd_resync_finished(device); |
706 | default: | 710 | default: |
707 | /* nothing to do */ | 711 | /* nothing to do */ |
708 | break; | 712 | break; |
709 | } | 713 | } |
710 | } | 714 | } |
711 | drbd_bcast_event(mdev, &sib); | 715 | drbd_bcast_event(device, &sib); |
712 | 716 | ||
713 | return 0; | 717 | return 0; |
714 | } | 718 | } |
@@ -720,7 +724,7 @@ static int w_update_odbm(struct drbd_work *w, int unused) | |||
720 | * | 724 | * |
721 | * TODO will be obsoleted once we have a caching lru of the on disk bitmap | 725 | * TODO will be obsoleted once we have a caching lru of the on disk bitmap |
722 | */ | 726 | */ |
723 | static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | 727 | static void drbd_try_clear_on_disk_bm(struct drbd_device *device, sector_t sector, |
724 | int count, int success) | 728 | int count, int success) |
725 | { | 729 | { |
726 | struct lc_element *e; | 730 | struct lc_element *e; |
@@ -728,13 +732,13 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
728 | 732 | ||
729 | unsigned int enr; | 733 | unsigned int enr; |
730 | 734 | ||
731 | D_ASSERT(atomic_read(&mdev->local_cnt)); | 735 | D_ASSERT(device, atomic_read(&device->local_cnt)); |
732 | 736 | ||
733 | /* I simply assume that a sector/size pair never crosses | 737 | /* I simply assume that a sector/size pair never crosses |
734 | * a 16 MB extent border. (Currently this is true...) */ | 738 | * a 16 MB extent border. (Currently this is true...) */ |
735 | enr = BM_SECT_TO_EXT(sector); | 739 | enr = BM_SECT_TO_EXT(sector); |
736 | 740 | ||
737 | e = lc_get(mdev->resync, enr); | 741 | e = lc_get(device->resync, enr); |
738 | if (e) { | 742 | if (e) { |
739 | struct bm_extent *ext = lc_entry(e, struct bm_extent, lce); | 743 | struct bm_extent *ext = lc_entry(e, struct bm_extent, lce); |
740 | if (ext->lce.lc_number == enr) { | 744 | if (ext->lce.lc_number == enr) { |
@@ -743,12 +747,12 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
743 | else | 747 | else |
744 | ext->rs_failed += count; | 748 | ext->rs_failed += count; |
745 | if (ext->rs_left < ext->rs_failed) { | 749 | if (ext->rs_left < ext->rs_failed) { |
746 | dev_warn(DEV, "BAD! sector=%llus enr=%u rs_left=%d " | 750 | drbd_warn(device, "BAD! sector=%llus enr=%u rs_left=%d " |
747 | "rs_failed=%d count=%d cstate=%s\n", | 751 | "rs_failed=%d count=%d cstate=%s\n", |
748 | (unsigned long long)sector, | 752 | (unsigned long long)sector, |
749 | ext->lce.lc_number, ext->rs_left, | 753 | ext->lce.lc_number, ext->rs_left, |
750 | ext->rs_failed, count, | 754 | ext->rs_failed, count, |
751 | drbd_conn_str(mdev->state.conn)); | 755 | drbd_conn_str(device->state.conn)); |
752 | 756 | ||
753 | /* We don't expect to be able to clear more bits | 757 | /* We don't expect to be able to clear more bits |
754 | * than have been set when we originally counted | 758 | * than have been set when we originally counted |
@@ -756,7 +760,7 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
756 | * Whatever the reason (disconnect during resync, | 760 | * Whatever the reason (disconnect during resync, |
757 | * delayed local completion of an application write), | 761 | * delayed local completion of an application write), |
758 | * try to fix it up by recounting here. */ | 762 | * try to fix it up by recounting here. */ |
759 | ext->rs_left = drbd_bm_e_weight(mdev, enr); | 763 | ext->rs_left = drbd_bm_e_weight(device, enr); |
760 | } | 764 | } |
761 | } else { | 765 | } else { |
762 | /* Normally this element should be in the cache, | 766 | /* Normally this element should be in the cache, |
@@ -765,16 +769,16 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
765 | * But maybe an application write finished, and we set | 769 | * But maybe an application write finished, and we set |
766 | * something outside the resync lru_cache in sync. | 770 | * something outside the resync lru_cache in sync. |
767 | */ | 771 | */ |
768 | int rs_left = drbd_bm_e_weight(mdev, enr); | 772 | int rs_left = drbd_bm_e_weight(device, enr); |
769 | if (ext->flags != 0) { | 773 | if (ext->flags != 0) { |
770 | dev_warn(DEV, "changing resync lce: %d[%u;%02lx]" | 774 | drbd_warn(device, "changing resync lce: %d[%u;%02lx]" |
771 | " -> %d[%u;00]\n", | 775 | " -> %d[%u;00]\n", |
772 | ext->lce.lc_number, ext->rs_left, | 776 | ext->lce.lc_number, ext->rs_left, |
773 | ext->flags, enr, rs_left); | 777 | ext->flags, enr, rs_left); |
774 | ext->flags = 0; | 778 | ext->flags = 0; |
775 | } | 779 | } |
776 | if (ext->rs_failed) { | 780 | if (ext->rs_failed) { |
777 | dev_warn(DEV, "Kicking resync_lru element enr=%u " | 781 | drbd_warn(device, "Kicking resync_lru element enr=%u " |
778 | "out with rs_failed=%d\n", | 782 | "out with rs_failed=%d\n", |
779 | ext->lce.lc_number, ext->rs_failed); | 783 | ext->lce.lc_number, ext->rs_failed); |
780 | } | 784 | } |
@@ -782,9 +786,9 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
782 | ext->rs_failed = success ? 0 : count; | 786 | ext->rs_failed = success ? 0 : count; |
783 | /* we don't keep a persistent log of the resync lru, | 787 | /* we don't keep a persistent log of the resync lru, |
784 | * we can commit any change right away. */ | 788 | * we can commit any change right away. */ |
785 | lc_committed(mdev->resync); | 789 | lc_committed(device->resync); |
786 | } | 790 | } |
787 | lc_put(mdev->resync, &ext->lce); | 791 | lc_put(device->resync, &ext->lce); |
788 | /* no race, we are within the al_lock! */ | 792 | /* no race, we are within the al_lock! */ |
789 | 793 | ||
790 | if (ext->rs_left == ext->rs_failed) { | 794 | if (ext->rs_left == ext->rs_failed) { |
@@ -794,32 +798,33 @@ static void drbd_try_clear_on_disk_bm(struct drbd_conf *mdev, sector_t sector, | |||
794 | if (udw) { | 798 | if (udw) { |
795 | udw->enr = ext->lce.lc_number; | 799 | udw->enr = ext->lce.lc_number; |
796 | udw->w.cb = w_update_odbm; | 800 | udw->w.cb = w_update_odbm; |
797 | udw->w.mdev = mdev; | 801 | udw->device = device; |
798 | drbd_queue_work_front(&mdev->tconn->sender_work, &udw->w); | 802 | drbd_queue_work_front(&first_peer_device(device)->connection->sender_work, |
803 | &udw->w); | ||
799 | } else { | 804 | } else { |
800 | dev_warn(DEV, "Could not kmalloc an udw\n"); | 805 | drbd_warn(device, "Could not kmalloc an udw\n"); |
801 | } | 806 | } |
802 | } | 807 | } |
803 | } else { | 808 | } else { |
804 | dev_err(DEV, "lc_get() failed! locked=%d/%d flags=%lu\n", | 809 | drbd_err(device, "lc_get() failed! locked=%d/%d flags=%lu\n", |
805 | mdev->resync_locked, | 810 | device->resync_locked, |
806 | mdev->resync->nr_elements, | 811 | device->resync->nr_elements, |
807 | mdev->resync->flags); | 812 | device->resync->flags); |
808 | } | 813 | } |
809 | } | 814 | } |
810 | 815 | ||
811 | void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go) | 816 | void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go) |
812 | { | 817 | { |
813 | unsigned long now = jiffies; | 818 | unsigned long now = jiffies; |
814 | unsigned long last = mdev->rs_mark_time[mdev->rs_last_mark]; | 819 | unsigned long last = device->rs_mark_time[device->rs_last_mark]; |
815 | int next = (mdev->rs_last_mark + 1) % DRBD_SYNC_MARKS; | 820 | int next = (device->rs_last_mark + 1) % DRBD_SYNC_MARKS; |
816 | if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) { | 821 | if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) { |
817 | if (mdev->rs_mark_left[mdev->rs_last_mark] != still_to_go && | 822 | if (device->rs_mark_left[device->rs_last_mark] != still_to_go && |
818 | mdev->state.conn != C_PAUSED_SYNC_T && | 823 | device->state.conn != C_PAUSED_SYNC_T && |
819 | mdev->state.conn != C_PAUSED_SYNC_S) { | 824 | device->state.conn != C_PAUSED_SYNC_S) { |
820 | mdev->rs_mark_time[next] = now; | 825 | device->rs_mark_time[next] = now; |
821 | mdev->rs_mark_left[next] = still_to_go; | 826 | device->rs_mark_left[next] = still_to_go; |
822 | mdev->rs_last_mark = next; | 827 | device->rs_last_mark = next; |
823 | } | 828 | } |
824 | } | 829 | } |
825 | } | 830 | } |
@@ -831,7 +836,7 @@ void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go) | |||
831 | * called by worker on C_SYNC_TARGET and receiver on SyncSource. | 836 | * called by worker on C_SYNC_TARGET and receiver on SyncSource. |
832 | * | 837 | * |
833 | */ | 838 | */ |
834 | void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, int size, | 839 | void __drbd_set_in_sync(struct drbd_device *device, sector_t sector, int size, |
835 | const char *file, const unsigned int line) | 840 | const char *file, const unsigned int line) |
836 | { | 841 | { |
837 | /* Is called from worker and receiver context _only_ */ | 842 | /* Is called from worker and receiver context _only_ */ |
@@ -842,15 +847,15 @@ void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, int size, | |||
842 | unsigned long flags; | 847 | unsigned long flags; |
843 | 848 | ||
844 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { | 849 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
845 | dev_err(DEV, "drbd_set_in_sync: sector=%llus size=%d nonsense!\n", | 850 | drbd_err(device, "drbd_set_in_sync: sector=%llus size=%d nonsense!\n", |
846 | (unsigned long long)sector, size); | 851 | (unsigned long long)sector, size); |
847 | return; | 852 | return; |
848 | } | 853 | } |
849 | 854 | ||
850 | if (!get_ldev(mdev)) | 855 | if (!get_ldev(device)) |
851 | return; /* no disk, no metadata, no bitmap to clear bits in */ | 856 | return; /* no disk, no metadata, no bitmap to clear bits in */ |
852 | 857 | ||
853 | nr_sectors = drbd_get_capacity(mdev->this_bdev); | 858 | nr_sectors = drbd_get_capacity(device->this_bdev); |
854 | esector = sector + (size >> 9) - 1; | 859 | esector = sector + (size >> 9) - 1; |
855 | 860 | ||
856 | if (!expect(sector < nr_sectors)) | 861 | if (!expect(sector < nr_sectors)) |
@@ -878,21 +883,21 @@ void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, int size, | |||
878 | * ok, (capacity & 7) != 0 sometimes, but who cares... | 883 | * ok, (capacity & 7) != 0 sometimes, but who cares... |
879 | * we count rs_{total,left} in bits, not sectors. | 884 | * we count rs_{total,left} in bits, not sectors. |
880 | */ | 885 | */ |
881 | count = drbd_bm_clear_bits(mdev, sbnr, ebnr); | 886 | count = drbd_bm_clear_bits(device, sbnr, ebnr); |
882 | if (count) { | 887 | if (count) { |
883 | drbd_advance_rs_marks(mdev, drbd_bm_total_weight(mdev)); | 888 | drbd_advance_rs_marks(device, drbd_bm_total_weight(device)); |
884 | spin_lock_irqsave(&mdev->al_lock, flags); | 889 | spin_lock_irqsave(&device->al_lock, flags); |
885 | drbd_try_clear_on_disk_bm(mdev, sector, count, true); | 890 | drbd_try_clear_on_disk_bm(device, sector, count, true); |
886 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 891 | spin_unlock_irqrestore(&device->al_lock, flags); |
887 | 892 | ||
888 | /* just wake_up unconditional now, various lc_chaged(), | 893 | /* just wake_up unconditional now, various lc_chaged(), |
889 | * lc_put() in drbd_try_clear_on_disk_bm(). */ | 894 | * lc_put() in drbd_try_clear_on_disk_bm(). */ |
890 | wake_up = 1; | 895 | wake_up = 1; |
891 | } | 896 | } |
892 | out: | 897 | out: |
893 | put_ldev(mdev); | 898 | put_ldev(device); |
894 | if (wake_up) | 899 | if (wake_up) |
895 | wake_up(&mdev->al_wait); | 900 | wake_up(&device->al_wait); |
896 | } | 901 | } |
897 | 902 | ||
898 | /* | 903 | /* |
@@ -903,7 +908,7 @@ out: | |||
903 | * called by tl_clear and drbd_send_dblock (==drbd_make_request). | 908 | * called by tl_clear and drbd_send_dblock (==drbd_make_request). |
904 | * so this can be _any_ process. | 909 | * so this can be _any_ process. |
905 | */ | 910 | */ |
906 | int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size, | 911 | int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector, int size, |
907 | const char *file, const unsigned int line) | 912 | const char *file, const unsigned int line) |
908 | { | 913 | { |
909 | unsigned long sbnr, ebnr, flags; | 914 | unsigned long sbnr, ebnr, flags; |
@@ -916,15 +921,15 @@ int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size, | |||
916 | return 0; | 921 | return 0; |
917 | 922 | ||
918 | if (size < 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { | 923 | if (size < 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
919 | dev_err(DEV, "sector: %llus, size: %d\n", | 924 | drbd_err(device, "sector: %llus, size: %d\n", |
920 | (unsigned long long)sector, size); | 925 | (unsigned long long)sector, size); |
921 | return 0; | 926 | return 0; |
922 | } | 927 | } |
923 | 928 | ||
924 | if (!get_ldev(mdev)) | 929 | if (!get_ldev(device)) |
925 | return 0; /* no disk, no metadata, no bitmap to set bits in */ | 930 | return 0; /* no disk, no metadata, no bitmap to set bits in */ |
926 | 931 | ||
927 | nr_sectors = drbd_get_capacity(mdev->this_bdev); | 932 | nr_sectors = drbd_get_capacity(device->this_bdev); |
928 | esector = sector + (size >> 9) - 1; | 933 | esector = sector + (size >> 9) - 1; |
929 | 934 | ||
930 | if (!expect(sector < nr_sectors)) | 935 | if (!expect(sector < nr_sectors)) |
@@ -939,55 +944,55 @@ int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, int size, | |||
939 | 944 | ||
940 | /* ok, (capacity & 7) != 0 sometimes, but who cares... | 945 | /* ok, (capacity & 7) != 0 sometimes, but who cares... |
941 | * we count rs_{total,left} in bits, not sectors. */ | 946 | * we count rs_{total,left} in bits, not sectors. */ |
942 | spin_lock_irqsave(&mdev->al_lock, flags); | 947 | spin_lock_irqsave(&device->al_lock, flags); |
943 | count = drbd_bm_set_bits(mdev, sbnr, ebnr); | 948 | count = drbd_bm_set_bits(device, sbnr, ebnr); |
944 | 949 | ||
945 | enr = BM_SECT_TO_EXT(sector); | 950 | enr = BM_SECT_TO_EXT(sector); |
946 | e = lc_find(mdev->resync, enr); | 951 | e = lc_find(device->resync, enr); |
947 | if (e) | 952 | if (e) |
948 | lc_entry(e, struct bm_extent, lce)->rs_left += count; | 953 | lc_entry(e, struct bm_extent, lce)->rs_left += count; |
949 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 954 | spin_unlock_irqrestore(&device->al_lock, flags); |
950 | 955 | ||
951 | out: | 956 | out: |
952 | put_ldev(mdev); | 957 | put_ldev(device); |
953 | 958 | ||
954 | return count; | 959 | return count; |
955 | } | 960 | } |
956 | 961 | ||
957 | static | 962 | static |
958 | struct bm_extent *_bme_get(struct drbd_conf *mdev, unsigned int enr) | 963 | struct bm_extent *_bme_get(struct drbd_device *device, unsigned int enr) |
959 | { | 964 | { |
960 | struct lc_element *e; | 965 | struct lc_element *e; |
961 | struct bm_extent *bm_ext; | 966 | struct bm_extent *bm_ext; |
962 | int wakeup = 0; | 967 | int wakeup = 0; |
963 | unsigned long rs_flags; | 968 | unsigned long rs_flags; |
964 | 969 | ||
965 | spin_lock_irq(&mdev->al_lock); | 970 | spin_lock_irq(&device->al_lock); |
966 | if (mdev->resync_locked > mdev->resync->nr_elements/2) { | 971 | if (device->resync_locked > device->resync->nr_elements/2) { |
967 | spin_unlock_irq(&mdev->al_lock); | 972 | spin_unlock_irq(&device->al_lock); |
968 | return NULL; | 973 | return NULL; |
969 | } | 974 | } |
970 | e = lc_get(mdev->resync, enr); | 975 | e = lc_get(device->resync, enr); |
971 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; | 976 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
972 | if (bm_ext) { | 977 | if (bm_ext) { |
973 | if (bm_ext->lce.lc_number != enr) { | 978 | if (bm_ext->lce.lc_number != enr) { |
974 | bm_ext->rs_left = drbd_bm_e_weight(mdev, enr); | 979 | bm_ext->rs_left = drbd_bm_e_weight(device, enr); |
975 | bm_ext->rs_failed = 0; | 980 | bm_ext->rs_failed = 0; |
976 | lc_committed(mdev->resync); | 981 | lc_committed(device->resync); |
977 | wakeup = 1; | 982 | wakeup = 1; |
978 | } | 983 | } |
979 | if (bm_ext->lce.refcnt == 1) | 984 | if (bm_ext->lce.refcnt == 1) |
980 | mdev->resync_locked++; | 985 | device->resync_locked++; |
981 | set_bit(BME_NO_WRITES, &bm_ext->flags); | 986 | set_bit(BME_NO_WRITES, &bm_ext->flags); |
982 | } | 987 | } |
983 | rs_flags = mdev->resync->flags; | 988 | rs_flags = device->resync->flags; |
984 | spin_unlock_irq(&mdev->al_lock); | 989 | spin_unlock_irq(&device->al_lock); |
985 | if (wakeup) | 990 | if (wakeup) |
986 | wake_up(&mdev->al_wait); | 991 | wake_up(&device->al_wait); |
987 | 992 | ||
988 | if (!bm_ext) { | 993 | if (!bm_ext) { |
989 | if (rs_flags & LC_STARVING) | 994 | if (rs_flags & LC_STARVING) |
990 | dev_warn(DEV, "Have to wait for element" | 995 | drbd_warn(device, "Have to wait for element" |
991 | " (resync LRU too small?)\n"); | 996 | " (resync LRU too small?)\n"); |
992 | BUG_ON(rs_flags & LC_LOCKED); | 997 | BUG_ON(rs_flags & LC_LOCKED); |
993 | } | 998 | } |
@@ -995,25 +1000,25 @@ struct bm_extent *_bme_get(struct drbd_conf *mdev, unsigned int enr) | |||
995 | return bm_ext; | 1000 | return bm_ext; |
996 | } | 1001 | } |
997 | 1002 | ||
998 | static int _is_in_al(struct drbd_conf *mdev, unsigned int enr) | 1003 | static int _is_in_al(struct drbd_device *device, unsigned int enr) |
999 | { | 1004 | { |
1000 | int rv; | 1005 | int rv; |
1001 | 1006 | ||
1002 | spin_lock_irq(&mdev->al_lock); | 1007 | spin_lock_irq(&device->al_lock); |
1003 | rv = lc_is_used(mdev->act_log, enr); | 1008 | rv = lc_is_used(device->act_log, enr); |
1004 | spin_unlock_irq(&mdev->al_lock); | 1009 | spin_unlock_irq(&device->al_lock); |
1005 | 1010 | ||
1006 | return rv; | 1011 | return rv; |
1007 | } | 1012 | } |
1008 | 1013 | ||
1009 | /** | 1014 | /** |
1010 | * drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED | 1015 | * drbd_rs_begin_io() - Gets an extent in the resync LRU cache and sets it to BME_LOCKED |
1011 | * @mdev: DRBD device. | 1016 | * @device: DRBD device. |
1012 | * @sector: The sector number. | 1017 | * @sector: The sector number. |
1013 | * | 1018 | * |
1014 | * This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted. | 1019 | * This functions sleeps on al_wait. Returns 0 on success, -EINTR if interrupted. |
1015 | */ | 1020 | */ |
1016 | int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector) | 1021 | int drbd_rs_begin_io(struct drbd_device *device, sector_t sector) |
1017 | { | 1022 | { |
1018 | unsigned int enr = BM_SECT_TO_EXT(sector); | 1023 | unsigned int enr = BM_SECT_TO_EXT(sector); |
1019 | struct bm_extent *bm_ext; | 1024 | struct bm_extent *bm_ext; |
@@ -1022,8 +1027,8 @@ int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector) | |||
1022 | 200 times -> 20 seconds. */ | 1027 | 200 times -> 20 seconds. */ |
1023 | 1028 | ||
1024 | retry: | 1029 | retry: |
1025 | sig = wait_event_interruptible(mdev->al_wait, | 1030 | sig = wait_event_interruptible(device->al_wait, |
1026 | (bm_ext = _bme_get(mdev, enr))); | 1031 | (bm_ext = _bme_get(device, enr))); |
1027 | if (sig) | 1032 | if (sig) |
1028 | return -EINTR; | 1033 | return -EINTR; |
1029 | 1034 | ||
@@ -1031,24 +1036,24 @@ retry: | |||
1031 | return 0; | 1036 | return 0; |
1032 | 1037 | ||
1033 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { | 1038 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { |
1034 | sig = wait_event_interruptible(mdev->al_wait, | 1039 | sig = wait_event_interruptible(device->al_wait, |
1035 | !_is_in_al(mdev, enr * AL_EXT_PER_BM_SECT + i) || | 1040 | !_is_in_al(device, enr * AL_EXT_PER_BM_SECT + i) || |
1036 | test_bit(BME_PRIORITY, &bm_ext->flags)); | 1041 | test_bit(BME_PRIORITY, &bm_ext->flags)); |
1037 | 1042 | ||
1038 | if (sig || (test_bit(BME_PRIORITY, &bm_ext->flags) && sa)) { | 1043 | if (sig || (test_bit(BME_PRIORITY, &bm_ext->flags) && sa)) { |
1039 | spin_lock_irq(&mdev->al_lock); | 1044 | spin_lock_irq(&device->al_lock); |
1040 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) { | 1045 | if (lc_put(device->resync, &bm_ext->lce) == 0) { |
1041 | bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */ | 1046 | bm_ext->flags = 0; /* clears BME_NO_WRITES and eventually BME_PRIORITY */ |
1042 | mdev->resync_locked--; | 1047 | device->resync_locked--; |
1043 | wake_up(&mdev->al_wait); | 1048 | wake_up(&device->al_wait); |
1044 | } | 1049 | } |
1045 | spin_unlock_irq(&mdev->al_lock); | 1050 | spin_unlock_irq(&device->al_lock); |
1046 | if (sig) | 1051 | if (sig) |
1047 | return -EINTR; | 1052 | return -EINTR; |
1048 | if (schedule_timeout_interruptible(HZ/10)) | 1053 | if (schedule_timeout_interruptible(HZ/10)) |
1049 | return -EINTR; | 1054 | return -EINTR; |
1050 | if (sa && --sa == 0) | 1055 | if (sa && --sa == 0) |
1051 | dev_warn(DEV,"drbd_rs_begin_io() stepped aside for 20sec." | 1056 | drbd_warn(device, "drbd_rs_begin_io() stepped aside for 20sec." |
1052 | "Resync stalled?\n"); | 1057 | "Resync stalled?\n"); |
1053 | goto retry; | 1058 | goto retry; |
1054 | } | 1059 | } |
@@ -1059,14 +1064,14 @@ retry: | |||
1059 | 1064 | ||
1060 | /** | 1065 | /** |
1061 | * drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep | 1066 | * drbd_try_rs_begin_io() - Gets an extent in the resync LRU cache, does not sleep |
1062 | * @mdev: DRBD device. | 1067 | * @device: DRBD device. |
1063 | * @sector: The sector number. | 1068 | * @sector: The sector number. |
1064 | * | 1069 | * |
1065 | * Gets an extent in the resync LRU cache, sets it to BME_NO_WRITES, then | 1070 | * Gets an extent in the resync LRU cache, sets it to BME_NO_WRITES, then |
1066 | * tries to set it to BME_LOCKED. Returns 0 upon success, and -EAGAIN | 1071 | * tries to set it to BME_LOCKED. Returns 0 upon success, and -EAGAIN |
1067 | * if there is still application IO going on in this area. | 1072 | * if there is still application IO going on in this area. |
1068 | */ | 1073 | */ |
1069 | int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector) | 1074 | int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector) |
1070 | { | 1075 | { |
1071 | unsigned int enr = BM_SECT_TO_EXT(sector); | 1076 | unsigned int enr = BM_SECT_TO_EXT(sector); |
1072 | const unsigned int al_enr = enr*AL_EXT_PER_BM_SECT; | 1077 | const unsigned int al_enr = enr*AL_EXT_PER_BM_SECT; |
@@ -1074,8 +1079,8 @@ int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector) | |||
1074 | struct bm_extent *bm_ext; | 1079 | struct bm_extent *bm_ext; |
1075 | int i; | 1080 | int i; |
1076 | 1081 | ||
1077 | spin_lock_irq(&mdev->al_lock); | 1082 | spin_lock_irq(&device->al_lock); |
1078 | if (mdev->resync_wenr != LC_FREE && mdev->resync_wenr != enr) { | 1083 | if (device->resync_wenr != LC_FREE && device->resync_wenr != enr) { |
1079 | /* in case you have very heavy scattered io, it may | 1084 | /* in case you have very heavy scattered io, it may |
1080 | * stall the syncer undefined if we give up the ref count | 1085 | * stall the syncer undefined if we give up the ref count |
1081 | * when we try again and requeue. | 1086 | * when we try again and requeue. |
@@ -1089,193 +1094,193 @@ int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector) | |||
1089 | * the lc_put here... | 1094 | * the lc_put here... |
1090 | * we also have to wake_up | 1095 | * we also have to wake_up |
1091 | */ | 1096 | */ |
1092 | e = lc_find(mdev->resync, mdev->resync_wenr); | 1097 | e = lc_find(device->resync, device->resync_wenr); |
1093 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; | 1098 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
1094 | if (bm_ext) { | 1099 | if (bm_ext) { |
1095 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); | 1100 | D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); |
1096 | D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags)); | 1101 | D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags)); |
1097 | clear_bit(BME_NO_WRITES, &bm_ext->flags); | 1102 | clear_bit(BME_NO_WRITES, &bm_ext->flags); |
1098 | mdev->resync_wenr = LC_FREE; | 1103 | device->resync_wenr = LC_FREE; |
1099 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) | 1104 | if (lc_put(device->resync, &bm_ext->lce) == 0) |
1100 | mdev->resync_locked--; | 1105 | device->resync_locked--; |
1101 | wake_up(&mdev->al_wait); | 1106 | wake_up(&device->al_wait); |
1102 | } else { | 1107 | } else { |
1103 | dev_alert(DEV, "LOGIC BUG\n"); | 1108 | drbd_alert(device, "LOGIC BUG\n"); |
1104 | } | 1109 | } |
1105 | } | 1110 | } |
1106 | /* TRY. */ | 1111 | /* TRY. */ |
1107 | e = lc_try_get(mdev->resync, enr); | 1112 | e = lc_try_get(device->resync, enr); |
1108 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; | 1113 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
1109 | if (bm_ext) { | 1114 | if (bm_ext) { |
1110 | if (test_bit(BME_LOCKED, &bm_ext->flags)) | 1115 | if (test_bit(BME_LOCKED, &bm_ext->flags)) |
1111 | goto proceed; | 1116 | goto proceed; |
1112 | if (!test_and_set_bit(BME_NO_WRITES, &bm_ext->flags)) { | 1117 | if (!test_and_set_bit(BME_NO_WRITES, &bm_ext->flags)) { |
1113 | mdev->resync_locked++; | 1118 | device->resync_locked++; |
1114 | } else { | 1119 | } else { |
1115 | /* we did set the BME_NO_WRITES, | 1120 | /* we did set the BME_NO_WRITES, |
1116 | * but then could not set BME_LOCKED, | 1121 | * but then could not set BME_LOCKED, |
1117 | * so we tried again. | 1122 | * so we tried again. |
1118 | * drop the extra reference. */ | 1123 | * drop the extra reference. */ |
1119 | bm_ext->lce.refcnt--; | 1124 | bm_ext->lce.refcnt--; |
1120 | D_ASSERT(bm_ext->lce.refcnt > 0); | 1125 | D_ASSERT(device, bm_ext->lce.refcnt > 0); |
1121 | } | 1126 | } |
1122 | goto check_al; | 1127 | goto check_al; |
1123 | } else { | 1128 | } else { |
1124 | /* do we rather want to try later? */ | 1129 | /* do we rather want to try later? */ |
1125 | if (mdev->resync_locked > mdev->resync->nr_elements-3) | 1130 | if (device->resync_locked > device->resync->nr_elements-3) |
1126 | goto try_again; | 1131 | goto try_again; |
1127 | /* Do or do not. There is no try. -- Yoda */ | 1132 | /* Do or do not. There is no try. -- Yoda */ |
1128 | e = lc_get(mdev->resync, enr); | 1133 | e = lc_get(device->resync, enr); |
1129 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; | 1134 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
1130 | if (!bm_ext) { | 1135 | if (!bm_ext) { |
1131 | const unsigned long rs_flags = mdev->resync->flags; | 1136 | const unsigned long rs_flags = device->resync->flags; |
1132 | if (rs_flags & LC_STARVING) | 1137 | if (rs_flags & LC_STARVING) |
1133 | dev_warn(DEV, "Have to wait for element" | 1138 | drbd_warn(device, "Have to wait for element" |
1134 | " (resync LRU too small?)\n"); | 1139 | " (resync LRU too small?)\n"); |
1135 | BUG_ON(rs_flags & LC_LOCKED); | 1140 | BUG_ON(rs_flags & LC_LOCKED); |
1136 | goto try_again; | 1141 | goto try_again; |
1137 | } | 1142 | } |
1138 | if (bm_ext->lce.lc_number != enr) { | 1143 | if (bm_ext->lce.lc_number != enr) { |
1139 | bm_ext->rs_left = drbd_bm_e_weight(mdev, enr); | 1144 | bm_ext->rs_left = drbd_bm_e_weight(device, enr); |
1140 | bm_ext->rs_failed = 0; | 1145 | bm_ext->rs_failed = 0; |
1141 | lc_committed(mdev->resync); | 1146 | lc_committed(device->resync); |
1142 | wake_up(&mdev->al_wait); | 1147 | wake_up(&device->al_wait); |
1143 | D_ASSERT(test_bit(BME_LOCKED, &bm_ext->flags) == 0); | 1148 | D_ASSERT(device, test_bit(BME_LOCKED, &bm_ext->flags) == 0); |
1144 | } | 1149 | } |
1145 | set_bit(BME_NO_WRITES, &bm_ext->flags); | 1150 | set_bit(BME_NO_WRITES, &bm_ext->flags); |
1146 | D_ASSERT(bm_ext->lce.refcnt == 1); | 1151 | D_ASSERT(device, bm_ext->lce.refcnt == 1); |
1147 | mdev->resync_locked++; | 1152 | device->resync_locked++; |
1148 | goto check_al; | 1153 | goto check_al; |
1149 | } | 1154 | } |
1150 | check_al: | 1155 | check_al: |
1151 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { | 1156 | for (i = 0; i < AL_EXT_PER_BM_SECT; i++) { |
1152 | if (lc_is_used(mdev->act_log, al_enr+i)) | 1157 | if (lc_is_used(device->act_log, al_enr+i)) |
1153 | goto try_again; | 1158 | goto try_again; |
1154 | } | 1159 | } |
1155 | set_bit(BME_LOCKED, &bm_ext->flags); | 1160 | set_bit(BME_LOCKED, &bm_ext->flags); |
1156 | proceed: | 1161 | proceed: |
1157 | mdev->resync_wenr = LC_FREE; | 1162 | device->resync_wenr = LC_FREE; |
1158 | spin_unlock_irq(&mdev->al_lock); | 1163 | spin_unlock_irq(&device->al_lock); |
1159 | return 0; | 1164 | return 0; |
1160 | 1165 | ||
1161 | try_again: | 1166 | try_again: |
1162 | if (bm_ext) | 1167 | if (bm_ext) |
1163 | mdev->resync_wenr = enr; | 1168 | device->resync_wenr = enr; |
1164 | spin_unlock_irq(&mdev->al_lock); | 1169 | spin_unlock_irq(&device->al_lock); |
1165 | return -EAGAIN; | 1170 | return -EAGAIN; |
1166 | } | 1171 | } |
1167 | 1172 | ||
1168 | void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector) | 1173 | void drbd_rs_complete_io(struct drbd_device *device, sector_t sector) |
1169 | { | 1174 | { |
1170 | unsigned int enr = BM_SECT_TO_EXT(sector); | 1175 | unsigned int enr = BM_SECT_TO_EXT(sector); |
1171 | struct lc_element *e; | 1176 | struct lc_element *e; |
1172 | struct bm_extent *bm_ext; | 1177 | struct bm_extent *bm_ext; |
1173 | unsigned long flags; | 1178 | unsigned long flags; |
1174 | 1179 | ||
1175 | spin_lock_irqsave(&mdev->al_lock, flags); | 1180 | spin_lock_irqsave(&device->al_lock, flags); |
1176 | e = lc_find(mdev->resync, enr); | 1181 | e = lc_find(device->resync, enr); |
1177 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; | 1182 | bm_ext = e ? lc_entry(e, struct bm_extent, lce) : NULL; |
1178 | if (!bm_ext) { | 1183 | if (!bm_ext) { |
1179 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 1184 | spin_unlock_irqrestore(&device->al_lock, flags); |
1180 | if (__ratelimit(&drbd_ratelimit_state)) | 1185 | if (__ratelimit(&drbd_ratelimit_state)) |
1181 | dev_err(DEV, "drbd_rs_complete_io() called, but extent not found\n"); | 1186 | drbd_err(device, "drbd_rs_complete_io() called, but extent not found\n"); |
1182 | return; | 1187 | return; |
1183 | } | 1188 | } |
1184 | 1189 | ||
1185 | if (bm_ext->lce.refcnt == 0) { | 1190 | if (bm_ext->lce.refcnt == 0) { |
1186 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 1191 | spin_unlock_irqrestore(&device->al_lock, flags); |
1187 | dev_err(DEV, "drbd_rs_complete_io(,%llu [=%u]) called, " | 1192 | drbd_err(device, "drbd_rs_complete_io(,%llu [=%u]) called, " |
1188 | "but refcnt is 0!?\n", | 1193 | "but refcnt is 0!?\n", |
1189 | (unsigned long long)sector, enr); | 1194 | (unsigned long long)sector, enr); |
1190 | return; | 1195 | return; |
1191 | } | 1196 | } |
1192 | 1197 | ||
1193 | if (lc_put(mdev->resync, &bm_ext->lce) == 0) { | 1198 | if (lc_put(device->resync, &bm_ext->lce) == 0) { |
1194 | bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */ | 1199 | bm_ext->flags = 0; /* clear BME_LOCKED, BME_NO_WRITES and BME_PRIORITY */ |
1195 | mdev->resync_locked--; | 1200 | device->resync_locked--; |
1196 | wake_up(&mdev->al_wait); | 1201 | wake_up(&device->al_wait); |
1197 | } | 1202 | } |
1198 | 1203 | ||
1199 | spin_unlock_irqrestore(&mdev->al_lock, flags); | 1204 | spin_unlock_irqrestore(&device->al_lock, flags); |
1200 | } | 1205 | } |
1201 | 1206 | ||
1202 | /** | 1207 | /** |
1203 | * drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED) | 1208 | * drbd_rs_cancel_all() - Removes all extents from the resync LRU (even BME_LOCKED) |
1204 | * @mdev: DRBD device. | 1209 | * @device: DRBD device. |
1205 | */ | 1210 | */ |
1206 | void drbd_rs_cancel_all(struct drbd_conf *mdev) | 1211 | void drbd_rs_cancel_all(struct drbd_device *device) |
1207 | { | 1212 | { |
1208 | spin_lock_irq(&mdev->al_lock); | 1213 | spin_lock_irq(&device->al_lock); |
1209 | 1214 | ||
1210 | if (get_ldev_if_state(mdev, D_FAILED)) { /* Makes sure ->resync is there. */ | 1215 | if (get_ldev_if_state(device, D_FAILED)) { /* Makes sure ->resync is there. */ |
1211 | lc_reset(mdev->resync); | 1216 | lc_reset(device->resync); |
1212 | put_ldev(mdev); | 1217 | put_ldev(device); |
1213 | } | 1218 | } |
1214 | mdev->resync_locked = 0; | 1219 | device->resync_locked = 0; |
1215 | mdev->resync_wenr = LC_FREE; | 1220 | device->resync_wenr = LC_FREE; |
1216 | spin_unlock_irq(&mdev->al_lock); | 1221 | spin_unlock_irq(&device->al_lock); |
1217 | wake_up(&mdev->al_wait); | 1222 | wake_up(&device->al_wait); |
1218 | } | 1223 | } |
1219 | 1224 | ||
1220 | /** | 1225 | /** |
1221 | * drbd_rs_del_all() - Gracefully remove all extents from the resync LRU | 1226 | * drbd_rs_del_all() - Gracefully remove all extents from the resync LRU |
1222 | * @mdev: DRBD device. | 1227 | * @device: DRBD device. |
1223 | * | 1228 | * |
1224 | * Returns 0 upon success, -EAGAIN if at least one reference count was | 1229 | * Returns 0 upon success, -EAGAIN if at least one reference count was |
1225 | * not zero. | 1230 | * not zero. |
1226 | */ | 1231 | */ |
1227 | int drbd_rs_del_all(struct drbd_conf *mdev) | 1232 | int drbd_rs_del_all(struct drbd_device *device) |
1228 | { | 1233 | { |
1229 | struct lc_element *e; | 1234 | struct lc_element *e; |
1230 | struct bm_extent *bm_ext; | 1235 | struct bm_extent *bm_ext; |
1231 | int i; | 1236 | int i; |
1232 | 1237 | ||
1233 | spin_lock_irq(&mdev->al_lock); | 1238 | spin_lock_irq(&device->al_lock); |
1234 | 1239 | ||
1235 | if (get_ldev_if_state(mdev, D_FAILED)) { | 1240 | if (get_ldev_if_state(device, D_FAILED)) { |
1236 | /* ok, ->resync is there. */ | 1241 | /* ok, ->resync is there. */ |
1237 | for (i = 0; i < mdev->resync->nr_elements; i++) { | 1242 | for (i = 0; i < device->resync->nr_elements; i++) { |
1238 | e = lc_element_by_index(mdev->resync, i); | 1243 | e = lc_element_by_index(device->resync, i); |
1239 | bm_ext = lc_entry(e, struct bm_extent, lce); | 1244 | bm_ext = lc_entry(e, struct bm_extent, lce); |
1240 | if (bm_ext->lce.lc_number == LC_FREE) | 1245 | if (bm_ext->lce.lc_number == LC_FREE) |
1241 | continue; | 1246 | continue; |
1242 | if (bm_ext->lce.lc_number == mdev->resync_wenr) { | 1247 | if (bm_ext->lce.lc_number == device->resync_wenr) { |
1243 | dev_info(DEV, "dropping %u in drbd_rs_del_all, apparently" | 1248 | drbd_info(device, "dropping %u in drbd_rs_del_all, apparently" |
1244 | " got 'synced' by application io\n", | 1249 | " got 'synced' by application io\n", |
1245 | mdev->resync_wenr); | 1250 | device->resync_wenr); |
1246 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); | 1251 | D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); |
1247 | D_ASSERT(test_bit(BME_NO_WRITES, &bm_ext->flags)); | 1252 | D_ASSERT(device, test_bit(BME_NO_WRITES, &bm_ext->flags)); |
1248 | clear_bit(BME_NO_WRITES, &bm_ext->flags); | 1253 | clear_bit(BME_NO_WRITES, &bm_ext->flags); |
1249 | mdev->resync_wenr = LC_FREE; | 1254 | device->resync_wenr = LC_FREE; |
1250 | lc_put(mdev->resync, &bm_ext->lce); | 1255 | lc_put(device->resync, &bm_ext->lce); |
1251 | } | 1256 | } |
1252 | if (bm_ext->lce.refcnt != 0) { | 1257 | if (bm_ext->lce.refcnt != 0) { |
1253 | dev_info(DEV, "Retrying drbd_rs_del_all() later. " | 1258 | drbd_info(device, "Retrying drbd_rs_del_all() later. " |
1254 | "refcnt=%d\n", bm_ext->lce.refcnt); | 1259 | "refcnt=%d\n", bm_ext->lce.refcnt); |
1255 | put_ldev(mdev); | 1260 | put_ldev(device); |
1256 | spin_unlock_irq(&mdev->al_lock); | 1261 | spin_unlock_irq(&device->al_lock); |
1257 | return -EAGAIN; | 1262 | return -EAGAIN; |
1258 | } | 1263 | } |
1259 | D_ASSERT(!test_bit(BME_LOCKED, &bm_ext->flags)); | 1264 | D_ASSERT(device, !test_bit(BME_LOCKED, &bm_ext->flags)); |
1260 | D_ASSERT(!test_bit(BME_NO_WRITES, &bm_ext->flags)); | 1265 | D_ASSERT(device, !test_bit(BME_NO_WRITES, &bm_ext->flags)); |
1261 | lc_del(mdev->resync, &bm_ext->lce); | 1266 | lc_del(device->resync, &bm_ext->lce); |
1262 | } | 1267 | } |
1263 | D_ASSERT(mdev->resync->used == 0); | 1268 | D_ASSERT(device, device->resync->used == 0); |
1264 | put_ldev(mdev); | 1269 | put_ldev(device); |
1265 | } | 1270 | } |
1266 | spin_unlock_irq(&mdev->al_lock); | 1271 | spin_unlock_irq(&device->al_lock); |
1267 | wake_up(&mdev->al_wait); | 1272 | wake_up(&device->al_wait); |
1268 | 1273 | ||
1269 | return 0; | 1274 | return 0; |
1270 | } | 1275 | } |
1271 | 1276 | ||
1272 | /** | 1277 | /** |
1273 | * drbd_rs_failed_io() - Record information on a failure to resync the specified blocks | 1278 | * drbd_rs_failed_io() - Record information on a failure to resync the specified blocks |
1274 | * @mdev: DRBD device. | 1279 | * @device: DRBD device. |
1275 | * @sector: The sector number. | 1280 | * @sector: The sector number. |
1276 | * @size: Size of failed IO operation, in byte. | 1281 | * @size: Size of failed IO operation, in byte. |
1277 | */ | 1282 | */ |
1278 | void drbd_rs_failed_io(struct drbd_conf *mdev, sector_t sector, int size) | 1283 | void drbd_rs_failed_io(struct drbd_device *device, sector_t sector, int size) |
1279 | { | 1284 | { |
1280 | /* Is called from worker and receiver context _only_ */ | 1285 | /* Is called from worker and receiver context _only_ */ |
1281 | unsigned long sbnr, ebnr, lbnr; | 1286 | unsigned long sbnr, ebnr, lbnr; |
@@ -1284,11 +1289,11 @@ void drbd_rs_failed_io(struct drbd_conf *mdev, sector_t sector, int size) | |||
1284 | int wake_up = 0; | 1289 | int wake_up = 0; |
1285 | 1290 | ||
1286 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { | 1291 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
1287 | dev_err(DEV, "drbd_rs_failed_io: sector=%llus size=%d nonsense!\n", | 1292 | drbd_err(device, "drbd_rs_failed_io: sector=%llus size=%d nonsense!\n", |
1288 | (unsigned long long)sector, size); | 1293 | (unsigned long long)sector, size); |
1289 | return; | 1294 | return; |
1290 | } | 1295 | } |
1291 | nr_sectors = drbd_get_capacity(mdev->this_bdev); | 1296 | nr_sectors = drbd_get_capacity(device->this_bdev); |
1292 | esector = sector + (size >> 9) - 1; | 1297 | esector = sector + (size >> 9) - 1; |
1293 | 1298 | ||
1294 | if (!expect(sector < nr_sectors)) | 1299 | if (!expect(sector < nr_sectors)) |
@@ -1316,21 +1321,21 @@ void drbd_rs_failed_io(struct drbd_conf *mdev, sector_t sector, int size) | |||
1316 | * ok, (capacity & 7) != 0 sometimes, but who cares... | 1321 | * ok, (capacity & 7) != 0 sometimes, but who cares... |
1317 | * we count rs_{total,left} in bits, not sectors. | 1322 | * we count rs_{total,left} in bits, not sectors. |
1318 | */ | 1323 | */ |
1319 | spin_lock_irq(&mdev->al_lock); | 1324 | spin_lock_irq(&device->al_lock); |
1320 | count = drbd_bm_count_bits(mdev, sbnr, ebnr); | 1325 | count = drbd_bm_count_bits(device, sbnr, ebnr); |
1321 | if (count) { | 1326 | if (count) { |
1322 | mdev->rs_failed += count; | 1327 | device->rs_failed += count; |
1323 | 1328 | ||
1324 | if (get_ldev(mdev)) { | 1329 | if (get_ldev(device)) { |
1325 | drbd_try_clear_on_disk_bm(mdev, sector, count, false); | 1330 | drbd_try_clear_on_disk_bm(device, sector, count, false); |
1326 | put_ldev(mdev); | 1331 | put_ldev(device); |
1327 | } | 1332 | } |
1328 | 1333 | ||
1329 | /* just wake_up unconditional now, various lc_chaged(), | 1334 | /* just wake_up unconditional now, various lc_chaged(), |
1330 | * lc_put() in drbd_try_clear_on_disk_bm(). */ | 1335 | * lc_put() in drbd_try_clear_on_disk_bm(). */ |
1331 | wake_up = 1; | 1336 | wake_up = 1; |
1332 | } | 1337 | } |
1333 | spin_unlock_irq(&mdev->al_lock); | 1338 | spin_unlock_irq(&device->al_lock); |
1334 | if (wake_up) | 1339 | if (wake_up) |
1335 | wake_up(&mdev->al_wait); | 1340 | wake_up(&device->al_wait); |
1336 | } | 1341 | } |
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c index 597f111df67b..1aa29f8fdfe1 100644 --- a/drivers/block/drbd/drbd_bitmap.c +++ b/drivers/block/drbd/drbd_bitmap.c | |||
@@ -113,54 +113,54 @@ struct drbd_bitmap { | |||
113 | }; | 113 | }; |
114 | 114 | ||
115 | #define bm_print_lock_info(m) __bm_print_lock_info(m, __func__) | 115 | #define bm_print_lock_info(m) __bm_print_lock_info(m, __func__) |
116 | static void __bm_print_lock_info(struct drbd_conf *mdev, const char *func) | 116 | static void __bm_print_lock_info(struct drbd_device *device, const char *func) |
117 | { | 117 | { |
118 | struct drbd_bitmap *b = mdev->bitmap; | 118 | struct drbd_bitmap *b = device->bitmap; |
119 | if (!__ratelimit(&drbd_ratelimit_state)) | 119 | if (!__ratelimit(&drbd_ratelimit_state)) |
120 | return; | 120 | return; |
121 | dev_err(DEV, "FIXME %s in %s, bitmap locked for '%s' by %s\n", | 121 | drbd_err(device, "FIXME %s[%d] in %s, bitmap locked for '%s' by %s[%d]\n", |
122 | drbd_task_to_thread_name(mdev->tconn, current), | 122 | current->comm, task_pid_nr(current), |
123 | func, b->bm_why ?: "?", | 123 | func, b->bm_why ?: "?", |
124 | drbd_task_to_thread_name(mdev->tconn, b->bm_task)); | 124 | b->bm_task->comm, task_pid_nr(b->bm_task)); |
125 | } | 125 | } |
126 | 126 | ||
127 | void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags) | 127 | void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags) |
128 | { | 128 | { |
129 | struct drbd_bitmap *b = mdev->bitmap; | 129 | struct drbd_bitmap *b = device->bitmap; |
130 | int trylock_failed; | 130 | int trylock_failed; |
131 | 131 | ||
132 | if (!b) { | 132 | if (!b) { |
133 | dev_err(DEV, "FIXME no bitmap in drbd_bm_lock!?\n"); | 133 | drbd_err(device, "FIXME no bitmap in drbd_bm_lock!?\n"); |
134 | return; | 134 | return; |
135 | } | 135 | } |
136 | 136 | ||
137 | trylock_failed = !mutex_trylock(&b->bm_change); | 137 | trylock_failed = !mutex_trylock(&b->bm_change); |
138 | 138 | ||
139 | if (trylock_failed) { | 139 | if (trylock_failed) { |
140 | dev_warn(DEV, "%s going to '%s' but bitmap already locked for '%s' by %s\n", | 140 | drbd_warn(device, "%s[%d] going to '%s' but bitmap already locked for '%s' by %s[%d]\n", |
141 | drbd_task_to_thread_name(mdev->tconn, current), | 141 | current->comm, task_pid_nr(current), |
142 | why, b->bm_why ?: "?", | 142 | why, b->bm_why ?: "?", |
143 | drbd_task_to_thread_name(mdev->tconn, b->bm_task)); | 143 | b->bm_task->comm, task_pid_nr(b->bm_task)); |
144 | mutex_lock(&b->bm_change); | 144 | mutex_lock(&b->bm_change); |
145 | } | 145 | } |
146 | if (BM_LOCKED_MASK & b->bm_flags) | 146 | if (BM_LOCKED_MASK & b->bm_flags) |
147 | dev_err(DEV, "FIXME bitmap already locked in bm_lock\n"); | 147 | drbd_err(device, "FIXME bitmap already locked in bm_lock\n"); |
148 | b->bm_flags |= flags & BM_LOCKED_MASK; | 148 | b->bm_flags |= flags & BM_LOCKED_MASK; |
149 | 149 | ||
150 | b->bm_why = why; | 150 | b->bm_why = why; |
151 | b->bm_task = current; | 151 | b->bm_task = current; |
152 | } | 152 | } |
153 | 153 | ||
154 | void drbd_bm_unlock(struct drbd_conf *mdev) | 154 | void drbd_bm_unlock(struct drbd_device *device) |
155 | { | 155 | { |
156 | struct drbd_bitmap *b = mdev->bitmap; | 156 | struct drbd_bitmap *b = device->bitmap; |
157 | if (!b) { | 157 | if (!b) { |
158 | dev_err(DEV, "FIXME no bitmap in drbd_bm_unlock!?\n"); | 158 | drbd_err(device, "FIXME no bitmap in drbd_bm_unlock!?\n"); |
159 | return; | 159 | return; |
160 | } | 160 | } |
161 | 161 | ||
162 | if (!(BM_LOCKED_MASK & mdev->bitmap->bm_flags)) | 162 | if (!(BM_LOCKED_MASK & device->bitmap->bm_flags)) |
163 | dev_err(DEV, "FIXME bitmap not locked in bm_unlock\n"); | 163 | drbd_err(device, "FIXME bitmap not locked in bm_unlock\n"); |
164 | 164 | ||
165 | b->bm_flags &= ~BM_LOCKED_MASK; | 165 | b->bm_flags &= ~BM_LOCKED_MASK; |
166 | b->bm_why = NULL; | 166 | b->bm_why = NULL; |
@@ -211,19 +211,19 @@ static unsigned long bm_page_to_idx(struct page *page) | |||
211 | /* As is very unlikely that the same page is under IO from more than one | 211 | /* As is very unlikely that the same page is under IO from more than one |
212 | * context, we can get away with a bit per page and one wait queue per bitmap. | 212 | * context, we can get away with a bit per page and one wait queue per bitmap. |
213 | */ | 213 | */ |
214 | static void bm_page_lock_io(struct drbd_conf *mdev, int page_nr) | 214 | static void bm_page_lock_io(struct drbd_device *device, int page_nr) |
215 | { | 215 | { |
216 | struct drbd_bitmap *b = mdev->bitmap; | 216 | struct drbd_bitmap *b = device->bitmap; |
217 | void *addr = &page_private(b->bm_pages[page_nr]); | 217 | void *addr = &page_private(b->bm_pages[page_nr]); |
218 | wait_event(b->bm_io_wait, !test_and_set_bit(BM_PAGE_IO_LOCK, addr)); | 218 | wait_event(b->bm_io_wait, !test_and_set_bit(BM_PAGE_IO_LOCK, addr)); |
219 | } | 219 | } |
220 | 220 | ||
221 | static void bm_page_unlock_io(struct drbd_conf *mdev, int page_nr) | 221 | static void bm_page_unlock_io(struct drbd_device *device, int page_nr) |
222 | { | 222 | { |
223 | struct drbd_bitmap *b = mdev->bitmap; | 223 | struct drbd_bitmap *b = device->bitmap; |
224 | void *addr = &page_private(b->bm_pages[page_nr]); | 224 | void *addr = &page_private(b->bm_pages[page_nr]); |
225 | clear_bit_unlock(BM_PAGE_IO_LOCK, addr); | 225 | clear_bit_unlock(BM_PAGE_IO_LOCK, addr); |
226 | wake_up(&mdev->bitmap->bm_io_wait); | 226 | wake_up(&device->bitmap->bm_io_wait); |
227 | } | 227 | } |
228 | 228 | ||
229 | /* set _before_ submit_io, so it may be reset due to being changed | 229 | /* set _before_ submit_io, so it may be reset due to being changed |
@@ -242,22 +242,22 @@ static void bm_set_page_need_writeout(struct page *page) | |||
242 | 242 | ||
243 | /** | 243 | /** |
244 | * drbd_bm_mark_for_writeout() - mark a page with a "hint" to be considered for writeout | 244 | * drbd_bm_mark_for_writeout() - mark a page with a "hint" to be considered for writeout |
245 | * @mdev: DRBD device. | 245 | * @device: DRBD device. |
246 | * @page_nr: the bitmap page to mark with the "hint" flag | 246 | * @page_nr: the bitmap page to mark with the "hint" flag |
247 | * | 247 | * |
248 | * From within an activity log transaction, we mark a few pages with these | 248 | * From within an activity log transaction, we mark a few pages with these |
249 | * hints, then call drbd_bm_write_hinted(), which will only write out changed | 249 | * hints, then call drbd_bm_write_hinted(), which will only write out changed |
250 | * pages which are flagged with this mark. | 250 | * pages which are flagged with this mark. |
251 | */ | 251 | */ |
252 | void drbd_bm_mark_for_writeout(struct drbd_conf *mdev, int page_nr) | 252 | void drbd_bm_mark_for_writeout(struct drbd_device *device, int page_nr) |
253 | { | 253 | { |
254 | struct page *page; | 254 | struct page *page; |
255 | if (page_nr >= mdev->bitmap->bm_number_of_pages) { | 255 | if (page_nr >= device->bitmap->bm_number_of_pages) { |
256 | dev_warn(DEV, "BAD: page_nr: %u, number_of_pages: %u\n", | 256 | drbd_warn(device, "BAD: page_nr: %u, number_of_pages: %u\n", |
257 | page_nr, (int)mdev->bitmap->bm_number_of_pages); | 257 | page_nr, (int)device->bitmap->bm_number_of_pages); |
258 | return; | 258 | return; |
259 | } | 259 | } |
260 | page = mdev->bitmap->bm_pages[page_nr]; | 260 | page = device->bitmap->bm_pages[page_nr]; |
261 | set_bit(BM_PAGE_HINT_WRITEOUT, &page_private(page)); | 261 | set_bit(BM_PAGE_HINT_WRITEOUT, &page_private(page)); |
262 | } | 262 | } |
263 | 263 | ||
@@ -340,7 +340,7 @@ static void bm_unmap(unsigned long *p_addr) | |||
340 | 340 | ||
341 | /* | 341 | /* |
342 | * actually most functions herein should take a struct drbd_bitmap*, not a | 342 | * actually most functions herein should take a struct drbd_bitmap*, not a |
343 | * struct drbd_conf*, but for the debug macros I like to have the mdev around | 343 | * struct drbd_device*, but for the debug macros I like to have the device around |
344 | * to be able to report device specific. | 344 | * to be able to report device specific. |
345 | */ | 345 | */ |
346 | 346 | ||
@@ -436,11 +436,11 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want) | |||
436 | 436 | ||
437 | /* | 437 | /* |
438 | * called on driver init only. TODO call when a device is created. | 438 | * called on driver init only. TODO call when a device is created. |
439 | * allocates the drbd_bitmap, and stores it in mdev->bitmap. | 439 | * allocates the drbd_bitmap, and stores it in device->bitmap. |
440 | */ | 440 | */ |
441 | int drbd_bm_init(struct drbd_conf *mdev) | 441 | int drbd_bm_init(struct drbd_device *device) |
442 | { | 442 | { |
443 | struct drbd_bitmap *b = mdev->bitmap; | 443 | struct drbd_bitmap *b = device->bitmap; |
444 | WARN_ON(b != NULL); | 444 | WARN_ON(b != NULL); |
445 | b = kzalloc(sizeof(struct drbd_bitmap), GFP_KERNEL); | 445 | b = kzalloc(sizeof(struct drbd_bitmap), GFP_KERNEL); |
446 | if (!b) | 446 | if (!b) |
@@ -449,28 +449,28 @@ int drbd_bm_init(struct drbd_conf *mdev) | |||
449 | mutex_init(&b->bm_change); | 449 | mutex_init(&b->bm_change); |
450 | init_waitqueue_head(&b->bm_io_wait); | 450 | init_waitqueue_head(&b->bm_io_wait); |
451 | 451 | ||
452 | mdev->bitmap = b; | 452 | device->bitmap = b; |
453 | 453 | ||
454 | return 0; | 454 | return 0; |
455 | } | 455 | } |
456 | 456 | ||
457 | sector_t drbd_bm_capacity(struct drbd_conf *mdev) | 457 | sector_t drbd_bm_capacity(struct drbd_device *device) |
458 | { | 458 | { |
459 | if (!expect(mdev->bitmap)) | 459 | if (!expect(device->bitmap)) |
460 | return 0; | 460 | return 0; |
461 | return mdev->bitmap->bm_dev_capacity; | 461 | return device->bitmap->bm_dev_capacity; |
462 | } | 462 | } |
463 | 463 | ||
464 | /* called on driver unload. TODO: call when a device is destroyed. | 464 | /* called on driver unload. TODO: call when a device is destroyed. |
465 | */ | 465 | */ |
466 | void drbd_bm_cleanup(struct drbd_conf *mdev) | 466 | void drbd_bm_cleanup(struct drbd_device *device) |
467 | { | 467 | { |
468 | if (!expect(mdev->bitmap)) | 468 | if (!expect(device->bitmap)) |
469 | return; | 469 | return; |
470 | bm_free_pages(mdev->bitmap->bm_pages, mdev->bitmap->bm_number_of_pages); | 470 | bm_free_pages(device->bitmap->bm_pages, device->bitmap->bm_number_of_pages); |
471 | bm_vk_free(mdev->bitmap->bm_pages, (BM_P_VMALLOCED & mdev->bitmap->bm_flags)); | 471 | bm_vk_free(device->bitmap->bm_pages, (BM_P_VMALLOCED & device->bitmap->bm_flags)); |
472 | kfree(mdev->bitmap); | 472 | kfree(device->bitmap); |
473 | mdev->bitmap = NULL; | 473 | device->bitmap = NULL; |
474 | } | 474 | } |
475 | 475 | ||
476 | /* | 476 | /* |
@@ -631,9 +631,9 @@ static u64 drbd_md_on_disk_bits(struct drbd_backing_dev *ldev) | |||
631 | * In case this is actually a resize, we copy the old bitmap into the new one. | 631 | * In case this is actually a resize, we copy the old bitmap into the new one. |
632 | * Otherwise, the bitmap is initialized to all bits set. | 632 | * Otherwise, the bitmap is initialized to all bits set. |
633 | */ | 633 | */ |
634 | int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | 634 | int drbd_bm_resize(struct drbd_device *device, sector_t capacity, int set_new_bits) |
635 | { | 635 | { |
636 | struct drbd_bitmap *b = mdev->bitmap; | 636 | struct drbd_bitmap *b = device->bitmap; |
637 | unsigned long bits, words, owords, obits; | 637 | unsigned long bits, words, owords, obits; |
638 | unsigned long want, have, onpages; /* number of pages */ | 638 | unsigned long want, have, onpages; /* number of pages */ |
639 | struct page **npages, **opages = NULL; | 639 | struct page **npages, **opages = NULL; |
@@ -643,9 +643,9 @@ int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | |||
643 | if (!expect(b)) | 643 | if (!expect(b)) |
644 | return -ENOMEM; | 644 | return -ENOMEM; |
645 | 645 | ||
646 | drbd_bm_lock(mdev, "resize", BM_LOCKED_MASK); | 646 | drbd_bm_lock(device, "resize", BM_LOCKED_MASK); |
647 | 647 | ||
648 | dev_info(DEV, "drbd_bm_resize called with capacity == %llu\n", | 648 | drbd_info(device, "drbd_bm_resize called with capacity == %llu\n", |
649 | (unsigned long long)capacity); | 649 | (unsigned long long)capacity); |
650 | 650 | ||
651 | if (capacity == b->bm_dev_capacity) | 651 | if (capacity == b->bm_dev_capacity) |
@@ -678,12 +678,12 @@ int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | |||
678 | */ | 678 | */ |
679 | words = ALIGN(bits, 64) >> LN2_BPL; | 679 | words = ALIGN(bits, 64) >> LN2_BPL; |
680 | 680 | ||
681 | if (get_ldev(mdev)) { | 681 | if (get_ldev(device)) { |
682 | u64 bits_on_disk = drbd_md_on_disk_bits(mdev->ldev); | 682 | u64 bits_on_disk = drbd_md_on_disk_bits(device->ldev); |
683 | put_ldev(mdev); | 683 | put_ldev(device); |
684 | if (bits > bits_on_disk) { | 684 | if (bits > bits_on_disk) { |
685 | dev_info(DEV, "bits = %lu\n", bits); | 685 | drbd_info(device, "bits = %lu\n", bits); |
686 | dev_info(DEV, "bits_on_disk = %llu\n", bits_on_disk); | 686 | drbd_info(device, "bits_on_disk = %llu\n", bits_on_disk); |
687 | err = -ENOSPC; | 687 | err = -ENOSPC; |
688 | goto out; | 688 | goto out; |
689 | } | 689 | } |
@@ -692,10 +692,10 @@ int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | |||
692 | want = ALIGN(words*sizeof(long), PAGE_SIZE) >> PAGE_SHIFT; | 692 | want = ALIGN(words*sizeof(long), PAGE_SIZE) >> PAGE_SHIFT; |
693 | have = b->bm_number_of_pages; | 693 | have = b->bm_number_of_pages; |
694 | if (want == have) { | 694 | if (want == have) { |
695 | D_ASSERT(b->bm_pages != NULL); | 695 | D_ASSERT(device, b->bm_pages != NULL); |
696 | npages = b->bm_pages; | 696 | npages = b->bm_pages; |
697 | } else { | 697 | } else { |
698 | if (drbd_insert_fault(mdev, DRBD_FAULT_BM_ALLOC)) | 698 | if (drbd_insert_fault(device, DRBD_FAULT_BM_ALLOC)) |
699 | npages = NULL; | 699 | npages = NULL; |
700 | else | 700 | else |
701 | npages = bm_realloc_pages(b, want); | 701 | npages = bm_realloc_pages(b, want); |
@@ -742,10 +742,10 @@ int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | |||
742 | bm_vk_free(opages, opages_vmalloced); | 742 | bm_vk_free(opages, opages_vmalloced); |
743 | if (!growing) | 743 | if (!growing) |
744 | b->bm_set = bm_count_bits(b); | 744 | b->bm_set = bm_count_bits(b); |
745 | dev_info(DEV, "resync bitmap: bits=%lu words=%lu pages=%lu\n", bits, words, want); | 745 | drbd_info(device, "resync bitmap: bits=%lu words=%lu pages=%lu\n", bits, words, want); |
746 | 746 | ||
747 | out: | 747 | out: |
748 | drbd_bm_unlock(mdev); | 748 | drbd_bm_unlock(device); |
749 | return err; | 749 | return err; |
750 | } | 750 | } |
751 | 751 | ||
@@ -757,9 +757,9 @@ int drbd_bm_resize(struct drbd_conf *mdev, sector_t capacity, int set_new_bits) | |||
757 | * | 757 | * |
758 | * maybe bm_set should be atomic_t ? | 758 | * maybe bm_set should be atomic_t ? |
759 | */ | 759 | */ |
760 | unsigned long _drbd_bm_total_weight(struct drbd_conf *mdev) | 760 | unsigned long _drbd_bm_total_weight(struct drbd_device *device) |
761 | { | 761 | { |
762 | struct drbd_bitmap *b = mdev->bitmap; | 762 | struct drbd_bitmap *b = device->bitmap; |
763 | unsigned long s; | 763 | unsigned long s; |
764 | unsigned long flags; | 764 | unsigned long flags; |
765 | 765 | ||
@@ -775,20 +775,20 @@ unsigned long _drbd_bm_total_weight(struct drbd_conf *mdev) | |||
775 | return s; | 775 | return s; |
776 | } | 776 | } |
777 | 777 | ||
778 | unsigned long drbd_bm_total_weight(struct drbd_conf *mdev) | 778 | unsigned long drbd_bm_total_weight(struct drbd_device *device) |
779 | { | 779 | { |
780 | unsigned long s; | 780 | unsigned long s; |
781 | /* if I don't have a disk, I don't know about out-of-sync status */ | 781 | /* if I don't have a disk, I don't know about out-of-sync status */ |
782 | if (!get_ldev_if_state(mdev, D_NEGOTIATING)) | 782 | if (!get_ldev_if_state(device, D_NEGOTIATING)) |
783 | return 0; | 783 | return 0; |
784 | s = _drbd_bm_total_weight(mdev); | 784 | s = _drbd_bm_total_weight(device); |
785 | put_ldev(mdev); | 785 | put_ldev(device); |
786 | return s; | 786 | return s; |
787 | } | 787 | } |
788 | 788 | ||
789 | size_t drbd_bm_words(struct drbd_conf *mdev) | 789 | size_t drbd_bm_words(struct drbd_device *device) |
790 | { | 790 | { |
791 | struct drbd_bitmap *b = mdev->bitmap; | 791 | struct drbd_bitmap *b = device->bitmap; |
792 | if (!expect(b)) | 792 | if (!expect(b)) |
793 | return 0; | 793 | return 0; |
794 | if (!expect(b->bm_pages)) | 794 | if (!expect(b->bm_pages)) |
@@ -797,9 +797,9 @@ size_t drbd_bm_words(struct drbd_conf *mdev) | |||
797 | return b->bm_words; | 797 | return b->bm_words; |
798 | } | 798 | } |
799 | 799 | ||
800 | unsigned long drbd_bm_bits(struct drbd_conf *mdev) | 800 | unsigned long drbd_bm_bits(struct drbd_device *device) |
801 | { | 801 | { |
802 | struct drbd_bitmap *b = mdev->bitmap; | 802 | struct drbd_bitmap *b = device->bitmap; |
803 | if (!expect(b)) | 803 | if (!expect(b)) |
804 | return 0; | 804 | return 0; |
805 | 805 | ||
@@ -811,10 +811,10 @@ unsigned long drbd_bm_bits(struct drbd_conf *mdev) | |||
811 | * bitmap must be locked by drbd_bm_lock. | 811 | * bitmap must be locked by drbd_bm_lock. |
812 | * currently only used from receive_bitmap. | 812 | * currently only used from receive_bitmap. |
813 | */ | 813 | */ |
814 | void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset, size_t number, | 814 | void drbd_bm_merge_lel(struct drbd_device *device, size_t offset, size_t number, |
815 | unsigned long *buffer) | 815 | unsigned long *buffer) |
816 | { | 816 | { |
817 | struct drbd_bitmap *b = mdev->bitmap; | 817 | struct drbd_bitmap *b = device->bitmap; |
818 | unsigned long *p_addr, *bm; | 818 | unsigned long *p_addr, *bm; |
819 | unsigned long word, bits; | 819 | unsigned long word, bits; |
820 | unsigned int idx; | 820 | unsigned int idx; |
@@ -860,10 +860,10 @@ void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset, size_t number, | |||
860 | /* copy number words from the bitmap starting at offset into the buffer. | 860 | /* copy number words from the bitmap starting at offset into the buffer. |
861 | * buffer[i] will be little endian unsigned long. | 861 | * buffer[i] will be little endian unsigned long. |
862 | */ | 862 | */ |
863 | void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset, size_t number, | 863 | void drbd_bm_get_lel(struct drbd_device *device, size_t offset, size_t number, |
864 | unsigned long *buffer) | 864 | unsigned long *buffer) |
865 | { | 865 | { |
866 | struct drbd_bitmap *b = mdev->bitmap; | 866 | struct drbd_bitmap *b = device->bitmap; |
867 | unsigned long *p_addr, *bm; | 867 | unsigned long *p_addr, *bm; |
868 | size_t end, do_now; | 868 | size_t end, do_now; |
869 | 869 | ||
@@ -878,7 +878,7 @@ void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset, size_t number, | |||
878 | if ((offset >= b->bm_words) || | 878 | if ((offset >= b->bm_words) || |
879 | (end > b->bm_words) || | 879 | (end > b->bm_words) || |
880 | (number <= 0)) | 880 | (number <= 0)) |
881 | dev_err(DEV, "offset=%lu number=%lu bm_words=%lu\n", | 881 | drbd_err(device, "offset=%lu number=%lu bm_words=%lu\n", |
882 | (unsigned long) offset, | 882 | (unsigned long) offset, |
883 | (unsigned long) number, | 883 | (unsigned long) number, |
884 | (unsigned long) b->bm_words); | 884 | (unsigned long) b->bm_words); |
@@ -897,9 +897,9 @@ void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset, size_t number, | |||
897 | } | 897 | } |
898 | 898 | ||
899 | /* set all bits in the bitmap */ | 899 | /* set all bits in the bitmap */ |
900 | void drbd_bm_set_all(struct drbd_conf *mdev) | 900 | void drbd_bm_set_all(struct drbd_device *device) |
901 | { | 901 | { |
902 | struct drbd_bitmap *b = mdev->bitmap; | 902 | struct drbd_bitmap *b = device->bitmap; |
903 | if (!expect(b)) | 903 | if (!expect(b)) |
904 | return; | 904 | return; |
905 | if (!expect(b->bm_pages)) | 905 | if (!expect(b->bm_pages)) |
@@ -913,9 +913,9 @@ void drbd_bm_set_all(struct drbd_conf *mdev) | |||
913 | } | 913 | } |
914 | 914 | ||
915 | /* clear all bits in the bitmap */ | 915 | /* clear all bits in the bitmap */ |
916 | void drbd_bm_clear_all(struct drbd_conf *mdev) | 916 | void drbd_bm_clear_all(struct drbd_device *device) |
917 | { | 917 | { |
918 | struct drbd_bitmap *b = mdev->bitmap; | 918 | struct drbd_bitmap *b = device->bitmap; |
919 | if (!expect(b)) | 919 | if (!expect(b)) |
920 | return; | 920 | return; |
921 | if (!expect(b->bm_pages)) | 921 | if (!expect(b->bm_pages)) |
@@ -928,7 +928,7 @@ void drbd_bm_clear_all(struct drbd_conf *mdev) | |||
928 | } | 928 | } |
929 | 929 | ||
930 | struct bm_aio_ctx { | 930 | struct bm_aio_ctx { |
931 | struct drbd_conf *mdev; | 931 | struct drbd_device *device; |
932 | atomic_t in_flight; | 932 | atomic_t in_flight; |
933 | unsigned int done; | 933 | unsigned int done; |
934 | unsigned flags; | 934 | unsigned flags; |
@@ -943,7 +943,7 @@ static void bm_aio_ctx_destroy(struct kref *kref) | |||
943 | { | 943 | { |
944 | struct bm_aio_ctx *ctx = container_of(kref, struct bm_aio_ctx, kref); | 944 | struct bm_aio_ctx *ctx = container_of(kref, struct bm_aio_ctx, kref); |
945 | 945 | ||
946 | put_ldev(ctx->mdev); | 946 | put_ldev(ctx->device); |
947 | kfree(ctx); | 947 | kfree(ctx); |
948 | } | 948 | } |
949 | 949 | ||
@@ -951,8 +951,8 @@ static void bm_aio_ctx_destroy(struct kref *kref) | |||
951 | static void bm_async_io_complete(struct bio *bio, int error) | 951 | static void bm_async_io_complete(struct bio *bio, int error) |
952 | { | 952 | { |
953 | struct bm_aio_ctx *ctx = bio->bi_private; | 953 | struct bm_aio_ctx *ctx = bio->bi_private; |
954 | struct drbd_conf *mdev = ctx->mdev; | 954 | struct drbd_device *device = ctx->device; |
955 | struct drbd_bitmap *b = mdev->bitmap; | 955 | struct drbd_bitmap *b = device->bitmap; |
956 | unsigned int idx = bm_page_to_idx(bio->bi_io_vec[0].bv_page); | 956 | unsigned int idx = bm_page_to_idx(bio->bi_io_vec[0].bv_page); |
957 | int uptodate = bio_flagged(bio, BIO_UPTODATE); | 957 | int uptodate = bio_flagged(bio, BIO_UPTODATE); |
958 | 958 | ||
@@ -966,7 +966,7 @@ static void bm_async_io_complete(struct bio *bio, int error) | |||
966 | 966 | ||
967 | if ((ctx->flags & BM_AIO_COPY_PAGES) == 0 && | 967 | if ((ctx->flags & BM_AIO_COPY_PAGES) == 0 && |
968 | !bm_test_page_unchanged(b->bm_pages[idx])) | 968 | !bm_test_page_unchanged(b->bm_pages[idx])) |
969 | dev_warn(DEV, "bitmap page idx %u changed during IO!\n", idx); | 969 | drbd_warn(device, "bitmap page idx %u changed during IO!\n", idx); |
970 | 970 | ||
971 | if (error) { | 971 | if (error) { |
972 | /* ctx error will hold the completed-last non-zero error code, | 972 | /* ctx error will hold the completed-last non-zero error code, |
@@ -976,14 +976,14 @@ static void bm_async_io_complete(struct bio *bio, int error) | |||
976 | /* Not identical to on disk version of it. | 976 | /* Not identical to on disk version of it. |
977 | * Is BM_PAGE_IO_ERROR enough? */ | 977 | * Is BM_PAGE_IO_ERROR enough? */ |
978 | if (__ratelimit(&drbd_ratelimit_state)) | 978 | if (__ratelimit(&drbd_ratelimit_state)) |
979 | dev_err(DEV, "IO ERROR %d on bitmap page idx %u\n", | 979 | drbd_err(device, "IO ERROR %d on bitmap page idx %u\n", |
980 | error, idx); | 980 | error, idx); |
981 | } else { | 981 | } else { |
982 | bm_clear_page_io_err(b->bm_pages[idx]); | 982 | bm_clear_page_io_err(b->bm_pages[idx]); |
983 | dynamic_dev_dbg(DEV, "bitmap page idx %u completed\n", idx); | 983 | dynamic_drbd_dbg(device, "bitmap page idx %u completed\n", idx); |
984 | } | 984 | } |
985 | 985 | ||
986 | bm_page_unlock_io(mdev, idx); | 986 | bm_page_unlock_io(device, idx); |
987 | 987 | ||
988 | if (ctx->flags & BM_AIO_COPY_PAGES) | 988 | if (ctx->flags & BM_AIO_COPY_PAGES) |
989 | mempool_free(bio->bi_io_vec[0].bv_page, drbd_md_io_page_pool); | 989 | mempool_free(bio->bi_io_vec[0].bv_page, drbd_md_io_page_pool); |
@@ -992,7 +992,7 @@ static void bm_async_io_complete(struct bio *bio, int error) | |||
992 | 992 | ||
993 | if (atomic_dec_and_test(&ctx->in_flight)) { | 993 | if (atomic_dec_and_test(&ctx->in_flight)) { |
994 | ctx->done = 1; | 994 | ctx->done = 1; |
995 | wake_up(&mdev->misc_wait); | 995 | wake_up(&device->misc_wait); |
996 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); | 996 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); |
997 | } | 997 | } |
998 | } | 998 | } |
@@ -1000,23 +1000,23 @@ static void bm_async_io_complete(struct bio *bio, int error) | |||
1000 | static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must_hold(local) | 1000 | static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must_hold(local) |
1001 | { | 1001 | { |
1002 | struct bio *bio = bio_alloc_drbd(GFP_NOIO); | 1002 | struct bio *bio = bio_alloc_drbd(GFP_NOIO); |
1003 | struct drbd_conf *mdev = ctx->mdev; | 1003 | struct drbd_device *device = ctx->device; |
1004 | struct drbd_bitmap *b = mdev->bitmap; | 1004 | struct drbd_bitmap *b = device->bitmap; |
1005 | struct page *page; | 1005 | struct page *page; |
1006 | unsigned int len; | 1006 | unsigned int len; |
1007 | 1007 | ||
1008 | sector_t on_disk_sector = | 1008 | sector_t on_disk_sector = |
1009 | mdev->ldev->md.md_offset + mdev->ldev->md.bm_offset; | 1009 | device->ldev->md.md_offset + device->ldev->md.bm_offset; |
1010 | on_disk_sector += ((sector_t)page_nr) << (PAGE_SHIFT-9); | 1010 | on_disk_sector += ((sector_t)page_nr) << (PAGE_SHIFT-9); |
1011 | 1011 | ||
1012 | /* this might happen with very small | 1012 | /* this might happen with very small |
1013 | * flexible external meta data device, | 1013 | * flexible external meta data device, |
1014 | * or with PAGE_SIZE > 4k */ | 1014 | * or with PAGE_SIZE > 4k */ |
1015 | len = min_t(unsigned int, PAGE_SIZE, | 1015 | len = min_t(unsigned int, PAGE_SIZE, |
1016 | (drbd_md_last_sector(mdev->ldev) - on_disk_sector + 1)<<9); | 1016 | (drbd_md_last_sector(device->ldev) - on_disk_sector + 1)<<9); |
1017 | 1017 | ||
1018 | /* serialize IO on this page */ | 1018 | /* serialize IO on this page */ |
1019 | bm_page_lock_io(mdev, page_nr); | 1019 | bm_page_lock_io(device, page_nr); |
1020 | /* before memcpy and submit, | 1020 | /* before memcpy and submit, |
1021 | * so it can be redirtied any time */ | 1021 | * so it can be redirtied any time */ |
1022 | bm_set_page_unchanged(b->bm_pages[page_nr]); | 1022 | bm_set_page_unchanged(b->bm_pages[page_nr]); |
@@ -1027,7 +1027,7 @@ static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must | |||
1027 | bm_store_page_idx(page, page_nr); | 1027 | bm_store_page_idx(page, page_nr); |
1028 | } else | 1028 | } else |
1029 | page = b->bm_pages[page_nr]; | 1029 | page = b->bm_pages[page_nr]; |
1030 | bio->bi_bdev = mdev->ldev->md_bdev; | 1030 | bio->bi_bdev = device->ldev->md_bdev; |
1031 | bio->bi_iter.bi_sector = on_disk_sector; | 1031 | bio->bi_iter.bi_sector = on_disk_sector; |
1032 | /* bio_add_page of a single page to an empty bio will always succeed, | 1032 | /* bio_add_page of a single page to an empty bio will always succeed, |
1033 | * according to api. Do we want to assert that? */ | 1033 | * according to api. Do we want to assert that? */ |
@@ -1035,24 +1035,24 @@ static void bm_page_io_async(struct bm_aio_ctx *ctx, int page_nr, int rw) __must | |||
1035 | bio->bi_private = ctx; | 1035 | bio->bi_private = ctx; |
1036 | bio->bi_end_io = bm_async_io_complete; | 1036 | bio->bi_end_io = bm_async_io_complete; |
1037 | 1037 | ||
1038 | if (drbd_insert_fault(mdev, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD)) { | 1038 | if (drbd_insert_fault(device, (rw & WRITE) ? DRBD_FAULT_MD_WR : DRBD_FAULT_MD_RD)) { |
1039 | bio->bi_rw |= rw; | 1039 | bio->bi_rw |= rw; |
1040 | bio_endio(bio, -EIO); | 1040 | bio_endio(bio, -EIO); |
1041 | } else { | 1041 | } else { |
1042 | submit_bio(rw, bio); | 1042 | submit_bio(rw, bio); |
1043 | /* this should not count as user activity and cause the | 1043 | /* this should not count as user activity and cause the |
1044 | * resync to throttle -- see drbd_rs_should_slow_down(). */ | 1044 | * resync to throttle -- see drbd_rs_should_slow_down(). */ |
1045 | atomic_add(len >> 9, &mdev->rs_sect_ev); | 1045 | atomic_add(len >> 9, &device->rs_sect_ev); |
1046 | } | 1046 | } |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | /* | 1049 | /* |
1050 | * bm_rw: read/write the whole bitmap from/to its on disk location. | 1050 | * bm_rw: read/write the whole bitmap from/to its on disk location. |
1051 | */ | 1051 | */ |
1052 | static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_writeout_upper_idx) __must_hold(local) | 1052 | static int bm_rw(struct drbd_device *device, int rw, unsigned flags, unsigned lazy_writeout_upper_idx) __must_hold(local) |
1053 | { | 1053 | { |
1054 | struct bm_aio_ctx *ctx; | 1054 | struct bm_aio_ctx *ctx; |
1055 | struct drbd_bitmap *b = mdev->bitmap; | 1055 | struct drbd_bitmap *b = device->bitmap; |
1056 | int num_pages, i, count = 0; | 1056 | int num_pages, i, count = 0; |
1057 | unsigned long now; | 1057 | unsigned long now; |
1058 | char ppb[10]; | 1058 | char ppb[10]; |
@@ -1072,7 +1072,7 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1072 | return -ENOMEM; | 1072 | return -ENOMEM; |
1073 | 1073 | ||
1074 | *ctx = (struct bm_aio_ctx) { | 1074 | *ctx = (struct bm_aio_ctx) { |
1075 | .mdev = mdev, | 1075 | .device = device, |
1076 | .in_flight = ATOMIC_INIT(1), | 1076 | .in_flight = ATOMIC_INIT(1), |
1077 | .done = 0, | 1077 | .done = 0, |
1078 | .flags = flags, | 1078 | .flags = flags, |
@@ -1080,8 +1080,8 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1080 | .kref = { ATOMIC_INIT(2) }, | 1080 | .kref = { ATOMIC_INIT(2) }, |
1081 | }; | 1081 | }; |
1082 | 1082 | ||
1083 | if (!get_ldev_if_state(mdev, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */ | 1083 | if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */ |
1084 | dev_err(DEV, "ASSERT FAILED: get_ldev_if_state() == 1 in bm_rw()\n"); | 1084 | drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in bm_rw()\n"); |
1085 | kfree(ctx); | 1085 | kfree(ctx); |
1086 | return -ENODEV; | 1086 | return -ENODEV; |
1087 | } | 1087 | } |
@@ -1106,14 +1106,14 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1106 | 1106 | ||
1107 | if (!(flags & BM_WRITE_ALL_PAGES) && | 1107 | if (!(flags & BM_WRITE_ALL_PAGES) && |
1108 | bm_test_page_unchanged(b->bm_pages[i])) { | 1108 | bm_test_page_unchanged(b->bm_pages[i])) { |
1109 | dynamic_dev_dbg(DEV, "skipped bm write for idx %u\n", i); | 1109 | dynamic_drbd_dbg(device, "skipped bm write for idx %u\n", i); |
1110 | continue; | 1110 | continue; |
1111 | } | 1111 | } |
1112 | /* during lazy writeout, | 1112 | /* during lazy writeout, |
1113 | * ignore those pages not marked for lazy writeout. */ | 1113 | * ignore those pages not marked for lazy writeout. */ |
1114 | if (lazy_writeout_upper_idx && | 1114 | if (lazy_writeout_upper_idx && |
1115 | !bm_test_page_lazy_writeout(b->bm_pages[i])) { | 1115 | !bm_test_page_lazy_writeout(b->bm_pages[i])) { |
1116 | dynamic_dev_dbg(DEV, "skipped bm lazy write for idx %u\n", i); | 1116 | dynamic_drbd_dbg(device, "skipped bm lazy write for idx %u\n", i); |
1117 | continue; | 1117 | continue; |
1118 | } | 1118 | } |
1119 | } | 1119 | } |
@@ -1132,19 +1132,19 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1132 | * "in_flight reached zero, all done" event. | 1132 | * "in_flight reached zero, all done" event. |
1133 | */ | 1133 | */ |
1134 | if (!atomic_dec_and_test(&ctx->in_flight)) | 1134 | if (!atomic_dec_and_test(&ctx->in_flight)) |
1135 | wait_until_done_or_force_detached(mdev, mdev->ldev, &ctx->done); | 1135 | wait_until_done_or_force_detached(device, device->ldev, &ctx->done); |
1136 | else | 1136 | else |
1137 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); | 1137 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); |
1138 | 1138 | ||
1139 | /* summary for global bitmap IO */ | 1139 | /* summary for global bitmap IO */ |
1140 | if (flags == 0) | 1140 | if (flags == 0) |
1141 | dev_info(DEV, "bitmap %s of %u pages took %lu jiffies\n", | 1141 | drbd_info(device, "bitmap %s of %u pages took %lu jiffies\n", |
1142 | rw == WRITE ? "WRITE" : "READ", | 1142 | rw == WRITE ? "WRITE" : "READ", |
1143 | count, jiffies - now); | 1143 | count, jiffies - now); |
1144 | 1144 | ||
1145 | if (ctx->error) { | 1145 | if (ctx->error) { |
1146 | dev_alert(DEV, "we had at least one MD IO ERROR during bitmap IO\n"); | 1146 | drbd_alert(device, "we had at least one MD IO ERROR during bitmap IO\n"); |
1147 | drbd_chk_io_error(mdev, 1, DRBD_META_IO_ERROR); | 1147 | drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR); |
1148 | err = -EIO; /* ctx->error ? */ | 1148 | err = -EIO; /* ctx->error ? */ |
1149 | } | 1149 | } |
1150 | 1150 | ||
@@ -1153,16 +1153,16 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1153 | 1153 | ||
1154 | now = jiffies; | 1154 | now = jiffies; |
1155 | if (rw == WRITE) { | 1155 | if (rw == WRITE) { |
1156 | drbd_md_flush(mdev); | 1156 | drbd_md_flush(device); |
1157 | } else /* rw == READ */ { | 1157 | } else /* rw == READ */ { |
1158 | b->bm_set = bm_count_bits(b); | 1158 | b->bm_set = bm_count_bits(b); |
1159 | dev_info(DEV, "recounting of set bits took additional %lu jiffies\n", | 1159 | drbd_info(device, "recounting of set bits took additional %lu jiffies\n", |
1160 | jiffies - now); | 1160 | jiffies - now); |
1161 | } | 1161 | } |
1162 | now = b->bm_set; | 1162 | now = b->bm_set; |
1163 | 1163 | ||
1164 | if (flags == 0) | 1164 | if (flags == 0) |
1165 | dev_info(DEV, "%s (%lu bits) marked out-of-sync by on disk bit-map.\n", | 1165 | drbd_info(device, "%s (%lu bits) marked out-of-sync by on disk bit-map.\n", |
1166 | ppsize(ppb, now << (BM_BLOCK_SHIFT-10)), now); | 1166 | ppsize(ppb, now << (BM_BLOCK_SHIFT-10)), now); |
1167 | 1167 | ||
1168 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); | 1168 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); |
@@ -1171,48 +1171,38 @@ static int bm_rw(struct drbd_conf *mdev, int rw, unsigned flags, unsigned lazy_w | |||
1171 | 1171 | ||
1172 | /** | 1172 | /** |
1173 | * drbd_bm_read() - Read the whole bitmap from its on disk location. | 1173 | * drbd_bm_read() - Read the whole bitmap from its on disk location. |
1174 | * @mdev: DRBD device. | 1174 | * @device: DRBD device. |
1175 | */ | 1175 | */ |
1176 | int drbd_bm_read(struct drbd_conf *mdev) __must_hold(local) | 1176 | int drbd_bm_read(struct drbd_device *device) __must_hold(local) |
1177 | { | 1177 | { |
1178 | return bm_rw(mdev, READ, 0, 0); | 1178 | return bm_rw(device, READ, 0, 0); |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | /** | 1181 | /** |
1182 | * drbd_bm_write() - Write the whole bitmap to its on disk location. | 1182 | * drbd_bm_write() - Write the whole bitmap to its on disk location. |
1183 | * @mdev: DRBD device. | 1183 | * @device: DRBD device. |
1184 | * | 1184 | * |
1185 | * Will only write pages that have changed since last IO. | 1185 | * Will only write pages that have changed since last IO. |
1186 | */ | 1186 | */ |
1187 | int drbd_bm_write(struct drbd_conf *mdev) __must_hold(local) | 1187 | int drbd_bm_write(struct drbd_device *device) __must_hold(local) |
1188 | { | 1188 | { |
1189 | return bm_rw(mdev, WRITE, 0, 0); | 1189 | return bm_rw(device, WRITE, 0, 0); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | /** | 1192 | /** |
1193 | * drbd_bm_write_all() - Write the whole bitmap to its on disk location. | 1193 | * drbd_bm_write_all() - Write the whole bitmap to its on disk location. |
1194 | * @mdev: DRBD device. | 1194 | * @device: DRBD device. |
1195 | * | 1195 | * |
1196 | * Will write all pages. | 1196 | * Will write all pages. |
1197 | */ | 1197 | */ |
1198 | int drbd_bm_write_all(struct drbd_conf *mdev) __must_hold(local) | 1198 | int drbd_bm_write_all(struct drbd_device *device) __must_hold(local) |
1199 | { | 1199 | { |
1200 | return bm_rw(mdev, WRITE, BM_WRITE_ALL_PAGES, 0); | 1200 | return bm_rw(device, WRITE, BM_WRITE_ALL_PAGES, 0); |
1201 | } | ||
1202 | |||
1203 | /** | ||
1204 | * drbd_bm_lazy_write_out() - Write bitmap pages 0 to @upper_idx-1, if they have changed. | ||
1205 | * @mdev: DRBD device. | ||
1206 | * @upper_idx: 0: write all changed pages; +ve: page index to stop scanning for changed pages | ||
1207 | */ | ||
1208 | int drbd_bm_write_lazy(struct drbd_conf *mdev, unsigned upper_idx) __must_hold(local) | ||
1209 | { | ||
1210 | return bm_rw(mdev, WRITE, BM_AIO_COPY_PAGES, upper_idx); | ||
1211 | } | 1201 | } |
1212 | 1202 | ||
1213 | /** | 1203 | /** |
1214 | * drbd_bm_write_copy_pages() - Write the whole bitmap to its on disk location. | 1204 | * drbd_bm_write_copy_pages() - Write the whole bitmap to its on disk location. |
1215 | * @mdev: DRBD device. | 1205 | * @device: DRBD device. |
1216 | * | 1206 | * |
1217 | * Will only write pages that have changed since last IO. | 1207 | * Will only write pages that have changed since last IO. |
1218 | * In contrast to drbd_bm_write(), this will copy the bitmap pages | 1208 | * In contrast to drbd_bm_write(), this will copy the bitmap pages |
@@ -1221,23 +1211,23 @@ int drbd_bm_write_lazy(struct drbd_conf *mdev, unsigned upper_idx) __must_hold(l | |||
1221 | * verify is aborted due to a failed peer disk, while local IO continues, or | 1211 | * verify is aborted due to a failed peer disk, while local IO continues, or |
1222 | * pending resync acks are still being processed. | 1212 | * pending resync acks are still being processed. |
1223 | */ | 1213 | */ |
1224 | int drbd_bm_write_copy_pages(struct drbd_conf *mdev) __must_hold(local) | 1214 | int drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local) |
1225 | { | 1215 | { |
1226 | return bm_rw(mdev, WRITE, BM_AIO_COPY_PAGES, 0); | 1216 | return bm_rw(device, WRITE, BM_AIO_COPY_PAGES, 0); |
1227 | } | 1217 | } |
1228 | 1218 | ||
1229 | /** | 1219 | /** |
1230 | * drbd_bm_write_hinted() - Write bitmap pages with "hint" marks, if they have changed. | 1220 | * drbd_bm_write_hinted() - Write bitmap pages with "hint" marks, if they have changed. |
1231 | * @mdev: DRBD device. | 1221 | * @device: DRBD device. |
1232 | */ | 1222 | */ |
1233 | int drbd_bm_write_hinted(struct drbd_conf *mdev) __must_hold(local) | 1223 | int drbd_bm_write_hinted(struct drbd_device *device) __must_hold(local) |
1234 | { | 1224 | { |
1235 | return bm_rw(mdev, WRITE, BM_AIO_WRITE_HINTED | BM_AIO_COPY_PAGES, 0); | 1225 | return bm_rw(device, WRITE, BM_AIO_WRITE_HINTED | BM_AIO_COPY_PAGES, 0); |
1236 | } | 1226 | } |
1237 | 1227 | ||
1238 | /** | 1228 | /** |
1239 | * drbd_bm_write_page() - Writes a PAGE_SIZE aligned piece of bitmap | 1229 | * drbd_bm_write_page() - Writes a PAGE_SIZE aligned piece of bitmap |
1240 | * @mdev: DRBD device. | 1230 | * @device: DRBD device. |
1241 | * @idx: bitmap page index | 1231 | * @idx: bitmap page index |
1242 | * | 1232 | * |
1243 | * We don't want to special case on logical_block_size of the backend device, | 1233 | * We don't want to special case on logical_block_size of the backend device, |
@@ -1247,13 +1237,13 @@ int drbd_bm_write_hinted(struct drbd_conf *mdev) __must_hold(local) | |||
1247 | * In case this becomes an issue on systems with larger PAGE_SIZE, | 1237 | * In case this becomes an issue on systems with larger PAGE_SIZE, |
1248 | * we may want to change this again to write 4k aligned 4k pieces. | 1238 | * we may want to change this again to write 4k aligned 4k pieces. |
1249 | */ | 1239 | */ |
1250 | int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(local) | 1240 | int drbd_bm_write_page(struct drbd_device *device, unsigned int idx) __must_hold(local) |
1251 | { | 1241 | { |
1252 | struct bm_aio_ctx *ctx; | 1242 | struct bm_aio_ctx *ctx; |
1253 | int err; | 1243 | int err; |
1254 | 1244 | ||
1255 | if (bm_test_page_unchanged(mdev->bitmap->bm_pages[idx])) { | 1245 | if (bm_test_page_unchanged(device->bitmap->bm_pages[idx])) { |
1256 | dynamic_dev_dbg(DEV, "skipped bm page write for idx %u\n", idx); | 1246 | dynamic_drbd_dbg(device, "skipped bm page write for idx %u\n", idx); |
1257 | return 0; | 1247 | return 0; |
1258 | } | 1248 | } |
1259 | 1249 | ||
@@ -1262,7 +1252,7 @@ int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(loc | |||
1262 | return -ENOMEM; | 1252 | return -ENOMEM; |
1263 | 1253 | ||
1264 | *ctx = (struct bm_aio_ctx) { | 1254 | *ctx = (struct bm_aio_ctx) { |
1265 | .mdev = mdev, | 1255 | .device = device, |
1266 | .in_flight = ATOMIC_INIT(1), | 1256 | .in_flight = ATOMIC_INIT(1), |
1267 | .done = 0, | 1257 | .done = 0, |
1268 | .flags = BM_AIO_COPY_PAGES, | 1258 | .flags = BM_AIO_COPY_PAGES, |
@@ -1270,21 +1260,21 @@ int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(loc | |||
1270 | .kref = { ATOMIC_INIT(2) }, | 1260 | .kref = { ATOMIC_INIT(2) }, |
1271 | }; | 1261 | }; |
1272 | 1262 | ||
1273 | if (!get_ldev_if_state(mdev, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */ | 1263 | if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in bm_aio_ctx_destroy() */ |
1274 | dev_err(DEV, "ASSERT FAILED: get_ldev_if_state() == 1 in drbd_bm_write_page()\n"); | 1264 | drbd_err(device, "ASSERT FAILED: get_ldev_if_state() == 1 in drbd_bm_write_page()\n"); |
1275 | kfree(ctx); | 1265 | kfree(ctx); |
1276 | return -ENODEV; | 1266 | return -ENODEV; |
1277 | } | 1267 | } |
1278 | 1268 | ||
1279 | bm_page_io_async(ctx, idx, WRITE_SYNC); | 1269 | bm_page_io_async(ctx, idx, WRITE_SYNC); |
1280 | wait_until_done_or_force_detached(mdev, mdev->ldev, &ctx->done); | 1270 | wait_until_done_or_force_detached(device, device->ldev, &ctx->done); |
1281 | 1271 | ||
1282 | if (ctx->error) | 1272 | if (ctx->error) |
1283 | drbd_chk_io_error(mdev, 1, DRBD_META_IO_ERROR); | 1273 | drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR); |
1284 | /* that causes us to detach, so the in memory bitmap will be | 1274 | /* that causes us to detach, so the in memory bitmap will be |
1285 | * gone in a moment as well. */ | 1275 | * gone in a moment as well. */ |
1286 | 1276 | ||
1287 | mdev->bm_writ_cnt++; | 1277 | device->bm_writ_cnt++; |
1288 | err = atomic_read(&ctx->in_flight) ? -EIO : ctx->error; | 1278 | err = atomic_read(&ctx->in_flight) ? -EIO : ctx->error; |
1289 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); | 1279 | kref_put(&ctx->kref, &bm_aio_ctx_destroy); |
1290 | return err; | 1280 | return err; |
@@ -1298,17 +1288,17 @@ int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(loc | |||
1298 | * | 1288 | * |
1299 | * this returns a bit number, NOT a sector! | 1289 | * this returns a bit number, NOT a sector! |
1300 | */ | 1290 | */ |
1301 | static unsigned long __bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo, | 1291 | static unsigned long __bm_find_next(struct drbd_device *device, unsigned long bm_fo, |
1302 | const int find_zero_bit) | 1292 | const int find_zero_bit) |
1303 | { | 1293 | { |
1304 | struct drbd_bitmap *b = mdev->bitmap; | 1294 | struct drbd_bitmap *b = device->bitmap; |
1305 | unsigned long *p_addr; | 1295 | unsigned long *p_addr; |
1306 | unsigned long bit_offset; | 1296 | unsigned long bit_offset; |
1307 | unsigned i; | 1297 | unsigned i; |
1308 | 1298 | ||
1309 | 1299 | ||
1310 | if (bm_fo > b->bm_bits) { | 1300 | if (bm_fo > b->bm_bits) { |
1311 | dev_err(DEV, "bm_fo=%lu bm_bits=%lu\n", bm_fo, b->bm_bits); | 1301 | drbd_err(device, "bm_fo=%lu bm_bits=%lu\n", bm_fo, b->bm_bits); |
1312 | bm_fo = DRBD_END_OF_BITMAP; | 1302 | bm_fo = DRBD_END_OF_BITMAP; |
1313 | } else { | 1303 | } else { |
1314 | while (bm_fo < b->bm_bits) { | 1304 | while (bm_fo < b->bm_bits) { |
@@ -1338,10 +1328,10 @@ static unsigned long __bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo, | |||
1338 | return bm_fo; | 1328 | return bm_fo; |
1339 | } | 1329 | } |
1340 | 1330 | ||
1341 | static unsigned long bm_find_next(struct drbd_conf *mdev, | 1331 | static unsigned long bm_find_next(struct drbd_device *device, |
1342 | unsigned long bm_fo, const int find_zero_bit) | 1332 | unsigned long bm_fo, const int find_zero_bit) |
1343 | { | 1333 | { |
1344 | struct drbd_bitmap *b = mdev->bitmap; | 1334 | struct drbd_bitmap *b = device->bitmap; |
1345 | unsigned long i = DRBD_END_OF_BITMAP; | 1335 | unsigned long i = DRBD_END_OF_BITMAP; |
1346 | 1336 | ||
1347 | if (!expect(b)) | 1337 | if (!expect(b)) |
@@ -1351,39 +1341,39 @@ static unsigned long bm_find_next(struct drbd_conf *mdev, | |||
1351 | 1341 | ||
1352 | spin_lock_irq(&b->bm_lock); | 1342 | spin_lock_irq(&b->bm_lock); |
1353 | if (BM_DONT_TEST & b->bm_flags) | 1343 | if (BM_DONT_TEST & b->bm_flags) |
1354 | bm_print_lock_info(mdev); | 1344 | bm_print_lock_info(device); |
1355 | 1345 | ||
1356 | i = __bm_find_next(mdev, bm_fo, find_zero_bit); | 1346 | i = __bm_find_next(device, bm_fo, find_zero_bit); |
1357 | 1347 | ||
1358 | spin_unlock_irq(&b->bm_lock); | 1348 | spin_unlock_irq(&b->bm_lock); |
1359 | return i; | 1349 | return i; |
1360 | } | 1350 | } |
1361 | 1351 | ||
1362 | unsigned long drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo) | 1352 | unsigned long drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo) |
1363 | { | 1353 | { |
1364 | return bm_find_next(mdev, bm_fo, 0); | 1354 | return bm_find_next(device, bm_fo, 0); |
1365 | } | 1355 | } |
1366 | 1356 | ||
1367 | #if 0 | 1357 | #if 0 |
1368 | /* not yet needed for anything. */ | 1358 | /* not yet needed for anything. */ |
1369 | unsigned long drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_fo) | 1359 | unsigned long drbd_bm_find_next_zero(struct drbd_device *device, unsigned long bm_fo) |
1370 | { | 1360 | { |
1371 | return bm_find_next(mdev, bm_fo, 1); | 1361 | return bm_find_next(device, bm_fo, 1); |
1372 | } | 1362 | } |
1373 | #endif | 1363 | #endif |
1374 | 1364 | ||
1375 | /* does not spin_lock_irqsave. | 1365 | /* does not spin_lock_irqsave. |
1376 | * you must take drbd_bm_lock() first */ | 1366 | * you must take drbd_bm_lock() first */ |
1377 | unsigned long _drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo) | 1367 | unsigned long _drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo) |
1378 | { | 1368 | { |
1379 | /* WARN_ON(!(BM_DONT_SET & mdev->b->bm_flags)); */ | 1369 | /* WARN_ON(!(BM_DONT_SET & device->b->bm_flags)); */ |
1380 | return __bm_find_next(mdev, bm_fo, 0); | 1370 | return __bm_find_next(device, bm_fo, 0); |
1381 | } | 1371 | } |
1382 | 1372 | ||
1383 | unsigned long _drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_fo) | 1373 | unsigned long _drbd_bm_find_next_zero(struct drbd_device *device, unsigned long bm_fo) |
1384 | { | 1374 | { |
1385 | /* WARN_ON(!(BM_DONT_SET & mdev->b->bm_flags)); */ | 1375 | /* WARN_ON(!(BM_DONT_SET & device->b->bm_flags)); */ |
1386 | return __bm_find_next(mdev, bm_fo, 1); | 1376 | return __bm_find_next(device, bm_fo, 1); |
1387 | } | 1377 | } |
1388 | 1378 | ||
1389 | /* returns number of bits actually changed. | 1379 | /* returns number of bits actually changed. |
@@ -1392,10 +1382,10 @@ unsigned long _drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_f | |||
1392 | * wants bitnr, not sector. | 1382 | * wants bitnr, not sector. |
1393 | * expected to be called for only a few bits (e - s about BITS_PER_LONG). | 1383 | * expected to be called for only a few bits (e - s about BITS_PER_LONG). |
1394 | * Must hold bitmap lock already. */ | 1384 | * Must hold bitmap lock already. */ |
1395 | static int __bm_change_bits_to(struct drbd_conf *mdev, const unsigned long s, | 1385 | static int __bm_change_bits_to(struct drbd_device *device, const unsigned long s, |
1396 | unsigned long e, int val) | 1386 | unsigned long e, int val) |
1397 | { | 1387 | { |
1398 | struct drbd_bitmap *b = mdev->bitmap; | 1388 | struct drbd_bitmap *b = device->bitmap; |
1399 | unsigned long *p_addr = NULL; | 1389 | unsigned long *p_addr = NULL; |
1400 | unsigned long bitnr; | 1390 | unsigned long bitnr; |
1401 | unsigned int last_page_nr = -1U; | 1391 | unsigned int last_page_nr = -1U; |
@@ -1403,7 +1393,7 @@ static int __bm_change_bits_to(struct drbd_conf *mdev, const unsigned long s, | |||
1403 | int changed_total = 0; | 1393 | int changed_total = 0; |
1404 | 1394 | ||
1405 | if (e >= b->bm_bits) { | 1395 | if (e >= b->bm_bits) { |
1406 | dev_err(DEV, "ASSERT FAILED: bit_s=%lu bit_e=%lu bm_bits=%lu\n", | 1396 | drbd_err(device, "ASSERT FAILED: bit_s=%lu bit_e=%lu bm_bits=%lu\n", |
1407 | s, e, b->bm_bits); | 1397 | s, e, b->bm_bits); |
1408 | e = b->bm_bits ? b->bm_bits -1 : 0; | 1398 | e = b->bm_bits ? b->bm_bits -1 : 0; |
1409 | } | 1399 | } |
@@ -1441,11 +1431,11 @@ static int __bm_change_bits_to(struct drbd_conf *mdev, const unsigned long s, | |||
1441 | * for val != 0, we change 0 -> 1, return code positive | 1431 | * for val != 0, we change 0 -> 1, return code positive |
1442 | * for val == 0, we change 1 -> 0, return code negative | 1432 | * for val == 0, we change 1 -> 0, return code negative |
1443 | * wants bitnr, not sector */ | 1433 | * wants bitnr, not sector */ |
1444 | static int bm_change_bits_to(struct drbd_conf *mdev, const unsigned long s, | 1434 | static int bm_change_bits_to(struct drbd_device *device, const unsigned long s, |
1445 | const unsigned long e, int val) | 1435 | const unsigned long e, int val) |
1446 | { | 1436 | { |
1447 | unsigned long flags; | 1437 | unsigned long flags; |
1448 | struct drbd_bitmap *b = mdev->bitmap; | 1438 | struct drbd_bitmap *b = device->bitmap; |
1449 | int c = 0; | 1439 | int c = 0; |
1450 | 1440 | ||
1451 | if (!expect(b)) | 1441 | if (!expect(b)) |
@@ -1455,24 +1445,24 @@ static int bm_change_bits_to(struct drbd_conf *mdev, const unsigned long s, | |||
1455 | 1445 | ||
1456 | spin_lock_irqsave(&b->bm_lock, flags); | 1446 | spin_lock_irqsave(&b->bm_lock, flags); |
1457 | if ((val ? BM_DONT_SET : BM_DONT_CLEAR) & b->bm_flags) | 1447 | if ((val ? BM_DONT_SET : BM_DONT_CLEAR) & b->bm_flags) |
1458 | bm_print_lock_info(mdev); | 1448 | bm_print_lock_info(device); |
1459 | 1449 | ||
1460 | c = __bm_change_bits_to(mdev, s, e, val); | 1450 | c = __bm_change_bits_to(device, s, e, val); |
1461 | 1451 | ||
1462 | spin_unlock_irqrestore(&b->bm_lock, flags); | 1452 | spin_unlock_irqrestore(&b->bm_lock, flags); |
1463 | return c; | 1453 | return c; |
1464 | } | 1454 | } |
1465 | 1455 | ||
1466 | /* returns number of bits changed 0 -> 1 */ | 1456 | /* returns number of bits changed 0 -> 1 */ |
1467 | int drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsigned long e) | 1457 | int drbd_bm_set_bits(struct drbd_device *device, const unsigned long s, const unsigned long e) |
1468 | { | 1458 | { |
1469 | return bm_change_bits_to(mdev, s, e, 1); | 1459 | return bm_change_bits_to(device, s, e, 1); |
1470 | } | 1460 | } |
1471 | 1461 | ||
1472 | /* returns number of bits changed 1 -> 0 */ | 1462 | /* returns number of bits changed 1 -> 0 */ |
1473 | int drbd_bm_clear_bits(struct drbd_conf *mdev, const unsigned long s, const unsigned long e) | 1463 | int drbd_bm_clear_bits(struct drbd_device *device, const unsigned long s, const unsigned long e) |
1474 | { | 1464 | { |
1475 | return -bm_change_bits_to(mdev, s, e, 0); | 1465 | return -bm_change_bits_to(device, s, e, 0); |
1476 | } | 1466 | } |
1477 | 1467 | ||
1478 | /* sets all bits in full words, | 1468 | /* sets all bits in full words, |
@@ -1504,7 +1494,7 @@ static inline void bm_set_full_words_within_one_page(struct drbd_bitmap *b, | |||
1504 | * You must first drbd_bm_lock(). | 1494 | * You must first drbd_bm_lock(). |
1505 | * Can be called to set the whole bitmap in one go. | 1495 | * Can be called to set the whole bitmap in one go. |
1506 | * Sets bits from s to e _inclusive_. */ | 1496 | * Sets bits from s to e _inclusive_. */ |
1507 | void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsigned long e) | 1497 | void _drbd_bm_set_bits(struct drbd_device *device, const unsigned long s, const unsigned long e) |
1508 | { | 1498 | { |
1509 | /* First set_bit from the first bit (s) | 1499 | /* First set_bit from the first bit (s) |
1510 | * up to the next long boundary (sl), | 1500 | * up to the next long boundary (sl), |
@@ -1514,7 +1504,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1514 | * Do not use memset, because we must account for changes, | 1504 | * Do not use memset, because we must account for changes, |
1515 | * so we need to loop over the words with hweight() anyways. | 1505 | * so we need to loop over the words with hweight() anyways. |
1516 | */ | 1506 | */ |
1517 | struct drbd_bitmap *b = mdev->bitmap; | 1507 | struct drbd_bitmap *b = device->bitmap; |
1518 | unsigned long sl = ALIGN(s,BITS_PER_LONG); | 1508 | unsigned long sl = ALIGN(s,BITS_PER_LONG); |
1519 | unsigned long el = (e+1) & ~((unsigned long)BITS_PER_LONG-1); | 1509 | unsigned long el = (e+1) & ~((unsigned long)BITS_PER_LONG-1); |
1520 | int first_page; | 1510 | int first_page; |
@@ -1526,7 +1516,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1526 | if (e - s <= 3*BITS_PER_LONG) { | 1516 | if (e - s <= 3*BITS_PER_LONG) { |
1527 | /* don't bother; el and sl may even be wrong. */ | 1517 | /* don't bother; el and sl may even be wrong. */ |
1528 | spin_lock_irq(&b->bm_lock); | 1518 | spin_lock_irq(&b->bm_lock); |
1529 | __bm_change_bits_to(mdev, s, e, 1); | 1519 | __bm_change_bits_to(device, s, e, 1); |
1530 | spin_unlock_irq(&b->bm_lock); | 1520 | spin_unlock_irq(&b->bm_lock); |
1531 | return; | 1521 | return; |
1532 | } | 1522 | } |
@@ -1537,7 +1527,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1537 | 1527 | ||
1538 | /* bits filling the current long */ | 1528 | /* bits filling the current long */ |
1539 | if (sl) | 1529 | if (sl) |
1540 | __bm_change_bits_to(mdev, s, sl-1, 1); | 1530 | __bm_change_bits_to(device, s, sl-1, 1); |
1541 | 1531 | ||
1542 | first_page = sl >> (3 + PAGE_SHIFT); | 1532 | first_page = sl >> (3 + PAGE_SHIFT); |
1543 | last_page = el >> (3 + PAGE_SHIFT); | 1533 | last_page = el >> (3 + PAGE_SHIFT); |
@@ -1549,7 +1539,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1549 | 1539 | ||
1550 | /* first and full pages, unless first page == last page */ | 1540 | /* first and full pages, unless first page == last page */ |
1551 | for (page_nr = first_page; page_nr < last_page; page_nr++) { | 1541 | for (page_nr = first_page; page_nr < last_page; page_nr++) { |
1552 | bm_set_full_words_within_one_page(mdev->bitmap, page_nr, first_word, last_word); | 1542 | bm_set_full_words_within_one_page(device->bitmap, page_nr, first_word, last_word); |
1553 | spin_unlock_irq(&b->bm_lock); | 1543 | spin_unlock_irq(&b->bm_lock); |
1554 | cond_resched(); | 1544 | cond_resched(); |
1555 | first_word = 0; | 1545 | first_word = 0; |
@@ -1565,7 +1555,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1565 | * as we did not allocate it, it is not present in bitmap->bm_pages. | 1555 | * as we did not allocate it, it is not present in bitmap->bm_pages. |
1566 | */ | 1556 | */ |
1567 | if (last_word) | 1557 | if (last_word) |
1568 | bm_set_full_words_within_one_page(mdev->bitmap, last_page, first_word, last_word); | 1558 | bm_set_full_words_within_one_page(device->bitmap, last_page, first_word, last_word); |
1569 | 1559 | ||
1570 | /* possibly trailing bits. | 1560 | /* possibly trailing bits. |
1571 | * example: (e & 63) == 63, el will be e+1. | 1561 | * example: (e & 63) == 63, el will be e+1. |
@@ -1573,7 +1563,7 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1573 | * it would trigger an assert in __bm_change_bits_to() | 1563 | * it would trigger an assert in __bm_change_bits_to() |
1574 | */ | 1564 | */ |
1575 | if (el <= e) | 1565 | if (el <= e) |
1576 | __bm_change_bits_to(mdev, el, e, 1); | 1566 | __bm_change_bits_to(device, el, e, 1); |
1577 | spin_unlock_irq(&b->bm_lock); | 1567 | spin_unlock_irq(&b->bm_lock); |
1578 | } | 1568 | } |
1579 | 1569 | ||
@@ -1584,10 +1574,10 @@ void _drbd_bm_set_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1584 | * 0 ... bit not set | 1574 | * 0 ... bit not set |
1585 | * -1 ... first out of bounds access, stop testing for bits! | 1575 | * -1 ... first out of bounds access, stop testing for bits! |
1586 | */ | 1576 | */ |
1587 | int drbd_bm_test_bit(struct drbd_conf *mdev, const unsigned long bitnr) | 1577 | int drbd_bm_test_bit(struct drbd_device *device, const unsigned long bitnr) |
1588 | { | 1578 | { |
1589 | unsigned long flags; | 1579 | unsigned long flags; |
1590 | struct drbd_bitmap *b = mdev->bitmap; | 1580 | struct drbd_bitmap *b = device->bitmap; |
1591 | unsigned long *p_addr; | 1581 | unsigned long *p_addr; |
1592 | int i; | 1582 | int i; |
1593 | 1583 | ||
@@ -1598,7 +1588,7 @@ int drbd_bm_test_bit(struct drbd_conf *mdev, const unsigned long bitnr) | |||
1598 | 1588 | ||
1599 | spin_lock_irqsave(&b->bm_lock, flags); | 1589 | spin_lock_irqsave(&b->bm_lock, flags); |
1600 | if (BM_DONT_TEST & b->bm_flags) | 1590 | if (BM_DONT_TEST & b->bm_flags) |
1601 | bm_print_lock_info(mdev); | 1591 | bm_print_lock_info(device); |
1602 | if (bitnr < b->bm_bits) { | 1592 | if (bitnr < b->bm_bits) { |
1603 | p_addr = bm_map_pidx(b, bm_bit_to_page_idx(b, bitnr)); | 1593 | p_addr = bm_map_pidx(b, bm_bit_to_page_idx(b, bitnr)); |
1604 | i = test_bit_le(bitnr & BITS_PER_PAGE_MASK, p_addr) ? 1 : 0; | 1594 | i = test_bit_le(bitnr & BITS_PER_PAGE_MASK, p_addr) ? 1 : 0; |
@@ -1606,7 +1596,7 @@ int drbd_bm_test_bit(struct drbd_conf *mdev, const unsigned long bitnr) | |||
1606 | } else if (bitnr == b->bm_bits) { | 1596 | } else if (bitnr == b->bm_bits) { |
1607 | i = -1; | 1597 | i = -1; |
1608 | } else { /* (bitnr > b->bm_bits) */ | 1598 | } else { /* (bitnr > b->bm_bits) */ |
1609 | dev_err(DEV, "bitnr=%lu > bm_bits=%lu\n", bitnr, b->bm_bits); | 1599 | drbd_err(device, "bitnr=%lu > bm_bits=%lu\n", bitnr, b->bm_bits); |
1610 | i = 0; | 1600 | i = 0; |
1611 | } | 1601 | } |
1612 | 1602 | ||
@@ -1615,10 +1605,10 @@ int drbd_bm_test_bit(struct drbd_conf *mdev, const unsigned long bitnr) | |||
1615 | } | 1605 | } |
1616 | 1606 | ||
1617 | /* returns number of bits set in the range [s, e] */ | 1607 | /* returns number of bits set in the range [s, e] */ |
1618 | int drbd_bm_count_bits(struct drbd_conf *mdev, const unsigned long s, const unsigned long e) | 1608 | int drbd_bm_count_bits(struct drbd_device *device, const unsigned long s, const unsigned long e) |
1619 | { | 1609 | { |
1620 | unsigned long flags; | 1610 | unsigned long flags; |
1621 | struct drbd_bitmap *b = mdev->bitmap; | 1611 | struct drbd_bitmap *b = device->bitmap; |
1622 | unsigned long *p_addr = NULL; | 1612 | unsigned long *p_addr = NULL; |
1623 | unsigned long bitnr; | 1613 | unsigned long bitnr; |
1624 | unsigned int page_nr = -1U; | 1614 | unsigned int page_nr = -1U; |
@@ -1635,7 +1625,7 @@ int drbd_bm_count_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1635 | 1625 | ||
1636 | spin_lock_irqsave(&b->bm_lock, flags); | 1626 | spin_lock_irqsave(&b->bm_lock, flags); |
1637 | if (BM_DONT_TEST & b->bm_flags) | 1627 | if (BM_DONT_TEST & b->bm_flags) |
1638 | bm_print_lock_info(mdev); | 1628 | bm_print_lock_info(device); |
1639 | for (bitnr = s; bitnr <= e; bitnr++) { | 1629 | for (bitnr = s; bitnr <= e; bitnr++) { |
1640 | unsigned int idx = bm_bit_to_page_idx(b, bitnr); | 1630 | unsigned int idx = bm_bit_to_page_idx(b, bitnr); |
1641 | if (page_nr != idx) { | 1631 | if (page_nr != idx) { |
@@ -1647,7 +1637,7 @@ int drbd_bm_count_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1647 | if (expect(bitnr < b->bm_bits)) | 1637 | if (expect(bitnr < b->bm_bits)) |
1648 | c += (0 != test_bit_le(bitnr - (page_nr << (PAGE_SHIFT+3)), p_addr)); | 1638 | c += (0 != test_bit_le(bitnr - (page_nr << (PAGE_SHIFT+3)), p_addr)); |
1649 | else | 1639 | else |
1650 | dev_err(DEV, "bitnr=%lu bm_bits=%lu\n", bitnr, b->bm_bits); | 1640 | drbd_err(device, "bitnr=%lu bm_bits=%lu\n", bitnr, b->bm_bits); |
1651 | } | 1641 | } |
1652 | if (p_addr) | 1642 | if (p_addr) |
1653 | bm_unmap(p_addr); | 1643 | bm_unmap(p_addr); |
@@ -1670,9 +1660,9 @@ int drbd_bm_count_bits(struct drbd_conf *mdev, const unsigned long s, const unsi | |||
1670 | * reference count of some bitmap extent element from some lru instead... | 1660 | * reference count of some bitmap extent element from some lru instead... |
1671 | * | 1661 | * |
1672 | */ | 1662 | */ |
1673 | int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr) | 1663 | int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr) |
1674 | { | 1664 | { |
1675 | struct drbd_bitmap *b = mdev->bitmap; | 1665 | struct drbd_bitmap *b = device->bitmap; |
1676 | int count, s, e; | 1666 | int count, s, e; |
1677 | unsigned long flags; | 1667 | unsigned long flags; |
1678 | unsigned long *p_addr, *bm; | 1668 | unsigned long *p_addr, *bm; |
@@ -1684,7 +1674,7 @@ int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr) | |||
1684 | 1674 | ||
1685 | spin_lock_irqsave(&b->bm_lock, flags); | 1675 | spin_lock_irqsave(&b->bm_lock, flags); |
1686 | if (BM_DONT_TEST & b->bm_flags) | 1676 | if (BM_DONT_TEST & b->bm_flags) |
1687 | bm_print_lock_info(mdev); | 1677 | bm_print_lock_info(device); |
1688 | 1678 | ||
1689 | s = S2W(enr); | 1679 | s = S2W(enr); |
1690 | e = min((size_t)S2W(enr+1), b->bm_words); | 1680 | e = min((size_t)S2W(enr+1), b->bm_words); |
@@ -1697,7 +1687,7 @@ int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr) | |||
1697 | count += hweight_long(*bm++); | 1687 | count += hweight_long(*bm++); |
1698 | bm_unmap(p_addr); | 1688 | bm_unmap(p_addr); |
1699 | } else { | 1689 | } else { |
1700 | dev_err(DEV, "start offset (%d) too large in drbd_bm_e_weight\n", s); | 1690 | drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s); |
1701 | } | 1691 | } |
1702 | spin_unlock_irqrestore(&b->bm_lock, flags); | 1692 | spin_unlock_irqrestore(&b->bm_lock, flags); |
1703 | return count; | 1693 | return count; |
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index 0e06f0c5dd1e..e7093d4291f1 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h | |||
@@ -45,7 +45,9 @@ | |||
45 | #include <linux/prefetch.h> | 45 | #include <linux/prefetch.h> |
46 | #include <linux/drbd_genl_api.h> | 46 | #include <linux/drbd_genl_api.h> |
47 | #include <linux/drbd.h> | 47 | #include <linux/drbd.h> |
48 | #include "drbd_strings.h" | ||
48 | #include "drbd_state.h" | 49 | #include "drbd_state.h" |
50 | #include "drbd_protocol.h" | ||
49 | 51 | ||
50 | #ifdef __CHECKER__ | 52 | #ifdef __CHECKER__ |
51 | # define __protected_by(x) __attribute__((require_context(x,1,999,"rdwr"))) | 53 | # define __protected_by(x) __attribute__((require_context(x,1,999,"rdwr"))) |
@@ -65,6 +67,7 @@ | |||
65 | extern unsigned int minor_count; | 67 | extern unsigned int minor_count; |
66 | extern bool disable_sendpage; | 68 | extern bool disable_sendpage; |
67 | extern bool allow_oos; | 69 | extern bool allow_oos; |
70 | void tl_abort_disk_io(struct drbd_device *device); | ||
68 | 71 | ||
69 | #ifdef CONFIG_DRBD_FAULT_INJECTION | 72 | #ifdef CONFIG_DRBD_FAULT_INJECTION |
70 | extern int enable_faults; | 73 | extern int enable_faults; |
@@ -95,25 +98,60 @@ extern char usermode_helper[]; | |||
95 | 98 | ||
96 | #define UUID_NEW_BM_OFFSET ((u64)0x0001000000000000ULL) | 99 | #define UUID_NEW_BM_OFFSET ((u64)0x0001000000000000ULL) |
97 | 100 | ||
98 | struct drbd_conf; | 101 | struct drbd_device; |
99 | struct drbd_tconn; | 102 | struct drbd_connection; |
100 | 103 | ||
101 | 104 | #define __drbd_printk_device(level, device, fmt, args...) \ | |
102 | /* to shorten dev_warn(DEV, "msg"); and relatives statements */ | 105 | dev_printk(level, disk_to_dev((device)->vdisk), fmt, ## args) |
103 | #define DEV (disk_to_dev(mdev->vdisk)) | 106 | #define __drbd_printk_peer_device(level, peer_device, fmt, args...) \ |
104 | 107 | dev_printk(level, disk_to_dev((peer_device)->device->vdisk), fmt, ## args) | |
105 | #define conn_printk(LEVEL, TCONN, FMT, ARGS...) \ | 108 | #define __drbd_printk_resource(level, resource, fmt, args...) \ |
106 | printk(LEVEL "d-con %s: " FMT, TCONN->name , ## ARGS) | 109 | printk(level "drbd %s: " fmt, (resource)->name, ## args) |
107 | #define conn_alert(TCONN, FMT, ARGS...) conn_printk(KERN_ALERT, TCONN, FMT, ## ARGS) | 110 | #define __drbd_printk_connection(level, connection, fmt, args...) \ |
108 | #define conn_crit(TCONN, FMT, ARGS...) conn_printk(KERN_CRIT, TCONN, FMT, ## ARGS) | 111 | printk(level "drbd %s: " fmt, (connection)->resource->name, ## args) |
109 | #define conn_err(TCONN, FMT, ARGS...) conn_printk(KERN_ERR, TCONN, FMT, ## ARGS) | 112 | |
110 | #define conn_warn(TCONN, FMT, ARGS...) conn_printk(KERN_WARNING, TCONN, FMT, ## ARGS) | 113 | void drbd_printk_with_wrong_object_type(void); |
111 | #define conn_notice(TCONN, FMT, ARGS...) conn_printk(KERN_NOTICE, TCONN, FMT, ## ARGS) | 114 | |
112 | #define conn_info(TCONN, FMT, ARGS...) conn_printk(KERN_INFO, TCONN, FMT, ## ARGS) | 115 | #define __drbd_printk_if_same_type(obj, type, func, level, fmt, args...) \ |
113 | #define conn_dbg(TCONN, FMT, ARGS...) conn_printk(KERN_DEBUG, TCONN, FMT, ## ARGS) | 116 | (__builtin_types_compatible_p(typeof(obj), type) || \ |
114 | 117 | __builtin_types_compatible_p(typeof(obj), const type)), \ | |
115 | #define D_ASSERT(exp) if (!(exp)) \ | 118 | func(level, (const type)(obj), fmt, ## args) |
116 | dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__) | 119 | |
120 | #define drbd_printk(level, obj, fmt, args...) \ | ||
121 | __builtin_choose_expr( \ | ||
122 | __drbd_printk_if_same_type(obj, struct drbd_device *, \ | ||
123 | __drbd_printk_device, level, fmt, ## args), \ | ||
124 | __builtin_choose_expr( \ | ||
125 | __drbd_printk_if_same_type(obj, struct drbd_resource *, \ | ||
126 | __drbd_printk_resource, level, fmt, ## args), \ | ||
127 | __builtin_choose_expr( \ | ||
128 | __drbd_printk_if_same_type(obj, struct drbd_connection *, \ | ||
129 | __drbd_printk_connection, level, fmt, ## args), \ | ||
130 | __builtin_choose_expr( \ | ||
131 | __drbd_printk_if_same_type(obj, struct drbd_peer_device *, \ | ||
132 | __drbd_printk_peer_device, level, fmt, ## args), \ | ||
133 | drbd_printk_with_wrong_object_type())))) | ||
134 | |||
135 | #define drbd_dbg(obj, fmt, args...) \ | ||
136 | drbd_printk(KERN_DEBUG, obj, fmt, ## args) | ||
137 | #define drbd_alert(obj, fmt, args...) \ | ||
138 | drbd_printk(KERN_ALERT, obj, fmt, ## args) | ||
139 | #define drbd_err(obj, fmt, args...) \ | ||
140 | drbd_printk(KERN_ERR, obj, fmt, ## args) | ||
141 | #define drbd_warn(obj, fmt, args...) \ | ||
142 | drbd_printk(KERN_WARNING, obj, fmt, ## args) | ||
143 | #define drbd_info(obj, fmt, args...) \ | ||
144 | drbd_printk(KERN_INFO, obj, fmt, ## args) | ||
145 | #define drbd_emerg(obj, fmt, args...) \ | ||
146 | drbd_printk(KERN_EMERG, obj, fmt, ## args) | ||
147 | |||
148 | #define dynamic_drbd_dbg(device, fmt, args...) \ | ||
149 | dynamic_dev_dbg(disk_to_dev(device->vdisk), fmt, ## args) | ||
150 | |||
151 | #define D_ASSERT(device, exp) do { \ | ||
152 | if (!(exp)) \ | ||
153 | drbd_err(device, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__); \ | ||
154 | } while (0) | ||
117 | 155 | ||
118 | /** | 156 | /** |
119 | * expect - Make an assertion | 157 | * expect - Make an assertion |
@@ -123,7 +161,7 @@ struct drbd_tconn; | |||
123 | #define expect(exp) ({ \ | 161 | #define expect(exp) ({ \ |
124 | bool _bool = (exp); \ | 162 | bool _bool = (exp); \ |
125 | if (!_bool) \ | 163 | if (!_bool) \ |
126 | dev_err(DEV, "ASSERTION %s FAILED in %s\n", \ | 164 | drbd_err(device, "ASSERTION %s FAILED in %s\n", \ |
127 | #exp, __func__); \ | 165 | #exp, __func__); \ |
128 | _bool; \ | 166 | _bool; \ |
129 | }) | 167 | }) |
@@ -145,14 +183,14 @@ enum { | |||
145 | }; | 183 | }; |
146 | 184 | ||
147 | extern unsigned int | 185 | extern unsigned int |
148 | _drbd_insert_fault(struct drbd_conf *mdev, unsigned int type); | 186 | _drbd_insert_fault(struct drbd_device *device, unsigned int type); |
149 | 187 | ||
150 | static inline int | 188 | static inline int |
151 | drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) { | 189 | drbd_insert_fault(struct drbd_device *device, unsigned int type) { |
152 | #ifdef CONFIG_DRBD_FAULT_INJECTION | 190 | #ifdef CONFIG_DRBD_FAULT_INJECTION |
153 | return fault_rate && | 191 | return fault_rate && |
154 | (enable_faults & (1<<type)) && | 192 | (enable_faults & (1<<type)) && |
155 | _drbd_insert_fault(mdev, type); | 193 | _drbd_insert_fault(device, type); |
156 | #else | 194 | #else |
157 | return 0; | 195 | return 0; |
158 | #endif | 196 | #endif |
@@ -164,74 +202,8 @@ drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) { | |||
164 | #define div_floor(A, B) ((A)/(B)) | 202 | #define div_floor(A, B) ((A)/(B)) |
165 | 203 | ||
166 | extern struct ratelimit_state drbd_ratelimit_state; | 204 | extern struct ratelimit_state drbd_ratelimit_state; |
167 | extern struct idr minors; /* RCU, updates: genl_lock() */ | 205 | extern struct idr drbd_devices; /* RCU, updates: genl_lock() */ |
168 | extern struct list_head drbd_tconns; /* RCU, updates: genl_lock() */ | 206 | extern struct list_head drbd_resources; /* RCU, updates: genl_lock() */ |
169 | |||
170 | /* on the wire */ | ||
171 | enum drbd_packet { | ||
172 | /* receiver (data socket) */ | ||
173 | P_DATA = 0x00, | ||
174 | P_DATA_REPLY = 0x01, /* Response to P_DATA_REQUEST */ | ||
175 | P_RS_DATA_REPLY = 0x02, /* Response to P_RS_DATA_REQUEST */ | ||
176 | P_BARRIER = 0x03, | ||
177 | P_BITMAP = 0x04, | ||
178 | P_BECOME_SYNC_TARGET = 0x05, | ||
179 | P_BECOME_SYNC_SOURCE = 0x06, | ||
180 | P_UNPLUG_REMOTE = 0x07, /* Used at various times to hint the peer */ | ||
181 | P_DATA_REQUEST = 0x08, /* Used to ask for a data block */ | ||
182 | P_RS_DATA_REQUEST = 0x09, /* Used to ask for a data block for resync */ | ||
183 | P_SYNC_PARAM = 0x0a, | ||
184 | P_PROTOCOL = 0x0b, | ||
185 | P_UUIDS = 0x0c, | ||
186 | P_SIZES = 0x0d, | ||
187 | P_STATE = 0x0e, | ||
188 | P_SYNC_UUID = 0x0f, | ||
189 | P_AUTH_CHALLENGE = 0x10, | ||
190 | P_AUTH_RESPONSE = 0x11, | ||
191 | P_STATE_CHG_REQ = 0x12, | ||
192 | |||
193 | /* asender (meta socket */ | ||
194 | P_PING = 0x13, | ||
195 | P_PING_ACK = 0x14, | ||
196 | P_RECV_ACK = 0x15, /* Used in protocol B */ | ||
197 | P_WRITE_ACK = 0x16, /* Used in protocol C */ | ||
198 | P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */ | ||
199 | P_SUPERSEDED = 0x18, /* Used in proto C, two-primaries conflict detection */ | ||
200 | P_NEG_ACK = 0x19, /* Sent if local disk is unusable */ | ||
201 | P_NEG_DREPLY = 0x1a, /* Local disk is broken... */ | ||
202 | P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */ | ||
203 | P_BARRIER_ACK = 0x1c, | ||
204 | P_STATE_CHG_REPLY = 0x1d, | ||
205 | |||
206 | /* "new" commands, no longer fitting into the ordering scheme above */ | ||
207 | |||
208 | P_OV_REQUEST = 0x1e, /* data socket */ | ||
209 | P_OV_REPLY = 0x1f, | ||
210 | P_OV_RESULT = 0x20, /* meta socket */ | ||
211 | P_CSUM_RS_REQUEST = 0x21, /* data socket */ | ||
212 | P_RS_IS_IN_SYNC = 0x22, /* meta socket */ | ||
213 | P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */ | ||
214 | P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */ | ||
215 | /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */ | ||
216 | /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */ | ||
217 | P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */ | ||
218 | P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */ | ||
219 | P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */ | ||
220 | P_CONN_ST_CHG_REQ = 0x2a, /* data sock: Connection wide state request */ | ||
221 | P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */ | ||
222 | P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */ | ||
223 | P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */ | ||
224 | |||
225 | P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */ | ||
226 | P_MAX_OPT_CMD = 0x101, | ||
227 | |||
228 | /* special command ids for handshake */ | ||
229 | |||
230 | P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */ | ||
231 | P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */ | ||
232 | |||
233 | P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */ | ||
234 | }; | ||
235 | 207 | ||
236 | extern const char *cmdname(enum drbd_packet cmd); | 208 | extern const char *cmdname(enum drbd_packet cmd); |
237 | 209 | ||
@@ -253,7 +225,7 @@ struct bm_xfer_ctx { | |||
253 | unsigned bytes[2]; | 225 | unsigned bytes[2]; |
254 | }; | 226 | }; |
255 | 227 | ||
256 | extern void INFO_bm_xfer_stats(struct drbd_conf *mdev, | 228 | extern void INFO_bm_xfer_stats(struct drbd_device *device, |
257 | const char *direction, struct bm_xfer_ctx *c); | 229 | const char *direction, struct bm_xfer_ctx *c); |
258 | 230 | ||
259 | static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c) | 231 | static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c) |
@@ -275,233 +247,7 @@ static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c) | |||
275 | #endif | 247 | #endif |
276 | } | 248 | } |
277 | 249 | ||
278 | #ifndef __packed | 250 | extern unsigned int drbd_header_size(struct drbd_connection *connection); |
279 | #define __packed __attribute__((packed)) | ||
280 | #endif | ||
281 | |||
282 | /* This is the layout for a packet on the wire. | ||
283 | * The byteorder is the network byte order. | ||
284 | * (except block_id and barrier fields. | ||
285 | * these are pointers to local structs | ||
286 | * and have no relevance for the partner, | ||
287 | * which just echoes them as received.) | ||
288 | * | ||
289 | * NOTE that the payload starts at a long aligned offset, | ||
290 | * regardless of 32 or 64 bit arch! | ||
291 | */ | ||
292 | struct p_header80 { | ||
293 | u32 magic; | ||
294 | u16 command; | ||
295 | u16 length; /* bytes of data after this header */ | ||
296 | } __packed; | ||
297 | |||
298 | /* Header for big packets, Used for data packets exceeding 64kB */ | ||
299 | struct p_header95 { | ||
300 | u16 magic; /* use DRBD_MAGIC_BIG here */ | ||
301 | u16 command; | ||
302 | u32 length; | ||
303 | } __packed; | ||
304 | |||
305 | struct p_header100 { | ||
306 | u32 magic; | ||
307 | u16 volume; | ||
308 | u16 command; | ||
309 | u32 length; | ||
310 | u32 pad; | ||
311 | } __packed; | ||
312 | |||
313 | extern unsigned int drbd_header_size(struct drbd_tconn *tconn); | ||
314 | |||
315 | /* these defines must not be changed without changing the protocol version */ | ||
316 | #define DP_HARDBARRIER 1 /* depricated */ | ||
317 | #define DP_RW_SYNC 2 /* equals REQ_SYNC */ | ||
318 | #define DP_MAY_SET_IN_SYNC 4 | ||
319 | #define DP_UNPLUG 8 /* not used anymore */ | ||
320 | #define DP_FUA 16 /* equals REQ_FUA */ | ||
321 | #define DP_FLUSH 32 /* equals REQ_FLUSH */ | ||
322 | #define DP_DISCARD 64 /* equals REQ_DISCARD */ | ||
323 | #define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */ | ||
324 | #define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */ | ||
325 | |||
326 | struct p_data { | ||
327 | u64 sector; /* 64 bits sector number */ | ||
328 | u64 block_id; /* to identify the request in protocol B&C */ | ||
329 | u32 seq_num; | ||
330 | u32 dp_flags; | ||
331 | } __packed; | ||
332 | |||
333 | /* | ||
334 | * commands which share a struct: | ||
335 | * p_block_ack: | ||
336 | * P_RECV_ACK (proto B), P_WRITE_ACK (proto C), | ||
337 | * P_SUPERSEDED (proto C, two-primaries conflict detection) | ||
338 | * p_block_req: | ||
339 | * P_DATA_REQUEST, P_RS_DATA_REQUEST | ||
340 | */ | ||
341 | struct p_block_ack { | ||
342 | u64 sector; | ||
343 | u64 block_id; | ||
344 | u32 blksize; | ||
345 | u32 seq_num; | ||
346 | } __packed; | ||
347 | |||
348 | struct p_block_req { | ||
349 | u64 sector; | ||
350 | u64 block_id; | ||
351 | u32 blksize; | ||
352 | u32 pad; /* to multiple of 8 Byte */ | ||
353 | } __packed; | ||
354 | |||
355 | /* | ||
356 | * commands with their own struct for additional fields: | ||
357 | * P_CONNECTION_FEATURES | ||
358 | * P_BARRIER | ||
359 | * P_BARRIER_ACK | ||
360 | * P_SYNC_PARAM | ||
361 | * ReportParams | ||
362 | */ | ||
363 | |||
364 | struct p_connection_features { | ||
365 | u32 protocol_min; | ||
366 | u32 feature_flags; | ||
367 | u32 protocol_max; | ||
368 | |||
369 | /* should be more than enough for future enhancements | ||
370 | * for now, feature_flags and the reserved array shall be zero. | ||
371 | */ | ||
372 | |||
373 | u32 _pad; | ||
374 | u64 reserved[7]; | ||
375 | } __packed; | ||
376 | |||
377 | struct p_barrier { | ||
378 | u32 barrier; /* barrier number _handle_ only */ | ||
379 | u32 pad; /* to multiple of 8 Byte */ | ||
380 | } __packed; | ||
381 | |||
382 | struct p_barrier_ack { | ||
383 | u32 barrier; | ||
384 | u32 set_size; | ||
385 | } __packed; | ||
386 | |||
387 | struct p_rs_param { | ||
388 | u32 resync_rate; | ||
389 | |||
390 | /* Since protocol version 88 and higher. */ | ||
391 | char verify_alg[0]; | ||
392 | } __packed; | ||
393 | |||
394 | struct p_rs_param_89 { | ||
395 | u32 resync_rate; | ||
396 | /* protocol version 89: */ | ||
397 | char verify_alg[SHARED_SECRET_MAX]; | ||
398 | char csums_alg[SHARED_SECRET_MAX]; | ||
399 | } __packed; | ||
400 | |||
401 | struct p_rs_param_95 { | ||
402 | u32 resync_rate; | ||
403 | char verify_alg[SHARED_SECRET_MAX]; | ||
404 | char csums_alg[SHARED_SECRET_MAX]; | ||
405 | u32 c_plan_ahead; | ||
406 | u32 c_delay_target; | ||
407 | u32 c_fill_target; | ||
408 | u32 c_max_rate; | ||
409 | } __packed; | ||
410 | |||
411 | enum drbd_conn_flags { | ||
412 | CF_DISCARD_MY_DATA = 1, | ||
413 | CF_DRY_RUN = 2, | ||
414 | }; | ||
415 | |||
416 | struct p_protocol { | ||
417 | u32 protocol; | ||
418 | u32 after_sb_0p; | ||
419 | u32 after_sb_1p; | ||
420 | u32 after_sb_2p; | ||
421 | u32 conn_flags; | ||
422 | u32 two_primaries; | ||
423 | |||
424 | /* Since protocol version 87 and higher. */ | ||
425 | char integrity_alg[0]; | ||
426 | |||
427 | } __packed; | ||
428 | |||
429 | struct p_uuids { | ||
430 | u64 uuid[UI_EXTENDED_SIZE]; | ||
431 | } __packed; | ||
432 | |||
433 | struct p_rs_uuid { | ||
434 | u64 uuid; | ||
435 | } __packed; | ||
436 | |||
437 | struct p_sizes { | ||
438 | u64 d_size; /* size of disk */ | ||
439 | u64 u_size; /* user requested size */ | ||
440 | u64 c_size; /* current exported size */ | ||
441 | u32 max_bio_size; /* Maximal size of a BIO */ | ||
442 | u16 queue_order_type; /* not yet implemented in DRBD*/ | ||
443 | u16 dds_flags; /* use enum dds_flags here. */ | ||
444 | } __packed; | ||
445 | |||
446 | struct p_state { | ||
447 | u32 state; | ||
448 | } __packed; | ||
449 | |||
450 | struct p_req_state { | ||
451 | u32 mask; | ||
452 | u32 val; | ||
453 | } __packed; | ||
454 | |||
455 | struct p_req_state_reply { | ||
456 | u32 retcode; | ||
457 | } __packed; | ||
458 | |||
459 | struct p_drbd06_param { | ||
460 | u64 size; | ||
461 | u32 state; | ||
462 | u32 blksize; | ||
463 | u32 protocol; | ||
464 | u32 version; | ||
465 | u32 gen_cnt[5]; | ||
466 | u32 bit_map_gen[5]; | ||
467 | } __packed; | ||
468 | |||
469 | struct p_block_desc { | ||
470 | u64 sector; | ||
471 | u32 blksize; | ||
472 | u32 pad; /* to multiple of 8 Byte */ | ||
473 | } __packed; | ||
474 | |||
475 | /* Valid values for the encoding field. | ||
476 | * Bump proto version when changing this. */ | ||
477 | enum drbd_bitmap_code { | ||
478 | /* RLE_VLI_Bytes = 0, | ||
479 | * and other bit variants had been defined during | ||
480 | * algorithm evaluation. */ | ||
481 | RLE_VLI_Bits = 2, | ||
482 | }; | ||
483 | |||
484 | struct p_compressed_bm { | ||
485 | /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code | ||
486 | * (encoding & 0x80): polarity (set/unset) of first runlength | ||
487 | * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits | ||
488 | * used to pad up to head.length bytes | ||
489 | */ | ||
490 | u8 encoding; | ||
491 | |||
492 | u8 code[0]; | ||
493 | } __packed; | ||
494 | |||
495 | struct p_delay_probe93 { | ||
496 | u32 seq_num; /* sequence number to match the two probe packets */ | ||
497 | u32 offset; /* usecs the probe got sent after the reference time point */ | ||
498 | } __packed; | ||
499 | |||
500 | /* | ||
501 | * Bitmap packets need to fit within a single page on the sender and receiver, | ||
502 | * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger). | ||
503 | */ | ||
504 | #define DRBD_SOCKET_BUFFER_SIZE 4096 | ||
505 | 251 | ||
506 | /**********************************************************************/ | 252 | /**********************************************************************/ |
507 | enum drbd_thread_state { | 253 | enum drbd_thread_state { |
@@ -517,9 +263,10 @@ struct drbd_thread { | |||
517 | struct completion stop; | 263 | struct completion stop; |
518 | enum drbd_thread_state t_state; | 264 | enum drbd_thread_state t_state; |
519 | int (*function) (struct drbd_thread *); | 265 | int (*function) (struct drbd_thread *); |
520 | struct drbd_tconn *tconn; | 266 | struct drbd_resource *resource; |
267 | struct drbd_connection *connection; | ||
521 | int reset_cpu_mask; | 268 | int reset_cpu_mask; |
522 | char name[9]; | 269 | const char *name; |
523 | }; | 270 | }; |
524 | 271 | ||
525 | static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi) | 272 | static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi) |
@@ -535,18 +282,20 @@ static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi) | |||
535 | struct drbd_work { | 282 | struct drbd_work { |
536 | struct list_head list; | 283 | struct list_head list; |
537 | int (*cb)(struct drbd_work *, int cancel); | 284 | int (*cb)(struct drbd_work *, int cancel); |
538 | union { | 285 | }; |
539 | struct drbd_conf *mdev; | 286 | |
540 | struct drbd_tconn *tconn; | 287 | struct drbd_device_work { |
541 | }; | 288 | struct drbd_work w; |
289 | struct drbd_device *device; | ||
542 | }; | 290 | }; |
543 | 291 | ||
544 | #include "drbd_interval.h" | 292 | #include "drbd_interval.h" |
545 | 293 | ||
546 | extern int drbd_wait_misc(struct drbd_conf *, struct drbd_interval *); | 294 | extern int drbd_wait_misc(struct drbd_device *, struct drbd_interval *); |
547 | 295 | ||
548 | struct drbd_request { | 296 | struct drbd_request { |
549 | struct drbd_work w; | 297 | struct drbd_work w; |
298 | struct drbd_device *device; | ||
550 | 299 | ||
551 | /* if local IO is not allowed, will be NULL. | 300 | /* if local IO is not allowed, will be NULL. |
552 | * if local IO _is_ allowed, holds the locally submitted bio clone, | 301 | * if local IO _is_ allowed, holds the locally submitted bio clone, |
@@ -579,7 +328,7 @@ struct drbd_request { | |||
579 | }; | 328 | }; |
580 | 329 | ||
581 | struct drbd_epoch { | 330 | struct drbd_epoch { |
582 | struct drbd_tconn *tconn; | 331 | struct drbd_connection *connection; |
583 | struct list_head list; | 332 | struct list_head list; |
584 | unsigned int barrier_nr; | 333 | unsigned int barrier_nr; |
585 | atomic_t epoch_size; /* increased on every request added. */ | 334 | atomic_t epoch_size; /* increased on every request added. */ |
@@ -587,6 +336,10 @@ struct drbd_epoch { | |||
587 | unsigned long flags; | 336 | unsigned long flags; |
588 | }; | 337 | }; |
589 | 338 | ||
339 | /* Prototype declaration of function defined in drbd_receiver.c */ | ||
340 | int drbdd_init(struct drbd_thread *); | ||
341 | int drbd_asender(struct drbd_thread *); | ||
342 | |||
590 | /* drbd_epoch flag bits */ | 343 | /* drbd_epoch flag bits */ |
591 | enum { | 344 | enum { |
592 | DE_HAVE_BARRIER_NUMBER, | 345 | DE_HAVE_BARRIER_NUMBER, |
@@ -599,11 +352,6 @@ enum epoch_event { | |||
599 | EV_CLEANUP = 32, /* used as flag */ | 352 | EV_CLEANUP = 32, /* used as flag */ |
600 | }; | 353 | }; |
601 | 354 | ||
602 | struct drbd_wq_barrier { | ||
603 | struct drbd_work w; | ||
604 | struct completion done; | ||
605 | }; | ||
606 | |||
607 | struct digest_info { | 355 | struct digest_info { |
608 | int digest_size; | 356 | int digest_size; |
609 | void *digest; | 357 | void *digest; |
@@ -611,6 +359,7 @@ struct digest_info { | |||
611 | 359 | ||
612 | struct drbd_peer_request { | 360 | struct drbd_peer_request { |
613 | struct drbd_work w; | 361 | struct drbd_work w; |
362 | struct drbd_peer_device *peer_device; | ||
614 | struct drbd_epoch *epoch; /* for writes */ | 363 | struct drbd_epoch *epoch; /* for writes */ |
615 | struct page *pages; | 364 | struct page *pages; |
616 | atomic_t pending_bios; | 365 | atomic_t pending_bios; |
@@ -663,7 +412,7 @@ enum { | |||
663 | #define EE_SEND_WRITE_ACK (1<<__EE_SEND_WRITE_ACK) | 412 | #define EE_SEND_WRITE_ACK (1<<__EE_SEND_WRITE_ACK) |
664 | #define EE_IN_INTERVAL_TREE (1<<__EE_IN_INTERVAL_TREE) | 413 | #define EE_IN_INTERVAL_TREE (1<<__EE_IN_INTERVAL_TREE) |
665 | 414 | ||
666 | /* flag bits per mdev */ | 415 | /* flag bits per device */ |
667 | enum { | 416 | enum { |
668 | UNPLUG_REMOTE, /* sending a "UnplugRemote" could help */ | 417 | UNPLUG_REMOTE, /* sending a "UnplugRemote" could help */ |
669 | MD_DIRTY, /* current uuids and flags not yet on disk */ | 418 | MD_DIRTY, /* current uuids and flags not yet on disk */ |
@@ -695,7 +444,7 @@ enum { | |||
695 | READ_BALANCE_RR, | 444 | READ_BALANCE_RR, |
696 | }; | 445 | }; |
697 | 446 | ||
698 | struct drbd_bitmap; /* opaque for drbd_conf */ | 447 | struct drbd_bitmap; /* opaque for drbd_device */ |
699 | 448 | ||
700 | /* definition of bits in bm_flags to be used in drbd_bm_lock | 449 | /* definition of bits in bm_flags to be used in drbd_bm_lock |
701 | * and drbd_bitmap_io and friends. */ | 450 | * and drbd_bitmap_io and friends. */ |
@@ -769,7 +518,7 @@ struct drbd_backing_dev { | |||
769 | struct block_device *backing_bdev; | 518 | struct block_device *backing_bdev; |
770 | struct block_device *md_bdev; | 519 | struct block_device *md_bdev; |
771 | struct drbd_md md; | 520 | struct drbd_md md; |
772 | struct disk_conf *disk_conf; /* RCU, for updates: mdev->tconn->conf_update */ | 521 | struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */ |
773 | sector_t known_size; /* last known size of that backing device */ | 522 | sector_t known_size; /* last known size of that backing device */ |
774 | }; | 523 | }; |
775 | 524 | ||
@@ -782,8 +531,8 @@ struct bm_io_work { | |||
782 | struct drbd_work w; | 531 | struct drbd_work w; |
783 | char *why; | 532 | char *why; |
784 | enum bm_flag flags; | 533 | enum bm_flag flags; |
785 | int (*io_fn)(struct drbd_conf *mdev); | 534 | int (*io_fn)(struct drbd_device *device); |
786 | void (*done)(struct drbd_conf *mdev, int rv); | 535 | void (*done)(struct drbd_device *device, int rv); |
787 | }; | 536 | }; |
788 | 537 | ||
789 | enum write_ordering_e { | 538 | enum write_ordering_e { |
@@ -800,7 +549,7 @@ struct fifo_buffer { | |||
800 | }; | 549 | }; |
801 | extern struct fifo_buffer *fifo_alloc(int fifo_size); | 550 | extern struct fifo_buffer *fifo_alloc(int fifo_size); |
802 | 551 | ||
803 | /* flag bits per tconn */ | 552 | /* flag bits per connection */ |
804 | enum { | 553 | enum { |
805 | NET_CONGESTED, /* The data socket is congested */ | 554 | NET_CONGESTED, /* The data socket is congested */ |
806 | RESOLVE_CONFLICTS, /* Set on one node, cleared on the peer! */ | 555 | RESOLVE_CONFLICTS, /* Set on one node, cleared on the peer! */ |
@@ -822,23 +571,35 @@ enum { | |||
822 | DISCONNECT_SENT, | 571 | DISCONNECT_SENT, |
823 | }; | 572 | }; |
824 | 573 | ||
825 | struct drbd_tconn { /* is a resource from the config file */ | 574 | struct drbd_resource { |
826 | char *name; /* Resource name */ | 575 | char *name; |
827 | struct list_head all_tconn; /* linked on global drbd_tconns */ | ||
828 | struct kref kref; | 576 | struct kref kref; |
829 | struct idr volumes; /* <tconn, vnr> to mdev mapping */ | 577 | struct idr devices; /* volume number to device mapping */ |
830 | enum drbd_conns cstate; /* Only C_STANDALONE to C_WF_REPORT_PARAMS */ | 578 | struct list_head connections; |
579 | struct list_head resources; | ||
580 | struct res_opts res_opts; | ||
581 | struct mutex conf_update; /* mutex for ready-copy-update of net_conf and disk_conf */ | ||
582 | spinlock_t req_lock; | ||
583 | |||
831 | unsigned susp:1; /* IO suspended by user */ | 584 | unsigned susp:1; /* IO suspended by user */ |
832 | unsigned susp_nod:1; /* IO suspended because no data */ | 585 | unsigned susp_nod:1; /* IO suspended because no data */ |
833 | unsigned susp_fen:1; /* IO suspended because fence peer handler runs */ | 586 | unsigned susp_fen:1; /* IO suspended because fence peer handler runs */ |
587 | |||
588 | cpumask_var_t cpu_mask; | ||
589 | }; | ||
590 | |||
591 | struct drbd_connection { | ||
592 | struct list_head connections; | ||
593 | struct drbd_resource *resource; | ||
594 | struct kref kref; | ||
595 | struct idr peer_devices; /* volume number to peer device mapping */ | ||
596 | enum drbd_conns cstate; /* Only C_STANDALONE to C_WF_REPORT_PARAMS */ | ||
834 | struct mutex cstate_mutex; /* Protects graceful disconnects */ | 597 | struct mutex cstate_mutex; /* Protects graceful disconnects */ |
835 | unsigned int connect_cnt; /* Inc each time a connection is established */ | 598 | unsigned int connect_cnt; /* Inc each time a connection is established */ |
836 | 599 | ||
837 | unsigned long flags; | 600 | unsigned long flags; |
838 | struct net_conf *net_conf; /* content protected by rcu */ | 601 | struct net_conf *net_conf; /* content protected by rcu */ |
839 | struct mutex conf_update; /* mutex for ready-copy-update of net_conf and disk_conf */ | ||
840 | wait_queue_head_t ping_wait; /* Woken upon reception of a ping, and a state change */ | 602 | wait_queue_head_t ping_wait; /* Woken upon reception of a ping, and a state change */ |
841 | struct res_opts res_opts; | ||
842 | 603 | ||
843 | struct sockaddr_storage my_addr; | 604 | struct sockaddr_storage my_addr; |
844 | int my_addr_len; | 605 | int my_addr_len; |
@@ -851,12 +612,10 @@ struct drbd_tconn { /* is a resource from the config file */ | |||
851 | unsigned long last_received; /* in jiffies, either socket */ | 612 | unsigned long last_received; /* in jiffies, either socket */ |
852 | unsigned int ko_count; | 613 | unsigned int ko_count; |
853 | 614 | ||
854 | spinlock_t req_lock; | ||
855 | |||
856 | struct list_head transfer_log; /* all requests not yet fully processed */ | 615 | struct list_head transfer_log; /* all requests not yet fully processed */ |
857 | 616 | ||
858 | struct crypto_hash *cram_hmac_tfm; | 617 | struct crypto_hash *cram_hmac_tfm; |
859 | struct crypto_hash *integrity_tfm; /* checksums we compute, updates protected by tconn->data->mutex */ | 618 | struct crypto_hash *integrity_tfm; /* checksums we compute, updates protected by connection->data->mutex */ |
860 | struct crypto_hash *peer_integrity_tfm; /* checksums we verify, only accessed from receiver thread */ | 619 | struct crypto_hash *peer_integrity_tfm; /* checksums we verify, only accessed from receiver thread */ |
861 | struct crypto_hash *csums_tfm; | 620 | struct crypto_hash *csums_tfm; |
862 | struct crypto_hash *verify_tfm; | 621 | struct crypto_hash *verify_tfm; |
@@ -875,7 +634,6 @@ struct drbd_tconn { /* is a resource from the config file */ | |||
875 | struct drbd_thread receiver; | 634 | struct drbd_thread receiver; |
876 | struct drbd_thread worker; | 635 | struct drbd_thread worker; |
877 | struct drbd_thread asender; | 636 | struct drbd_thread asender; |
878 | cpumask_var_t cpu_mask; | ||
879 | 637 | ||
880 | /* sender side */ | 638 | /* sender side */ |
881 | struct drbd_work_queue sender_work; | 639 | struct drbd_work_queue sender_work; |
@@ -903,8 +661,15 @@ struct submit_worker { | |||
903 | struct list_head writes; | 661 | struct list_head writes; |
904 | }; | 662 | }; |
905 | 663 | ||
906 | struct drbd_conf { | 664 | struct drbd_peer_device { |
907 | struct drbd_tconn *tconn; | 665 | struct list_head peer_devices; |
666 | struct drbd_device *device; | ||
667 | struct drbd_connection *connection; | ||
668 | }; | ||
669 | |||
670 | struct drbd_device { | ||
671 | struct drbd_resource *resource; | ||
672 | struct list_head peer_devices; | ||
908 | int vnr; /* volume number within the connection */ | 673 | int vnr; /* volume number within the connection */ |
909 | struct kref kref; | 674 | struct kref kref; |
910 | 675 | ||
@@ -920,11 +685,11 @@ struct drbd_conf { | |||
920 | struct gendisk *vdisk; | 685 | struct gendisk *vdisk; |
921 | 686 | ||
922 | unsigned long last_reattach_jif; | 687 | unsigned long last_reattach_jif; |
923 | struct drbd_work resync_work, | 688 | struct drbd_work resync_work; |
924 | unplug_work, | 689 | struct drbd_work unplug_work; |
925 | go_diskless, | 690 | struct drbd_work go_diskless; |
926 | md_sync_work, | 691 | struct drbd_work md_sync_work; |
927 | start_resync_work; | 692 | struct drbd_work start_resync_work; |
928 | struct timer_list resync_timer; | 693 | struct timer_list resync_timer; |
929 | struct timer_list md_sync_timer; | 694 | struct timer_list md_sync_timer; |
930 | struct timer_list start_resync_timer; | 695 | struct timer_list start_resync_timer; |
@@ -1030,7 +795,7 @@ struct drbd_conf { | |||
1030 | struct bm_io_work bm_io_work; | 795 | struct bm_io_work bm_io_work; |
1031 | u64 ed_uuid; /* UUID of the exposed data */ | 796 | u64 ed_uuid; /* UUID of the exposed data */ |
1032 | struct mutex own_state_mutex; | 797 | struct mutex own_state_mutex; |
1033 | struct mutex *state_mutex; /* either own_state_mutex or mdev->tconn->cstate_mutex */ | 798 | struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */ |
1034 | char congestion_reason; /* Why we where congested... */ | 799 | char congestion_reason; /* Why we where congested... */ |
1035 | atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */ | 800 | atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */ |
1036 | atomic_t rs_sect_ev; /* for submitted resync data rate, both */ | 801 | atomic_t rs_sect_ev; /* for submitted resync data rate, both */ |
@@ -1038,7 +803,7 @@ struct drbd_conf { | |||
1038 | int rs_last_events; /* counter of read or write "events" (unit sectors) | 803 | int rs_last_events; /* counter of read or write "events" (unit sectors) |
1039 | * on the lower level device when we last looked. */ | 804 | * on the lower level device when we last looked. */ |
1040 | int c_sync_rate; /* current resync rate after syncer throttle magic */ | 805 | int c_sync_rate; /* current resync rate after syncer throttle magic */ |
1041 | struct fifo_buffer *rs_plan_s; /* correction values of resync planer (RCU, tconn->conn_update) */ | 806 | struct fifo_buffer *rs_plan_s; /* correction values of resync planer (RCU, connection->conn_update) */ |
1042 | int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */ | 807 | int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */ |
1043 | atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */ | 808 | atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */ |
1044 | unsigned int peer_max_bio_size; | 809 | unsigned int peer_max_bio_size; |
@@ -1049,19 +814,46 @@ struct drbd_conf { | |||
1049 | struct submit_worker submit; | 814 | struct submit_worker submit; |
1050 | }; | 815 | }; |
1051 | 816 | ||
1052 | static inline struct drbd_conf *minor_to_mdev(unsigned int minor) | 817 | static inline struct drbd_device *minor_to_device(unsigned int minor) |
1053 | { | 818 | { |
1054 | return (struct drbd_conf *)idr_find(&minors, minor); | 819 | return (struct drbd_device *)idr_find(&drbd_devices, minor); |
1055 | } | 820 | } |
1056 | 821 | ||
1057 | static inline unsigned int mdev_to_minor(struct drbd_conf *mdev) | 822 | static inline struct drbd_peer_device *first_peer_device(struct drbd_device *device) |
1058 | { | 823 | { |
1059 | return mdev->minor; | 824 | return list_first_entry(&device->peer_devices, struct drbd_peer_device, peer_devices); |
1060 | } | 825 | } |
1061 | 826 | ||
1062 | static inline struct drbd_conf *vnr_to_mdev(struct drbd_tconn *tconn, int vnr) | 827 | #define for_each_resource(resource, _resources) \ |
828 | list_for_each_entry(resource, _resources, resources) | ||
829 | |||
830 | #define for_each_resource_rcu(resource, _resources) \ | ||
831 | list_for_each_entry_rcu(resource, _resources, resources) | ||
832 | |||
833 | #define for_each_resource_safe(resource, tmp, _resources) \ | ||
834 | list_for_each_entry_safe(resource, tmp, _resources, resources) | ||
835 | |||
836 | #define for_each_connection(connection, resource) \ | ||
837 | list_for_each_entry(connection, &resource->connections, connections) | ||
838 | |||
839 | #define for_each_connection_rcu(connection, resource) \ | ||
840 | list_for_each_entry_rcu(connection, &resource->connections, connections) | ||
841 | |||
842 | #define for_each_connection_safe(connection, tmp, resource) \ | ||
843 | list_for_each_entry_safe(connection, tmp, &resource->connections, connections) | ||
844 | |||
845 | #define for_each_peer_device(peer_device, device) \ | ||
846 | list_for_each_entry(peer_device, &device->peer_devices, peer_devices) | ||
847 | |||
848 | #define for_each_peer_device_rcu(peer_device, device) \ | ||
849 | list_for_each_entry_rcu(peer_device, &device->peer_devices, peer_devices) | ||
850 | |||
851 | #define for_each_peer_device_safe(peer_device, tmp, device) \ | ||
852 | list_for_each_entry_safe(peer_device, tmp, &device->peer_devices, peer_devices) | ||
853 | |||
854 | static inline unsigned int device_to_minor(struct drbd_device *device) | ||
1063 | { | 855 | { |
1064 | return (struct drbd_conf *)idr_find(&tconn->volumes, vnr); | 856 | return device->minor; |
1065 | } | 857 | } |
1066 | 858 | ||
1067 | /* | 859 | /* |
@@ -1075,96 +867,93 @@ enum dds_flags { | |||
1075 | DDSF_NO_RESYNC = 2, /* Do not run a resync for the new space */ | 867 | DDSF_NO_RESYNC = 2, /* Do not run a resync for the new space */ |
1076 | }; | 868 | }; |
1077 | 869 | ||
1078 | extern void drbd_init_set_defaults(struct drbd_conf *mdev); | 870 | extern void drbd_init_set_defaults(struct drbd_device *device); |
1079 | extern int drbd_thread_start(struct drbd_thread *thi); | 871 | extern int drbd_thread_start(struct drbd_thread *thi); |
1080 | extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait); | 872 | extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait); |
1081 | extern char *drbd_task_to_thread_name(struct drbd_tconn *tconn, struct task_struct *task); | ||
1082 | #ifdef CONFIG_SMP | 873 | #ifdef CONFIG_SMP |
1083 | extern void drbd_thread_current_set_cpu(struct drbd_thread *thi); | 874 | extern void drbd_thread_current_set_cpu(struct drbd_thread *thi); |
1084 | extern void drbd_calc_cpu_mask(struct drbd_tconn *tconn); | ||
1085 | #else | 875 | #else |
1086 | #define drbd_thread_current_set_cpu(A) ({}) | 876 | #define drbd_thread_current_set_cpu(A) ({}) |
1087 | #define drbd_calc_cpu_mask(A) ({}) | ||
1088 | #endif | 877 | #endif |
1089 | extern void tl_release(struct drbd_tconn *, unsigned int barrier_nr, | 878 | extern void tl_release(struct drbd_connection *, unsigned int barrier_nr, |
1090 | unsigned int set_size); | 879 | unsigned int set_size); |
1091 | extern void tl_clear(struct drbd_tconn *); | 880 | extern void tl_clear(struct drbd_connection *); |
1092 | extern void drbd_free_sock(struct drbd_tconn *tconn); | 881 | extern void drbd_free_sock(struct drbd_connection *connection); |
1093 | extern int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | 882 | extern int drbd_send(struct drbd_connection *connection, struct socket *sock, |
1094 | void *buf, size_t size, unsigned msg_flags); | 883 | void *buf, size_t size, unsigned msg_flags); |
1095 | extern int drbd_send_all(struct drbd_tconn *, struct socket *, void *, size_t, | 884 | extern int drbd_send_all(struct drbd_connection *, struct socket *, void *, size_t, |
1096 | unsigned); | 885 | unsigned); |
1097 | 886 | ||
1098 | extern int __drbd_send_protocol(struct drbd_tconn *tconn, enum drbd_packet cmd); | 887 | extern int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cmd); |
1099 | extern int drbd_send_protocol(struct drbd_tconn *tconn); | 888 | extern int drbd_send_protocol(struct drbd_connection *connection); |
1100 | extern int drbd_send_uuids(struct drbd_conf *mdev); | 889 | extern int drbd_send_uuids(struct drbd_peer_device *); |
1101 | extern int drbd_send_uuids_skip_initial_sync(struct drbd_conf *mdev); | 890 | extern int drbd_send_uuids_skip_initial_sync(struct drbd_peer_device *); |
1102 | extern void drbd_gen_and_send_sync_uuid(struct drbd_conf *mdev); | 891 | extern void drbd_gen_and_send_sync_uuid(struct drbd_peer_device *); |
1103 | extern int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags flags); | 892 | extern int drbd_send_sizes(struct drbd_peer_device *, int trigger_reply, enum dds_flags flags); |
1104 | extern int drbd_send_state(struct drbd_conf *mdev, union drbd_state s); | 893 | extern int drbd_send_state(struct drbd_peer_device *, union drbd_state s); |
1105 | extern int drbd_send_current_state(struct drbd_conf *mdev); | 894 | extern int drbd_send_current_state(struct drbd_peer_device *); |
1106 | extern int drbd_send_sync_param(struct drbd_conf *mdev); | 895 | extern int drbd_send_sync_param(struct drbd_peer_device *); |
1107 | extern void drbd_send_b_ack(struct drbd_tconn *tconn, u32 barrier_nr, | 896 | extern void drbd_send_b_ack(struct drbd_connection *connection, u32 barrier_nr, |
1108 | u32 set_size); | 897 | u32 set_size); |
1109 | extern int drbd_send_ack(struct drbd_conf *, enum drbd_packet, | 898 | extern int drbd_send_ack(struct drbd_peer_device *, enum drbd_packet, |
1110 | struct drbd_peer_request *); | 899 | struct drbd_peer_request *); |
1111 | extern void drbd_send_ack_rp(struct drbd_conf *mdev, enum drbd_packet cmd, | 900 | extern void drbd_send_ack_rp(struct drbd_peer_device *, enum drbd_packet, |
1112 | struct p_block_req *rp); | 901 | struct p_block_req *rp); |
1113 | extern void drbd_send_ack_dp(struct drbd_conf *mdev, enum drbd_packet cmd, | 902 | extern void drbd_send_ack_dp(struct drbd_peer_device *, enum drbd_packet, |
1114 | struct p_data *dp, int data_size); | 903 | struct p_data *dp, int data_size); |
1115 | extern int drbd_send_ack_ex(struct drbd_conf *mdev, enum drbd_packet cmd, | 904 | extern int drbd_send_ack_ex(struct drbd_peer_device *, enum drbd_packet, |
1116 | sector_t sector, int blksize, u64 block_id); | 905 | sector_t sector, int blksize, u64 block_id); |
1117 | extern int drbd_send_out_of_sync(struct drbd_conf *, struct drbd_request *); | 906 | extern int drbd_send_out_of_sync(struct drbd_peer_device *, struct drbd_request *); |
1118 | extern int drbd_send_block(struct drbd_conf *, enum drbd_packet, | 907 | extern int drbd_send_block(struct drbd_peer_device *, enum drbd_packet, |
1119 | struct drbd_peer_request *); | 908 | struct drbd_peer_request *); |
1120 | extern int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req); | 909 | extern int drbd_send_dblock(struct drbd_peer_device *, struct drbd_request *req); |
1121 | extern int drbd_send_drequest(struct drbd_conf *mdev, int cmd, | 910 | extern int drbd_send_drequest(struct drbd_peer_device *, int cmd, |
1122 | sector_t sector, int size, u64 block_id); | 911 | sector_t sector, int size, u64 block_id); |
1123 | extern int drbd_send_drequest_csum(struct drbd_conf *mdev, sector_t sector, | 912 | extern int drbd_send_drequest_csum(struct drbd_peer_device *, sector_t sector, |
1124 | int size, void *digest, int digest_size, | 913 | int size, void *digest, int digest_size, |
1125 | enum drbd_packet cmd); | 914 | enum drbd_packet cmd); |
1126 | extern int drbd_send_ov_request(struct drbd_conf *mdev,sector_t sector,int size); | 915 | extern int drbd_send_ov_request(struct drbd_peer_device *, sector_t sector, int size); |
1127 | 916 | ||
1128 | extern int drbd_send_bitmap(struct drbd_conf *mdev); | 917 | extern int drbd_send_bitmap(struct drbd_device *device); |
1129 | extern void drbd_send_sr_reply(struct drbd_conf *mdev, enum drbd_state_rv retcode); | 918 | extern void drbd_send_sr_reply(struct drbd_peer_device *, enum drbd_state_rv retcode); |
1130 | extern void conn_send_sr_reply(struct drbd_tconn *tconn, enum drbd_state_rv retcode); | 919 | extern void conn_send_sr_reply(struct drbd_connection *connection, enum drbd_state_rv retcode); |
1131 | extern void drbd_free_bc(struct drbd_backing_dev *ldev); | 920 | extern void drbd_free_bc(struct drbd_backing_dev *ldev); |
1132 | extern void drbd_mdev_cleanup(struct drbd_conf *mdev); | 921 | extern void drbd_device_cleanup(struct drbd_device *device); |
1133 | void drbd_print_uuids(struct drbd_conf *mdev, const char *text); | 922 | void drbd_print_uuids(struct drbd_device *device, const char *text); |
1134 | 923 | ||
1135 | extern void conn_md_sync(struct drbd_tconn *tconn); | 924 | extern void conn_md_sync(struct drbd_connection *connection); |
1136 | extern void drbd_md_write(struct drbd_conf *mdev, void *buffer); | 925 | extern void drbd_md_write(struct drbd_device *device, void *buffer); |
1137 | extern void drbd_md_sync(struct drbd_conf *mdev); | 926 | extern void drbd_md_sync(struct drbd_device *device); |
1138 | extern int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev); | 927 | extern int drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev); |
1139 | extern void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local); | 928 | extern void drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local); |
1140 | extern void _drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local); | 929 | extern void _drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local); |
1141 | extern void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local); | 930 | extern void drbd_uuid_new_current(struct drbd_device *device) __must_hold(local); |
1142 | extern void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local); | 931 | extern void drbd_uuid_set_bm(struct drbd_device *device, u64 val) __must_hold(local); |
1143 | extern void drbd_uuid_move_history(struct drbd_conf *mdev) __must_hold(local); | 932 | extern void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local); |
1144 | extern void __drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local); | 933 | extern void __drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local); |
1145 | extern void drbd_md_set_flag(struct drbd_conf *mdev, int flags) __must_hold(local); | 934 | extern void drbd_md_set_flag(struct drbd_device *device, int flags) __must_hold(local); |
1146 | extern void drbd_md_clear_flag(struct drbd_conf *mdev, int flags)__must_hold(local); | 935 | extern void drbd_md_clear_flag(struct drbd_device *device, int flags)__must_hold(local); |
1147 | extern int drbd_md_test_flag(struct drbd_backing_dev *, int); | 936 | extern int drbd_md_test_flag(struct drbd_backing_dev *, int); |
1148 | #ifndef DRBD_DEBUG_MD_SYNC | 937 | #ifndef DRBD_DEBUG_MD_SYNC |
1149 | extern void drbd_md_mark_dirty(struct drbd_conf *mdev); | 938 | extern void drbd_md_mark_dirty(struct drbd_device *device); |
1150 | #else | 939 | #else |
1151 | #define drbd_md_mark_dirty(m) drbd_md_mark_dirty_(m, __LINE__ , __func__ ) | 940 | #define drbd_md_mark_dirty(m) drbd_md_mark_dirty_(m, __LINE__ , __func__ ) |
1152 | extern void drbd_md_mark_dirty_(struct drbd_conf *mdev, | 941 | extern void drbd_md_mark_dirty_(struct drbd_device *device, |
1153 | unsigned int line, const char *func); | 942 | unsigned int line, const char *func); |
1154 | #endif | 943 | #endif |
1155 | extern void drbd_queue_bitmap_io(struct drbd_conf *mdev, | 944 | extern void drbd_queue_bitmap_io(struct drbd_device *device, |
1156 | int (*io_fn)(struct drbd_conf *), | 945 | int (*io_fn)(struct drbd_device *), |
1157 | void (*done)(struct drbd_conf *, int), | 946 | void (*done)(struct drbd_device *, int), |
1158 | char *why, enum bm_flag flags); | 947 | char *why, enum bm_flag flags); |
1159 | extern int drbd_bitmap_io(struct drbd_conf *mdev, | 948 | extern int drbd_bitmap_io(struct drbd_device *device, |
1160 | int (*io_fn)(struct drbd_conf *), | 949 | int (*io_fn)(struct drbd_device *), |
1161 | char *why, enum bm_flag flags); | 950 | char *why, enum bm_flag flags); |
1162 | extern int drbd_bitmap_io_from_worker(struct drbd_conf *mdev, | 951 | extern int drbd_bitmap_io_from_worker(struct drbd_device *device, |
1163 | int (*io_fn)(struct drbd_conf *), | 952 | int (*io_fn)(struct drbd_device *), |
1164 | char *why, enum bm_flag flags); | 953 | char *why, enum bm_flag flags); |
1165 | extern int drbd_bmio_set_n_write(struct drbd_conf *mdev); | 954 | extern int drbd_bmio_set_n_write(struct drbd_device *device); |
1166 | extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev); | 955 | extern int drbd_bmio_clear_n_write(struct drbd_device *device); |
1167 | extern void drbd_ldev_destroy(struct drbd_conf *mdev); | 956 | extern void drbd_ldev_destroy(struct drbd_device *device); |
1168 | 957 | ||
1169 | /* Meta data layout | 958 | /* Meta data layout |
1170 | * | 959 | * |
@@ -1350,52 +1139,52 @@ struct bm_extent { | |||
1350 | #define DRBD_MAX_SIZE_H80_PACKET (1U << 15) /* Header 80 only allows packets up to 32KiB data */ | 1139 | #define DRBD_MAX_SIZE_H80_PACKET (1U << 15) /* Header 80 only allows packets up to 32KiB data */ |
1351 | #define DRBD_MAX_BIO_SIZE_P95 (1U << 17) /* Protocol 95 to 99 allows bios up to 128KiB */ | 1140 | #define DRBD_MAX_BIO_SIZE_P95 (1U << 17) /* Protocol 95 to 99 allows bios up to 128KiB */ |
1352 | 1141 | ||
1353 | extern int drbd_bm_init(struct drbd_conf *mdev); | 1142 | extern int drbd_bm_init(struct drbd_device *device); |
1354 | extern int drbd_bm_resize(struct drbd_conf *mdev, sector_t sectors, int set_new_bits); | 1143 | extern int drbd_bm_resize(struct drbd_device *device, sector_t sectors, int set_new_bits); |
1355 | extern void drbd_bm_cleanup(struct drbd_conf *mdev); | 1144 | extern void drbd_bm_cleanup(struct drbd_device *device); |
1356 | extern void drbd_bm_set_all(struct drbd_conf *mdev); | 1145 | extern void drbd_bm_set_all(struct drbd_device *device); |
1357 | extern void drbd_bm_clear_all(struct drbd_conf *mdev); | 1146 | extern void drbd_bm_clear_all(struct drbd_device *device); |
1358 | /* set/clear/test only a few bits at a time */ | 1147 | /* set/clear/test only a few bits at a time */ |
1359 | extern int drbd_bm_set_bits( | 1148 | extern int drbd_bm_set_bits( |
1360 | struct drbd_conf *mdev, unsigned long s, unsigned long e); | 1149 | struct drbd_device *device, unsigned long s, unsigned long e); |
1361 | extern int drbd_bm_clear_bits( | 1150 | extern int drbd_bm_clear_bits( |
1362 | struct drbd_conf *mdev, unsigned long s, unsigned long e); | 1151 | struct drbd_device *device, unsigned long s, unsigned long e); |
1363 | extern int drbd_bm_count_bits( | 1152 | extern int drbd_bm_count_bits( |
1364 | struct drbd_conf *mdev, const unsigned long s, const unsigned long e); | 1153 | struct drbd_device *device, const unsigned long s, const unsigned long e); |
1365 | /* bm_set_bits variant for use while holding drbd_bm_lock, | 1154 | /* bm_set_bits variant for use while holding drbd_bm_lock, |
1366 | * may process the whole bitmap in one go */ | 1155 | * may process the whole bitmap in one go */ |
1367 | extern void _drbd_bm_set_bits(struct drbd_conf *mdev, | 1156 | extern void _drbd_bm_set_bits(struct drbd_device *device, |
1368 | const unsigned long s, const unsigned long e); | 1157 | const unsigned long s, const unsigned long e); |
1369 | extern int drbd_bm_test_bit(struct drbd_conf *mdev, unsigned long bitnr); | 1158 | extern int drbd_bm_test_bit(struct drbd_device *device, unsigned long bitnr); |
1370 | extern int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr); | 1159 | extern int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr); |
1371 | extern int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(local); | 1160 | extern int drbd_bm_write_page(struct drbd_device *device, unsigned int idx) __must_hold(local); |
1372 | extern int drbd_bm_read(struct drbd_conf *mdev) __must_hold(local); | 1161 | extern int drbd_bm_read(struct drbd_device *device) __must_hold(local); |
1373 | extern void drbd_bm_mark_for_writeout(struct drbd_conf *mdev, int page_nr); | 1162 | extern void drbd_bm_mark_for_writeout(struct drbd_device *device, int page_nr); |
1374 | extern int drbd_bm_write(struct drbd_conf *mdev) __must_hold(local); | 1163 | extern int drbd_bm_write(struct drbd_device *device) __must_hold(local); |
1375 | extern int drbd_bm_write_hinted(struct drbd_conf *mdev) __must_hold(local); | 1164 | extern int drbd_bm_write_hinted(struct drbd_device *device) __must_hold(local); |
1376 | extern int drbd_bm_write_all(struct drbd_conf *mdev) __must_hold(local); | 1165 | extern int drbd_bm_write_all(struct drbd_device *device) __must_hold(local); |
1377 | extern int drbd_bm_write_copy_pages(struct drbd_conf *mdev) __must_hold(local); | 1166 | extern int drbd_bm_write_copy_pages(struct drbd_device *device) __must_hold(local); |
1378 | extern size_t drbd_bm_words(struct drbd_conf *mdev); | 1167 | extern size_t drbd_bm_words(struct drbd_device *device); |
1379 | extern unsigned long drbd_bm_bits(struct drbd_conf *mdev); | 1168 | extern unsigned long drbd_bm_bits(struct drbd_device *device); |
1380 | extern sector_t drbd_bm_capacity(struct drbd_conf *mdev); | 1169 | extern sector_t drbd_bm_capacity(struct drbd_device *device); |
1381 | 1170 | ||
1382 | #define DRBD_END_OF_BITMAP (~(unsigned long)0) | 1171 | #define DRBD_END_OF_BITMAP (~(unsigned long)0) |
1383 | extern unsigned long drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo); | 1172 | extern unsigned long drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo); |
1384 | /* bm_find_next variants for use while you hold drbd_bm_lock() */ | 1173 | /* bm_find_next variants for use while you hold drbd_bm_lock() */ |
1385 | extern unsigned long _drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo); | 1174 | extern unsigned long _drbd_bm_find_next(struct drbd_device *device, unsigned long bm_fo); |
1386 | extern unsigned long _drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_fo); | 1175 | extern unsigned long _drbd_bm_find_next_zero(struct drbd_device *device, unsigned long bm_fo); |
1387 | extern unsigned long _drbd_bm_total_weight(struct drbd_conf *mdev); | 1176 | extern unsigned long _drbd_bm_total_weight(struct drbd_device *device); |
1388 | extern unsigned long drbd_bm_total_weight(struct drbd_conf *mdev); | 1177 | extern unsigned long drbd_bm_total_weight(struct drbd_device *device); |
1389 | extern int drbd_bm_rs_done(struct drbd_conf *mdev); | 1178 | extern int drbd_bm_rs_done(struct drbd_device *device); |
1390 | /* for receive_bitmap */ | 1179 | /* for receive_bitmap */ |
1391 | extern void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset, | 1180 | extern void drbd_bm_merge_lel(struct drbd_device *device, size_t offset, |
1392 | size_t number, unsigned long *buffer); | 1181 | size_t number, unsigned long *buffer); |
1393 | /* for _drbd_send_bitmap */ | 1182 | /* for _drbd_send_bitmap */ |
1394 | extern void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset, | 1183 | extern void drbd_bm_get_lel(struct drbd_device *device, size_t offset, |
1395 | size_t number, unsigned long *buffer); | 1184 | size_t number, unsigned long *buffer); |
1396 | 1185 | ||
1397 | extern void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags); | 1186 | extern void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags); |
1398 | extern void drbd_bm_unlock(struct drbd_conf *mdev); | 1187 | extern void drbd_bm_unlock(struct drbd_device *device); |
1399 | /* drbd_main.c */ | 1188 | /* drbd_main.c */ |
1400 | 1189 | ||
1401 | extern struct kmem_cache *drbd_request_cache; | 1190 | extern struct kmem_cache *drbd_request_cache; |
@@ -1439,35 +1228,40 @@ extern struct bio *bio_alloc_drbd(gfp_t gfp_mask); | |||
1439 | 1228 | ||
1440 | extern rwlock_t global_state_lock; | 1229 | extern rwlock_t global_state_lock; |
1441 | 1230 | ||
1442 | extern int conn_lowest_minor(struct drbd_tconn *tconn); | 1231 | extern int conn_lowest_minor(struct drbd_connection *connection); |
1443 | enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, int vnr); | 1232 | enum drbd_ret_code drbd_create_device(struct drbd_resource *resource, unsigned int minor, int vnr); |
1444 | extern void drbd_minor_destroy(struct kref *kref); | 1233 | extern void drbd_destroy_device(struct kref *kref); |
1234 | extern void drbd_delete_device(struct drbd_device *mdev); | ||
1235 | |||
1236 | extern struct drbd_resource *drbd_create_resource(const char *name); | ||
1237 | extern void drbd_free_resource(struct drbd_resource *resource); | ||
1445 | 1238 | ||
1446 | extern int set_resource_options(struct drbd_tconn *tconn, struct res_opts *res_opts); | 1239 | extern int set_resource_options(struct drbd_resource *resource, struct res_opts *res_opts); |
1447 | extern struct drbd_tconn *conn_create(const char *name, struct res_opts *res_opts); | 1240 | extern struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts); |
1448 | extern void conn_destroy(struct kref *kref); | 1241 | extern void drbd_destroy_connection(struct kref *kref); |
1449 | struct drbd_tconn *conn_get_by_name(const char *name); | 1242 | extern struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len, |
1450 | extern struct drbd_tconn *conn_get_by_addrs(void *my_addr, int my_addr_len, | ||
1451 | void *peer_addr, int peer_addr_len); | 1243 | void *peer_addr, int peer_addr_len); |
1452 | extern void conn_free_crypto(struct drbd_tconn *tconn); | 1244 | extern struct drbd_resource *drbd_find_resource(const char *name); |
1245 | extern void drbd_destroy_resource(struct kref *kref); | ||
1246 | extern void conn_free_crypto(struct drbd_connection *connection); | ||
1453 | 1247 | ||
1454 | extern int proc_details; | 1248 | extern int proc_details; |
1455 | 1249 | ||
1456 | /* drbd_req */ | 1250 | /* drbd_req */ |
1457 | extern void do_submit(struct work_struct *ws); | 1251 | extern void do_submit(struct work_struct *ws); |
1458 | extern void __drbd_make_request(struct drbd_conf *, struct bio *, unsigned long); | 1252 | extern void __drbd_make_request(struct drbd_device *, struct bio *, unsigned long); |
1459 | extern void drbd_make_request(struct request_queue *q, struct bio *bio); | 1253 | extern void drbd_make_request(struct request_queue *q, struct bio *bio); |
1460 | extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req); | 1254 | extern int drbd_read_remote(struct drbd_device *device, struct drbd_request *req); |
1461 | extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec); | 1255 | extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec); |
1462 | extern int is_valid_ar_handle(struct drbd_request *, sector_t); | 1256 | extern int is_valid_ar_handle(struct drbd_request *, sector_t); |
1463 | 1257 | ||
1464 | 1258 | ||
1465 | /* drbd_nl.c */ | 1259 | /* drbd_nl.c */ |
1466 | extern int drbd_msg_put_info(const char *info); | 1260 | extern int drbd_msg_put_info(const char *info); |
1467 | extern void drbd_suspend_io(struct drbd_conf *mdev); | 1261 | extern void drbd_suspend_io(struct drbd_device *device); |
1468 | extern void drbd_resume_io(struct drbd_conf *mdev); | 1262 | extern void drbd_resume_io(struct drbd_device *device); |
1469 | extern char *ppsize(char *buf, unsigned long long size); | 1263 | extern char *ppsize(char *buf, unsigned long long size); |
1470 | extern sector_t drbd_new_dev_size(struct drbd_conf *, struct drbd_backing_dev *, sector_t, int); | 1264 | extern sector_t drbd_new_dev_size(struct drbd_device *, struct drbd_backing_dev *, sector_t, int); |
1471 | enum determine_dev_size { | 1265 | enum determine_dev_size { |
1472 | DS_ERROR_SHRINK = -3, | 1266 | DS_ERROR_SHRINK = -3, |
1473 | DS_ERROR_SPACE_MD = -2, | 1267 | DS_ERROR_SPACE_MD = -2, |
@@ -1478,48 +1272,47 @@ enum determine_dev_size { | |||
1478 | DS_GREW_FROM_ZERO = 3, | 1272 | DS_GREW_FROM_ZERO = 3, |
1479 | }; | 1273 | }; |
1480 | extern enum determine_dev_size | 1274 | extern enum determine_dev_size |
1481 | drbd_determine_dev_size(struct drbd_conf *, enum dds_flags, struct resize_parms *) __must_hold(local); | 1275 | drbd_determine_dev_size(struct drbd_device *, enum dds_flags, struct resize_parms *) __must_hold(local); |
1482 | extern void resync_after_online_grow(struct drbd_conf *); | 1276 | extern void resync_after_online_grow(struct drbd_device *); |
1483 | extern void drbd_reconsider_max_bio_size(struct drbd_conf *mdev); | 1277 | extern void drbd_reconsider_max_bio_size(struct drbd_device *device); |
1484 | extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev, | 1278 | extern enum drbd_state_rv drbd_set_role(struct drbd_device *device, |
1485 | enum drbd_role new_role, | 1279 | enum drbd_role new_role, |
1486 | int force); | 1280 | int force); |
1487 | extern bool conn_try_outdate_peer(struct drbd_tconn *tconn); | 1281 | extern bool conn_try_outdate_peer(struct drbd_connection *connection); |
1488 | extern void conn_try_outdate_peer_async(struct drbd_tconn *tconn); | 1282 | extern void conn_try_outdate_peer_async(struct drbd_connection *connection); |
1489 | extern int drbd_khelper(struct drbd_conf *mdev, char *cmd); | 1283 | extern int drbd_khelper(struct drbd_device *device, char *cmd); |
1490 | 1284 | ||
1491 | /* drbd_worker.c */ | 1285 | /* drbd_worker.c */ |
1492 | extern int drbd_worker(struct drbd_thread *thi); | 1286 | extern int drbd_worker(struct drbd_thread *thi); |
1493 | enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor); | 1287 | enum drbd_ret_code drbd_resync_after_valid(struct drbd_device *device, int o_minor); |
1494 | void drbd_resync_after_changed(struct drbd_conf *mdev); | 1288 | void drbd_resync_after_changed(struct drbd_device *device); |
1495 | extern void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side); | 1289 | extern void drbd_start_resync(struct drbd_device *device, enum drbd_conns side); |
1496 | extern void resume_next_sg(struct drbd_conf *mdev); | 1290 | extern void resume_next_sg(struct drbd_device *device); |
1497 | extern void suspend_other_sg(struct drbd_conf *mdev); | 1291 | extern void suspend_other_sg(struct drbd_device *device); |
1498 | extern int drbd_resync_finished(struct drbd_conf *mdev); | 1292 | extern int drbd_resync_finished(struct drbd_device *device); |
1499 | /* maybe rather drbd_main.c ? */ | 1293 | /* maybe rather drbd_main.c ? */ |
1500 | extern void *drbd_md_get_buffer(struct drbd_conf *mdev); | 1294 | extern void *drbd_md_get_buffer(struct drbd_device *device); |
1501 | extern void drbd_md_put_buffer(struct drbd_conf *mdev); | 1295 | extern void drbd_md_put_buffer(struct drbd_device *device); |
1502 | extern int drbd_md_sync_page_io(struct drbd_conf *mdev, | 1296 | extern int drbd_md_sync_page_io(struct drbd_device *device, |
1503 | struct drbd_backing_dev *bdev, sector_t sector, int rw); | 1297 | struct drbd_backing_dev *bdev, sector_t sector, int rw); |
1504 | extern void drbd_ov_out_of_sync_found(struct drbd_conf *, sector_t, int); | 1298 | extern void drbd_ov_out_of_sync_found(struct drbd_device *, sector_t, int); |
1505 | extern void wait_until_done_or_force_detached(struct drbd_conf *mdev, | 1299 | extern void wait_until_done_or_force_detached(struct drbd_device *device, |
1506 | struct drbd_backing_dev *bdev, unsigned int *done); | 1300 | struct drbd_backing_dev *bdev, unsigned int *done); |
1507 | extern void drbd_rs_controller_reset(struct drbd_conf *mdev); | 1301 | extern void drbd_rs_controller_reset(struct drbd_device *device); |
1508 | 1302 | ||
1509 | static inline void ov_out_of_sync_print(struct drbd_conf *mdev) | 1303 | static inline void ov_out_of_sync_print(struct drbd_device *device) |
1510 | { | 1304 | { |
1511 | if (mdev->ov_last_oos_size) { | 1305 | if (device->ov_last_oos_size) { |
1512 | dev_err(DEV, "Out of sync: start=%llu, size=%lu (sectors)\n", | 1306 | drbd_err(device, "Out of sync: start=%llu, size=%lu (sectors)\n", |
1513 | (unsigned long long)mdev->ov_last_oos_start, | 1307 | (unsigned long long)device->ov_last_oos_start, |
1514 | (unsigned long)mdev->ov_last_oos_size); | 1308 | (unsigned long)device->ov_last_oos_size); |
1515 | } | 1309 | } |
1516 | mdev->ov_last_oos_size=0; | 1310 | device->ov_last_oos_size = 0; |
1517 | } | 1311 | } |
1518 | 1312 | ||
1519 | 1313 | ||
1520 | extern void drbd_csum_bio(struct drbd_conf *, struct crypto_hash *, struct bio *, void *); | 1314 | extern void drbd_csum_bio(struct crypto_hash *, struct bio *, void *); |
1521 | extern void drbd_csum_ee(struct drbd_conf *, struct crypto_hash *, | 1315 | extern void drbd_csum_ee(struct crypto_hash *, struct drbd_peer_request *, void *); |
1522 | struct drbd_peer_request *, void *); | ||
1523 | /* worker callbacks */ | 1316 | /* worker callbacks */ |
1524 | extern int w_e_end_data_req(struct drbd_work *, int); | 1317 | extern int w_e_end_data_req(struct drbd_work *, int); |
1525 | extern int w_e_end_rsdata_req(struct drbd_work *, int); | 1318 | extern int w_e_end_rsdata_req(struct drbd_work *, int); |
@@ -1529,10 +1322,8 @@ extern int w_e_end_ov_req(struct drbd_work *, int); | |||
1529 | extern int w_ov_finished(struct drbd_work *, int); | 1322 | extern int w_ov_finished(struct drbd_work *, int); |
1530 | extern int w_resync_timer(struct drbd_work *, int); | 1323 | extern int w_resync_timer(struct drbd_work *, int); |
1531 | extern int w_send_write_hint(struct drbd_work *, int); | 1324 | extern int w_send_write_hint(struct drbd_work *, int); |
1532 | extern int w_make_resync_request(struct drbd_work *, int); | ||
1533 | extern int w_send_dblock(struct drbd_work *, int); | 1325 | extern int w_send_dblock(struct drbd_work *, int); |
1534 | extern int w_send_read_req(struct drbd_work *, int); | 1326 | extern int w_send_read_req(struct drbd_work *, int); |
1535 | extern int w_prev_work_done(struct drbd_work *, int); | ||
1536 | extern int w_e_reissue(struct drbd_work *, int); | 1327 | extern int w_e_reissue(struct drbd_work *, int); |
1537 | extern int w_restart_disk_io(struct drbd_work *, int); | 1328 | extern int w_restart_disk_io(struct drbd_work *, int); |
1538 | extern int w_send_out_of_sync(struct drbd_work *, int); | 1329 | extern int w_send_out_of_sync(struct drbd_work *, int); |
@@ -1542,27 +1333,24 @@ extern void resync_timer_fn(unsigned long data); | |||
1542 | extern void start_resync_timer_fn(unsigned long data); | 1333 | extern void start_resync_timer_fn(unsigned long data); |
1543 | 1334 | ||
1544 | /* drbd_receiver.c */ | 1335 | /* drbd_receiver.c */ |
1545 | extern int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector); | 1336 | extern int drbd_receiver(struct drbd_thread *thi); |
1546 | extern int drbd_submit_peer_request(struct drbd_conf *, | 1337 | extern int drbd_asender(struct drbd_thread *thi); |
1338 | extern int drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector); | ||
1339 | extern int drbd_submit_peer_request(struct drbd_device *, | ||
1547 | struct drbd_peer_request *, const unsigned, | 1340 | struct drbd_peer_request *, const unsigned, |
1548 | const int); | 1341 | const int); |
1549 | extern int drbd_free_peer_reqs(struct drbd_conf *, struct list_head *); | 1342 | extern int drbd_free_peer_reqs(struct drbd_device *, struct list_head *); |
1550 | extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_conf *, u64, | 1343 | extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_peer_device *, u64, |
1551 | sector_t, unsigned int, | 1344 | sector_t, unsigned int, |
1552 | gfp_t) __must_hold(local); | 1345 | gfp_t) __must_hold(local); |
1553 | extern void __drbd_free_peer_req(struct drbd_conf *, struct drbd_peer_request *, | 1346 | extern void __drbd_free_peer_req(struct drbd_device *, struct drbd_peer_request *, |
1554 | int); | 1347 | int); |
1555 | #define drbd_free_peer_req(m,e) __drbd_free_peer_req(m, e, 0) | 1348 | #define drbd_free_peer_req(m,e) __drbd_free_peer_req(m, e, 0) |
1556 | #define drbd_free_net_peer_req(m,e) __drbd_free_peer_req(m, e, 1) | 1349 | #define drbd_free_net_peer_req(m,e) __drbd_free_peer_req(m, e, 1) |
1557 | extern struct page *drbd_alloc_pages(struct drbd_conf *, unsigned int, bool); | 1350 | extern struct page *drbd_alloc_pages(struct drbd_peer_device *, unsigned int, bool); |
1558 | extern void drbd_set_recv_tcq(struct drbd_conf *mdev, int tcq_enabled); | 1351 | extern void drbd_set_recv_tcq(struct drbd_device *device, int tcq_enabled); |
1559 | extern void _drbd_clear_done_ee(struct drbd_conf *mdev, struct list_head *to_be_freed); | 1352 | extern void _drbd_clear_done_ee(struct drbd_device *device, struct list_head *to_be_freed); |
1560 | extern void conn_flush_workqueue(struct drbd_tconn *tconn); | 1353 | extern int drbd_connected(struct drbd_peer_device *); |
1561 | extern int drbd_connected(struct drbd_conf *mdev); | ||
1562 | static inline void drbd_flush_workqueue(struct drbd_conf *mdev) | ||
1563 | { | ||
1564 | conn_flush_workqueue(mdev->tconn); | ||
1565 | } | ||
1566 | 1354 | ||
1567 | /* Yes, there is kernel_setsockopt, but only since 2.6.18. | 1355 | /* Yes, there is kernel_setsockopt, but only since 2.6.18. |
1568 | * So we have our own copy of it here. */ | 1356 | * So we have our own copy of it here. */ |
@@ -1613,7 +1401,7 @@ static inline void drbd_tcp_quickack(struct socket *sock) | |||
1613 | (char*)&val, sizeof(val)); | 1401 | (char*)&val, sizeof(val)); |
1614 | } | 1402 | } |
1615 | 1403 | ||
1616 | void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo); | 1404 | void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ordering_e wo); |
1617 | 1405 | ||
1618 | /* drbd_proc.c */ | 1406 | /* drbd_proc.c */ |
1619 | extern struct proc_dir_entry *drbd_proc; | 1407 | extern struct proc_dir_entry *drbd_proc; |
@@ -1622,29 +1410,29 @@ extern const char *drbd_conn_str(enum drbd_conns s); | |||
1622 | extern const char *drbd_role_str(enum drbd_role s); | 1410 | extern const char *drbd_role_str(enum drbd_role s); |
1623 | 1411 | ||
1624 | /* drbd_actlog.c */ | 1412 | /* drbd_actlog.c */ |
1625 | extern int drbd_al_begin_io_nonblock(struct drbd_conf *mdev, struct drbd_interval *i); | 1413 | extern int drbd_al_begin_io_nonblock(struct drbd_device *device, struct drbd_interval *i); |
1626 | extern void drbd_al_begin_io_commit(struct drbd_conf *mdev, bool delegate); | 1414 | extern void drbd_al_begin_io_commit(struct drbd_device *device, bool delegate); |
1627 | extern bool drbd_al_begin_io_fastpath(struct drbd_conf *mdev, struct drbd_interval *i); | 1415 | extern bool drbd_al_begin_io_fastpath(struct drbd_device *device, struct drbd_interval *i); |
1628 | extern void drbd_al_begin_io(struct drbd_conf *mdev, struct drbd_interval *i, bool delegate); | 1416 | extern void drbd_al_begin_io(struct drbd_device *device, struct drbd_interval *i, bool delegate); |
1629 | extern void drbd_al_complete_io(struct drbd_conf *mdev, struct drbd_interval *i); | 1417 | extern void drbd_al_complete_io(struct drbd_device *device, struct drbd_interval *i); |
1630 | extern void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector); | 1418 | extern void drbd_rs_complete_io(struct drbd_device *device, sector_t sector); |
1631 | extern int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector); | 1419 | extern int drbd_rs_begin_io(struct drbd_device *device, sector_t sector); |
1632 | extern int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector); | 1420 | extern int drbd_try_rs_begin_io(struct drbd_device *device, sector_t sector); |
1633 | extern void drbd_rs_cancel_all(struct drbd_conf *mdev); | 1421 | extern void drbd_rs_cancel_all(struct drbd_device *device); |
1634 | extern int drbd_rs_del_all(struct drbd_conf *mdev); | 1422 | extern int drbd_rs_del_all(struct drbd_device *device); |
1635 | extern void drbd_rs_failed_io(struct drbd_conf *mdev, | 1423 | extern void drbd_rs_failed_io(struct drbd_device *device, |
1636 | sector_t sector, int size); | 1424 | sector_t sector, int size); |
1637 | extern void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go); | 1425 | extern void drbd_advance_rs_marks(struct drbd_device *device, unsigned long still_to_go); |
1638 | extern void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, | 1426 | extern void __drbd_set_in_sync(struct drbd_device *device, sector_t sector, |
1639 | int size, const char *file, const unsigned int line); | 1427 | int size, const char *file, const unsigned int line); |
1640 | #define drbd_set_in_sync(mdev, sector, size) \ | 1428 | #define drbd_set_in_sync(device, sector, size) \ |
1641 | __drbd_set_in_sync(mdev, sector, size, __FILE__, __LINE__) | 1429 | __drbd_set_in_sync(device, sector, size, __FILE__, __LINE__) |
1642 | extern int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, | 1430 | extern int __drbd_set_out_of_sync(struct drbd_device *device, sector_t sector, |
1643 | int size, const char *file, const unsigned int line); | 1431 | int size, const char *file, const unsigned int line); |
1644 | #define drbd_set_out_of_sync(mdev, sector, size) \ | 1432 | #define drbd_set_out_of_sync(device, sector, size) \ |
1645 | __drbd_set_out_of_sync(mdev, sector, size, __FILE__, __LINE__) | 1433 | __drbd_set_out_of_sync(device, sector, size, __FILE__, __LINE__) |
1646 | extern void drbd_al_shrink(struct drbd_conf *mdev); | 1434 | extern void drbd_al_shrink(struct drbd_device *device); |
1647 | extern int drbd_initialize_al(struct drbd_conf *, void *); | 1435 | extern int drbd_initialize_al(struct drbd_device *, void *); |
1648 | 1436 | ||
1649 | /* drbd_nl.c */ | 1437 | /* drbd_nl.c */ |
1650 | /* state info broadcast */ | 1438 | /* state info broadcast */ |
@@ -1661,7 +1449,7 @@ struct sib_info { | |||
1661 | }; | 1449 | }; |
1662 | }; | 1450 | }; |
1663 | }; | 1451 | }; |
1664 | void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib); | 1452 | void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib); |
1665 | 1453 | ||
1666 | /* | 1454 | /* |
1667 | * inline helper functions | 1455 | * inline helper functions |
@@ -1690,26 +1478,27 @@ static inline int drbd_peer_req_has_active_page(struct drbd_peer_request *peer_r | |||
1690 | } | 1478 | } |
1691 | 1479 | ||
1692 | static inline enum drbd_state_rv | 1480 | static inline enum drbd_state_rv |
1693 | _drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | 1481 | _drbd_set_state(struct drbd_device *device, union drbd_state ns, |
1694 | enum chg_state_flags flags, struct completion *done) | 1482 | enum chg_state_flags flags, struct completion *done) |
1695 | { | 1483 | { |
1696 | enum drbd_state_rv rv; | 1484 | enum drbd_state_rv rv; |
1697 | 1485 | ||
1698 | read_lock(&global_state_lock); | 1486 | read_lock(&global_state_lock); |
1699 | rv = __drbd_set_state(mdev, ns, flags, done); | 1487 | rv = __drbd_set_state(device, ns, flags, done); |
1700 | read_unlock(&global_state_lock); | 1488 | read_unlock(&global_state_lock); |
1701 | 1489 | ||
1702 | return rv; | 1490 | return rv; |
1703 | } | 1491 | } |
1704 | 1492 | ||
1705 | static inline union drbd_state drbd_read_state(struct drbd_conf *mdev) | 1493 | static inline union drbd_state drbd_read_state(struct drbd_device *device) |
1706 | { | 1494 | { |
1495 | struct drbd_resource *resource = device->resource; | ||
1707 | union drbd_state rv; | 1496 | union drbd_state rv; |
1708 | 1497 | ||
1709 | rv.i = mdev->state.i; | 1498 | rv.i = device->state.i; |
1710 | rv.susp = mdev->tconn->susp; | 1499 | rv.susp = resource->susp; |
1711 | rv.susp_nod = mdev->tconn->susp_nod; | 1500 | rv.susp_nod = resource->susp_nod; |
1712 | rv.susp_fen = mdev->tconn->susp_fen; | 1501 | rv.susp_fen = resource->susp_fen; |
1713 | 1502 | ||
1714 | return rv; | 1503 | return rv; |
1715 | } | 1504 | } |
@@ -1722,22 +1511,22 @@ enum drbd_force_detach_flags { | |||
1722 | }; | 1511 | }; |
1723 | 1512 | ||
1724 | #define __drbd_chk_io_error(m,f) __drbd_chk_io_error_(m,f, __func__) | 1513 | #define __drbd_chk_io_error(m,f) __drbd_chk_io_error_(m,f, __func__) |
1725 | static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, | 1514 | static inline void __drbd_chk_io_error_(struct drbd_device *device, |
1726 | enum drbd_force_detach_flags df, | 1515 | enum drbd_force_detach_flags df, |
1727 | const char *where) | 1516 | const char *where) |
1728 | { | 1517 | { |
1729 | enum drbd_io_error_p ep; | 1518 | enum drbd_io_error_p ep; |
1730 | 1519 | ||
1731 | rcu_read_lock(); | 1520 | rcu_read_lock(); |
1732 | ep = rcu_dereference(mdev->ldev->disk_conf)->on_io_error; | 1521 | ep = rcu_dereference(device->ldev->disk_conf)->on_io_error; |
1733 | rcu_read_unlock(); | 1522 | rcu_read_unlock(); |
1734 | switch (ep) { | 1523 | switch (ep) { |
1735 | case EP_PASS_ON: /* FIXME would this be better named "Ignore"? */ | 1524 | case EP_PASS_ON: /* FIXME would this be better named "Ignore"? */ |
1736 | if (df == DRBD_READ_ERROR || df == DRBD_WRITE_ERROR) { | 1525 | if (df == DRBD_READ_ERROR || df == DRBD_WRITE_ERROR) { |
1737 | if (__ratelimit(&drbd_ratelimit_state)) | 1526 | if (__ratelimit(&drbd_ratelimit_state)) |
1738 | dev_err(DEV, "Local IO failed in %s.\n", where); | 1527 | drbd_err(device, "Local IO failed in %s.\n", where); |
1739 | if (mdev->state.disk > D_INCONSISTENT) | 1528 | if (device->state.disk > D_INCONSISTENT) |
1740 | _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_HARD, NULL); | 1529 | _drbd_set_state(_NS(device, disk, D_INCONSISTENT), CS_HARD, NULL); |
1741 | break; | 1530 | break; |
1742 | } | 1531 | } |
1743 | /* NOTE fall through for DRBD_META_IO_ERROR or DRBD_FORCE_DETACH */ | 1532 | /* NOTE fall through for DRBD_META_IO_ERROR or DRBD_FORCE_DETACH */ |
@@ -1763,14 +1552,14 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, | |||
1763 | * we read meta data only once during attach, | 1552 | * we read meta data only once during attach, |
1764 | * which will fail in case of errors. | 1553 | * which will fail in case of errors. |
1765 | */ | 1554 | */ |
1766 | set_bit(WAS_IO_ERROR, &mdev->flags); | 1555 | set_bit(WAS_IO_ERROR, &device->flags); |
1767 | if (df == DRBD_READ_ERROR) | 1556 | if (df == DRBD_READ_ERROR) |
1768 | set_bit(WAS_READ_ERROR, &mdev->flags); | 1557 | set_bit(WAS_READ_ERROR, &device->flags); |
1769 | if (df == DRBD_FORCE_DETACH) | 1558 | if (df == DRBD_FORCE_DETACH) |
1770 | set_bit(FORCE_DETACH, &mdev->flags); | 1559 | set_bit(FORCE_DETACH, &device->flags); |
1771 | if (mdev->state.disk > D_FAILED) { | 1560 | if (device->state.disk > D_FAILED) { |
1772 | _drbd_set_state(_NS(mdev, disk, D_FAILED), CS_HARD, NULL); | 1561 | _drbd_set_state(_NS(device, disk, D_FAILED), CS_HARD, NULL); |
1773 | dev_err(DEV, | 1562 | drbd_err(device, |
1774 | "Local IO failed in %s. Detaching...\n", where); | 1563 | "Local IO failed in %s. Detaching...\n", where); |
1775 | } | 1564 | } |
1776 | break; | 1565 | break; |
@@ -1779,21 +1568,21 @@ static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, | |||
1779 | 1568 | ||
1780 | /** | 1569 | /** |
1781 | * drbd_chk_io_error: Handle the on_io_error setting, should be called from all io completion handlers | 1570 | * drbd_chk_io_error: Handle the on_io_error setting, should be called from all io completion handlers |
1782 | * @mdev: DRBD device. | 1571 | * @device: DRBD device. |
1783 | * @error: Error code passed to the IO completion callback | 1572 | * @error: Error code passed to the IO completion callback |
1784 | * @forcedetach: Force detach. I.e. the error happened while accessing the meta data | 1573 | * @forcedetach: Force detach. I.e. the error happened while accessing the meta data |
1785 | * | 1574 | * |
1786 | * See also drbd_main.c:after_state_ch() if (os.disk > D_FAILED && ns.disk == D_FAILED) | 1575 | * See also drbd_main.c:after_state_ch() if (os.disk > D_FAILED && ns.disk == D_FAILED) |
1787 | */ | 1576 | */ |
1788 | #define drbd_chk_io_error(m,e,f) drbd_chk_io_error_(m,e,f, __func__) | 1577 | #define drbd_chk_io_error(m,e,f) drbd_chk_io_error_(m,e,f, __func__) |
1789 | static inline void drbd_chk_io_error_(struct drbd_conf *mdev, | 1578 | static inline void drbd_chk_io_error_(struct drbd_device *device, |
1790 | int error, enum drbd_force_detach_flags forcedetach, const char *where) | 1579 | int error, enum drbd_force_detach_flags forcedetach, const char *where) |
1791 | { | 1580 | { |
1792 | if (error) { | 1581 | if (error) { |
1793 | unsigned long flags; | 1582 | unsigned long flags; |
1794 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 1583 | spin_lock_irqsave(&device->resource->req_lock, flags); |
1795 | __drbd_chk_io_error_(mdev, forcedetach, where); | 1584 | __drbd_chk_io_error_(device, forcedetach, where); |
1796 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 1585 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
1797 | } | 1586 | } |
1798 | } | 1587 | } |
1799 | 1588 | ||
@@ -1916,31 +1705,33 @@ drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w) | |||
1916 | wake_up(&q->q_wait); | 1705 | wake_up(&q->q_wait); |
1917 | } | 1706 | } |
1918 | 1707 | ||
1919 | static inline void wake_asender(struct drbd_tconn *tconn) | 1708 | extern void drbd_flush_workqueue(struct drbd_work_queue *work_queue); |
1709 | |||
1710 | static inline void wake_asender(struct drbd_connection *connection) | ||
1920 | { | 1711 | { |
1921 | if (test_bit(SIGNAL_ASENDER, &tconn->flags)) | 1712 | if (test_bit(SIGNAL_ASENDER, &connection->flags)) |
1922 | force_sig(DRBD_SIG, tconn->asender.task); | 1713 | force_sig(DRBD_SIG, connection->asender.task); |
1923 | } | 1714 | } |
1924 | 1715 | ||
1925 | static inline void request_ping(struct drbd_tconn *tconn) | 1716 | static inline void request_ping(struct drbd_connection *connection) |
1926 | { | 1717 | { |
1927 | set_bit(SEND_PING, &tconn->flags); | 1718 | set_bit(SEND_PING, &connection->flags); |
1928 | wake_asender(tconn); | 1719 | wake_asender(connection); |
1929 | } | 1720 | } |
1930 | 1721 | ||
1931 | extern void *conn_prepare_command(struct drbd_tconn *, struct drbd_socket *); | 1722 | extern void *conn_prepare_command(struct drbd_connection *, struct drbd_socket *); |
1932 | extern void *drbd_prepare_command(struct drbd_conf *, struct drbd_socket *); | 1723 | extern void *drbd_prepare_command(struct drbd_peer_device *, struct drbd_socket *); |
1933 | extern int conn_send_command(struct drbd_tconn *, struct drbd_socket *, | 1724 | extern int conn_send_command(struct drbd_connection *, struct drbd_socket *, |
1934 | enum drbd_packet, unsigned int, void *, | 1725 | enum drbd_packet, unsigned int, void *, |
1935 | unsigned int); | 1726 | unsigned int); |
1936 | extern int drbd_send_command(struct drbd_conf *, struct drbd_socket *, | 1727 | extern int drbd_send_command(struct drbd_peer_device *, struct drbd_socket *, |
1937 | enum drbd_packet, unsigned int, void *, | 1728 | enum drbd_packet, unsigned int, void *, |
1938 | unsigned int); | 1729 | unsigned int); |
1939 | 1730 | ||
1940 | extern int drbd_send_ping(struct drbd_tconn *tconn); | 1731 | extern int drbd_send_ping(struct drbd_connection *connection); |
1941 | extern int drbd_send_ping_ack(struct drbd_tconn *tconn); | 1732 | extern int drbd_send_ping_ack(struct drbd_connection *connection); |
1942 | extern int drbd_send_state_req(struct drbd_conf *, union drbd_state, union drbd_state); | 1733 | extern int drbd_send_state_req(struct drbd_peer_device *, union drbd_state, union drbd_state); |
1943 | extern int conn_send_state_req(struct drbd_tconn *, union drbd_state, union drbd_state); | 1734 | extern int conn_send_state_req(struct drbd_connection *, union drbd_state, union drbd_state); |
1944 | 1735 | ||
1945 | static inline void drbd_thread_stop(struct drbd_thread *thi) | 1736 | static inline void drbd_thread_stop(struct drbd_thread *thi) |
1946 | { | 1737 | { |
@@ -1979,22 +1770,22 @@ static inline void drbd_thread_restart_nowait(struct drbd_thread *thi) | |||
1979 | * _req_mod(req, CONNECTION_LOST_WHILE_PENDING) | 1770 | * _req_mod(req, CONNECTION_LOST_WHILE_PENDING) |
1980 | * [from tl_clear_barrier] | 1771 | * [from tl_clear_barrier] |
1981 | */ | 1772 | */ |
1982 | static inline void inc_ap_pending(struct drbd_conf *mdev) | 1773 | static inline void inc_ap_pending(struct drbd_device *device) |
1983 | { | 1774 | { |
1984 | atomic_inc(&mdev->ap_pending_cnt); | 1775 | atomic_inc(&device->ap_pending_cnt); |
1985 | } | 1776 | } |
1986 | 1777 | ||
1987 | #define ERR_IF_CNT_IS_NEGATIVE(which, func, line) \ | 1778 | #define ERR_IF_CNT_IS_NEGATIVE(which, func, line) \ |
1988 | if (atomic_read(&mdev->which) < 0) \ | 1779 | if (atomic_read(&device->which) < 0) \ |
1989 | dev_err(DEV, "in %s:%d: " #which " = %d < 0 !\n", \ | 1780 | drbd_err(device, "in %s:%d: " #which " = %d < 0 !\n", \ |
1990 | func, line, \ | 1781 | func, line, \ |
1991 | atomic_read(&mdev->which)) | 1782 | atomic_read(&device->which)) |
1992 | 1783 | ||
1993 | #define dec_ap_pending(mdev) _dec_ap_pending(mdev, __FUNCTION__, __LINE__) | 1784 | #define dec_ap_pending(device) _dec_ap_pending(device, __FUNCTION__, __LINE__) |
1994 | static inline void _dec_ap_pending(struct drbd_conf *mdev, const char *func, int line) | 1785 | static inline void _dec_ap_pending(struct drbd_device *device, const char *func, int line) |
1995 | { | 1786 | { |
1996 | if (atomic_dec_and_test(&mdev->ap_pending_cnt)) | 1787 | if (atomic_dec_and_test(&device->ap_pending_cnt)) |
1997 | wake_up(&mdev->misc_wait); | 1788 | wake_up(&device->misc_wait); |
1998 | ERR_IF_CNT_IS_NEGATIVE(ap_pending_cnt, func, line); | 1789 | ERR_IF_CNT_IS_NEGATIVE(ap_pending_cnt, func, line); |
1999 | } | 1790 | } |
2000 | 1791 | ||
@@ -2004,15 +1795,15 @@ static inline void _dec_ap_pending(struct drbd_conf *mdev, const char *func, int | |||
2004 | * C_SYNC_SOURCE sends P_RS_DATA_REPLY (and expects P_WRITE_ACK with ID_SYNCER) | 1795 | * C_SYNC_SOURCE sends P_RS_DATA_REPLY (and expects P_WRITE_ACK with ID_SYNCER) |
2005 | * (or P_NEG_ACK with ID_SYNCER) | 1796 | * (or P_NEG_ACK with ID_SYNCER) |
2006 | */ | 1797 | */ |
2007 | static inline void inc_rs_pending(struct drbd_conf *mdev) | 1798 | static inline void inc_rs_pending(struct drbd_device *device) |
2008 | { | 1799 | { |
2009 | atomic_inc(&mdev->rs_pending_cnt); | 1800 | atomic_inc(&device->rs_pending_cnt); |
2010 | } | 1801 | } |
2011 | 1802 | ||
2012 | #define dec_rs_pending(mdev) _dec_rs_pending(mdev, __FUNCTION__, __LINE__) | 1803 | #define dec_rs_pending(device) _dec_rs_pending(device, __FUNCTION__, __LINE__) |
2013 | static inline void _dec_rs_pending(struct drbd_conf *mdev, const char *func, int line) | 1804 | static inline void _dec_rs_pending(struct drbd_device *device, const char *func, int line) |
2014 | { | 1805 | { |
2015 | atomic_dec(&mdev->rs_pending_cnt); | 1806 | atomic_dec(&device->rs_pending_cnt); |
2016 | ERR_IF_CNT_IS_NEGATIVE(rs_pending_cnt, func, line); | 1807 | ERR_IF_CNT_IS_NEGATIVE(rs_pending_cnt, func, line); |
2017 | } | 1808 | } |
2018 | 1809 | ||
@@ -2025,103 +1816,104 @@ static inline void _dec_rs_pending(struct drbd_conf *mdev, const char *func, int | |||
2025 | * receive_DataRequest (receive_RSDataRequest) we need to send back P_DATA | 1816 | * receive_DataRequest (receive_RSDataRequest) we need to send back P_DATA |
2026 | * receive_Barrier_* we need to send a P_BARRIER_ACK | 1817 | * receive_Barrier_* we need to send a P_BARRIER_ACK |
2027 | */ | 1818 | */ |
2028 | static inline void inc_unacked(struct drbd_conf *mdev) | 1819 | static inline void inc_unacked(struct drbd_device *device) |
2029 | { | 1820 | { |
2030 | atomic_inc(&mdev->unacked_cnt); | 1821 | atomic_inc(&device->unacked_cnt); |
2031 | } | 1822 | } |
2032 | 1823 | ||
2033 | #define dec_unacked(mdev) _dec_unacked(mdev, __FUNCTION__, __LINE__) | 1824 | #define dec_unacked(device) _dec_unacked(device, __FUNCTION__, __LINE__) |
2034 | static inline void _dec_unacked(struct drbd_conf *mdev, const char *func, int line) | 1825 | static inline void _dec_unacked(struct drbd_device *device, const char *func, int line) |
2035 | { | 1826 | { |
2036 | atomic_dec(&mdev->unacked_cnt); | 1827 | atomic_dec(&device->unacked_cnt); |
2037 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); | 1828 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); |
2038 | } | 1829 | } |
2039 | 1830 | ||
2040 | #define sub_unacked(mdev, n) _sub_unacked(mdev, n, __FUNCTION__, __LINE__) | 1831 | #define sub_unacked(device, n) _sub_unacked(device, n, __FUNCTION__, __LINE__) |
2041 | static inline void _sub_unacked(struct drbd_conf *mdev, int n, const char *func, int line) | 1832 | static inline void _sub_unacked(struct drbd_device *device, int n, const char *func, int line) |
2042 | { | 1833 | { |
2043 | atomic_sub(n, &mdev->unacked_cnt); | 1834 | atomic_sub(n, &device->unacked_cnt); |
2044 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); | 1835 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt, func, line); |
2045 | } | 1836 | } |
2046 | 1837 | ||
2047 | /** | 1838 | /** |
2048 | * get_ldev() - Increase the ref count on mdev->ldev. Returns 0 if there is no ldev | 1839 | * get_ldev() - Increase the ref count on device->ldev. Returns 0 if there is no ldev |
2049 | * @M: DRBD device. | 1840 | * @M: DRBD device. |
2050 | * | 1841 | * |
2051 | * You have to call put_ldev() when finished working with mdev->ldev. | 1842 | * You have to call put_ldev() when finished working with device->ldev. |
2052 | */ | 1843 | */ |
2053 | #define get_ldev(M) __cond_lock(local, _get_ldev_if_state(M,D_INCONSISTENT)) | 1844 | #define get_ldev(M) __cond_lock(local, _get_ldev_if_state(M,D_INCONSISTENT)) |
2054 | #define get_ldev_if_state(M,MINS) __cond_lock(local, _get_ldev_if_state(M,MINS)) | 1845 | #define get_ldev_if_state(M,MINS) __cond_lock(local, _get_ldev_if_state(M,MINS)) |
2055 | 1846 | ||
2056 | static inline void put_ldev(struct drbd_conf *mdev) | 1847 | static inline void put_ldev(struct drbd_device *device) |
2057 | { | 1848 | { |
2058 | int i = atomic_dec_return(&mdev->local_cnt); | 1849 | int i = atomic_dec_return(&device->local_cnt); |
2059 | 1850 | ||
2060 | /* This may be called from some endio handler, | 1851 | /* This may be called from some endio handler, |
2061 | * so we must not sleep here. */ | 1852 | * so we must not sleep here. */ |
2062 | 1853 | ||
2063 | __release(local); | 1854 | __release(local); |
2064 | D_ASSERT(i >= 0); | 1855 | D_ASSERT(device, i >= 0); |
2065 | if (i == 0) { | 1856 | if (i == 0) { |
2066 | if (mdev->state.disk == D_DISKLESS) | 1857 | if (device->state.disk == D_DISKLESS) |
2067 | /* even internal references gone, safe to destroy */ | 1858 | /* even internal references gone, safe to destroy */ |
2068 | drbd_ldev_destroy(mdev); | 1859 | drbd_ldev_destroy(device); |
2069 | if (mdev->state.disk == D_FAILED) { | 1860 | if (device->state.disk == D_FAILED) { |
2070 | /* all application IO references gone. */ | 1861 | /* all application IO references gone. */ |
2071 | if (!test_and_set_bit(GO_DISKLESS, &mdev->flags)) | 1862 | if (!test_and_set_bit(GO_DISKLESS, &device->flags)) |
2072 | drbd_queue_work(&mdev->tconn->sender_work, &mdev->go_diskless); | 1863 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
1864 | &device->go_diskless); | ||
2073 | } | 1865 | } |
2074 | wake_up(&mdev->misc_wait); | 1866 | wake_up(&device->misc_wait); |
2075 | } | 1867 | } |
2076 | } | 1868 | } |
2077 | 1869 | ||
2078 | #ifndef __CHECKER__ | 1870 | #ifndef __CHECKER__ |
2079 | static inline int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins) | 1871 | static inline int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins) |
2080 | { | 1872 | { |
2081 | int io_allowed; | 1873 | int io_allowed; |
2082 | 1874 | ||
2083 | /* never get a reference while D_DISKLESS */ | 1875 | /* never get a reference while D_DISKLESS */ |
2084 | if (mdev->state.disk == D_DISKLESS) | 1876 | if (device->state.disk == D_DISKLESS) |
2085 | return 0; | 1877 | return 0; |
2086 | 1878 | ||
2087 | atomic_inc(&mdev->local_cnt); | 1879 | atomic_inc(&device->local_cnt); |
2088 | io_allowed = (mdev->state.disk >= mins); | 1880 | io_allowed = (device->state.disk >= mins); |
2089 | if (!io_allowed) | 1881 | if (!io_allowed) |
2090 | put_ldev(mdev); | 1882 | put_ldev(device); |
2091 | return io_allowed; | 1883 | return io_allowed; |
2092 | } | 1884 | } |
2093 | #else | 1885 | #else |
2094 | extern int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins); | 1886 | extern int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins); |
2095 | #endif | 1887 | #endif |
2096 | 1888 | ||
2097 | /* you must have an "get_ldev" reference */ | 1889 | /* you must have an "get_ldev" reference */ |
2098 | static inline void drbd_get_syncer_progress(struct drbd_conf *mdev, | 1890 | static inline void drbd_get_syncer_progress(struct drbd_device *device, |
2099 | unsigned long *bits_left, unsigned int *per_mil_done) | 1891 | unsigned long *bits_left, unsigned int *per_mil_done) |
2100 | { | 1892 | { |
2101 | /* this is to break it at compile time when we change that, in case we | 1893 | /* this is to break it at compile time when we change that, in case we |
2102 | * want to support more than (1<<32) bits on a 32bit arch. */ | 1894 | * want to support more than (1<<32) bits on a 32bit arch. */ |
2103 | typecheck(unsigned long, mdev->rs_total); | 1895 | typecheck(unsigned long, device->rs_total); |
2104 | 1896 | ||
2105 | /* note: both rs_total and rs_left are in bits, i.e. in | 1897 | /* note: both rs_total and rs_left are in bits, i.e. in |
2106 | * units of BM_BLOCK_SIZE. | 1898 | * units of BM_BLOCK_SIZE. |
2107 | * for the percentage, we don't care. */ | 1899 | * for the percentage, we don't care. */ |
2108 | 1900 | ||
2109 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) | 1901 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
2110 | *bits_left = mdev->ov_left; | 1902 | *bits_left = device->ov_left; |
2111 | else | 1903 | else |
2112 | *bits_left = drbd_bm_total_weight(mdev) - mdev->rs_failed; | 1904 | *bits_left = drbd_bm_total_weight(device) - device->rs_failed; |
2113 | /* >> 10 to prevent overflow, | 1905 | /* >> 10 to prevent overflow, |
2114 | * +1 to prevent division by zero */ | 1906 | * +1 to prevent division by zero */ |
2115 | if (*bits_left > mdev->rs_total) { | 1907 | if (*bits_left > device->rs_total) { |
2116 | /* doh. maybe a logic bug somewhere. | 1908 | /* doh. maybe a logic bug somewhere. |
2117 | * may also be just a race condition | 1909 | * may also be just a race condition |
2118 | * between this and a disconnect during sync. | 1910 | * between this and a disconnect during sync. |
2119 | * for now, just prevent in-kernel buffer overflow. | 1911 | * for now, just prevent in-kernel buffer overflow. |
2120 | */ | 1912 | */ |
2121 | smp_rmb(); | 1913 | smp_rmb(); |
2122 | dev_warn(DEV, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n", | 1914 | drbd_warn(device, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n", |
2123 | drbd_conn_str(mdev->state.conn), | 1915 | drbd_conn_str(device->state.conn), |
2124 | *bits_left, mdev->rs_total, mdev->rs_failed); | 1916 | *bits_left, device->rs_total, device->rs_failed); |
2125 | *per_mil_done = 0; | 1917 | *per_mil_done = 0; |
2126 | } else { | 1918 | } else { |
2127 | /* Make sure the division happens in long context. | 1919 | /* Make sure the division happens in long context. |
@@ -2133,9 +1925,9 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev, | |||
2133 | * Note: currently we don't support such large bitmaps on 32bit | 1925 | * Note: currently we don't support such large bitmaps on 32bit |
2134 | * arch anyways, but no harm done to be prepared for it here. | 1926 | * arch anyways, but no harm done to be prepared for it here. |
2135 | */ | 1927 | */ |
2136 | unsigned int shift = mdev->rs_total > UINT_MAX ? 16 : 10; | 1928 | unsigned int shift = device->rs_total > UINT_MAX ? 16 : 10; |
2137 | unsigned long left = *bits_left >> shift; | 1929 | unsigned long left = *bits_left >> shift; |
2138 | unsigned long total = 1UL + (mdev->rs_total >> shift); | 1930 | unsigned long total = 1UL + (device->rs_total >> shift); |
2139 | unsigned long tmp = 1000UL - left * 1000UL/total; | 1931 | unsigned long tmp = 1000UL - left * 1000UL/total; |
2140 | *per_mil_done = tmp; | 1932 | *per_mil_done = tmp; |
2141 | } | 1933 | } |
@@ -2145,22 +1937,22 @@ static inline void drbd_get_syncer_progress(struct drbd_conf *mdev, | |||
2145 | /* this throttles on-the-fly application requests | 1937 | /* this throttles on-the-fly application requests |
2146 | * according to max_buffers settings; | 1938 | * according to max_buffers settings; |
2147 | * maybe re-implement using semaphores? */ | 1939 | * maybe re-implement using semaphores? */ |
2148 | static inline int drbd_get_max_buffers(struct drbd_conf *mdev) | 1940 | static inline int drbd_get_max_buffers(struct drbd_device *device) |
2149 | { | 1941 | { |
2150 | struct net_conf *nc; | 1942 | struct net_conf *nc; |
2151 | int mxb; | 1943 | int mxb; |
2152 | 1944 | ||
2153 | rcu_read_lock(); | 1945 | rcu_read_lock(); |
2154 | nc = rcu_dereference(mdev->tconn->net_conf); | 1946 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
2155 | mxb = nc ? nc->max_buffers : 1000000; /* arbitrary limit on open requests */ | 1947 | mxb = nc ? nc->max_buffers : 1000000; /* arbitrary limit on open requests */ |
2156 | rcu_read_unlock(); | 1948 | rcu_read_unlock(); |
2157 | 1949 | ||
2158 | return mxb; | 1950 | return mxb; |
2159 | } | 1951 | } |
2160 | 1952 | ||
2161 | static inline int drbd_state_is_stable(struct drbd_conf *mdev) | 1953 | static inline int drbd_state_is_stable(struct drbd_device *device) |
2162 | { | 1954 | { |
2163 | union drbd_dev_state s = mdev->state; | 1955 | union drbd_dev_state s = device->state; |
2164 | 1956 | ||
2165 | /* DO NOT add a default clause, we want the compiler to warn us | 1957 | /* DO NOT add a default clause, we want the compiler to warn us |
2166 | * for any newly introduced state we may have forgotten to add here */ | 1958 | * for any newly introduced state we may have forgotten to add here */ |
@@ -2194,7 +1986,7 @@ static inline int drbd_state_is_stable(struct drbd_conf *mdev) | |||
2194 | 1986 | ||
2195 | /* Allow IO in BM exchange states with new protocols */ | 1987 | /* Allow IO in BM exchange states with new protocols */ |
2196 | case C_WF_BITMAP_S: | 1988 | case C_WF_BITMAP_S: |
2197 | if (mdev->tconn->agreed_pro_version < 96) | 1989 | if (first_peer_device(device)->connection->agreed_pro_version < 96) |
2198 | return 0; | 1990 | return 0; |
2199 | break; | 1991 | break; |
2200 | 1992 | ||
@@ -2228,20 +2020,20 @@ static inline int drbd_state_is_stable(struct drbd_conf *mdev) | |||
2228 | return 1; | 2020 | return 1; |
2229 | } | 2021 | } |
2230 | 2022 | ||
2231 | static inline int drbd_suspended(struct drbd_conf *mdev) | 2023 | static inline int drbd_suspended(struct drbd_device *device) |
2232 | { | 2024 | { |
2233 | struct drbd_tconn *tconn = mdev->tconn; | 2025 | struct drbd_resource *resource = device->resource; |
2234 | 2026 | ||
2235 | return tconn->susp || tconn->susp_fen || tconn->susp_nod; | 2027 | return resource->susp || resource->susp_fen || resource->susp_nod; |
2236 | } | 2028 | } |
2237 | 2029 | ||
2238 | static inline bool may_inc_ap_bio(struct drbd_conf *mdev) | 2030 | static inline bool may_inc_ap_bio(struct drbd_device *device) |
2239 | { | 2031 | { |
2240 | int mxb = drbd_get_max_buffers(mdev); | 2032 | int mxb = drbd_get_max_buffers(device); |
2241 | 2033 | ||
2242 | if (drbd_suspended(mdev)) | 2034 | if (drbd_suspended(device)) |
2243 | return false; | 2035 | return false; |
2244 | if (test_bit(SUSPEND_IO, &mdev->flags)) | 2036 | if (test_bit(SUSPEND_IO, &device->flags)) |
2245 | return false; | 2037 | return false; |
2246 | 2038 | ||
2247 | /* to avoid potential deadlock or bitmap corruption, | 2039 | /* to avoid potential deadlock or bitmap corruption, |
@@ -2249,32 +2041,32 @@ static inline bool may_inc_ap_bio(struct drbd_conf *mdev) | |||
2249 | * to start during "stable" states. */ | 2041 | * to start during "stable" states. */ |
2250 | 2042 | ||
2251 | /* no new io accepted when attaching or detaching the disk */ | 2043 | /* no new io accepted when attaching or detaching the disk */ |
2252 | if (!drbd_state_is_stable(mdev)) | 2044 | if (!drbd_state_is_stable(device)) |
2253 | return false; | 2045 | return false; |
2254 | 2046 | ||
2255 | /* since some older kernels don't have atomic_add_unless, | 2047 | /* since some older kernels don't have atomic_add_unless, |
2256 | * and we are within the spinlock anyways, we have this workaround. */ | 2048 | * and we are within the spinlock anyways, we have this workaround. */ |
2257 | if (atomic_read(&mdev->ap_bio_cnt) > mxb) | 2049 | if (atomic_read(&device->ap_bio_cnt) > mxb) |
2258 | return false; | 2050 | return false; |
2259 | if (test_bit(BITMAP_IO, &mdev->flags)) | 2051 | if (test_bit(BITMAP_IO, &device->flags)) |
2260 | return false; | 2052 | return false; |
2261 | return true; | 2053 | return true; |
2262 | } | 2054 | } |
2263 | 2055 | ||
2264 | static inline bool inc_ap_bio_cond(struct drbd_conf *mdev) | 2056 | static inline bool inc_ap_bio_cond(struct drbd_device *device) |
2265 | { | 2057 | { |
2266 | bool rv = false; | 2058 | bool rv = false; |
2267 | 2059 | ||
2268 | spin_lock_irq(&mdev->tconn->req_lock); | 2060 | spin_lock_irq(&device->resource->req_lock); |
2269 | rv = may_inc_ap_bio(mdev); | 2061 | rv = may_inc_ap_bio(device); |
2270 | if (rv) | 2062 | if (rv) |
2271 | atomic_inc(&mdev->ap_bio_cnt); | 2063 | atomic_inc(&device->ap_bio_cnt); |
2272 | spin_unlock_irq(&mdev->tconn->req_lock); | 2064 | spin_unlock_irq(&device->resource->req_lock); |
2273 | 2065 | ||
2274 | return rv; | 2066 | return rv; |
2275 | } | 2067 | } |
2276 | 2068 | ||
2277 | static inline void inc_ap_bio(struct drbd_conf *mdev) | 2069 | static inline void inc_ap_bio(struct drbd_device *device) |
2278 | { | 2070 | { |
2279 | /* we wait here | 2071 | /* we wait here |
2280 | * as long as the device is suspended | 2072 | * as long as the device is suspended |
@@ -2284,42 +2076,44 @@ static inline void inc_ap_bio(struct drbd_conf *mdev) | |||
2284 | * to avoid races with the reconnect code, | 2076 | * to avoid races with the reconnect code, |
2285 | * we need to atomic_inc within the spinlock. */ | 2077 | * we need to atomic_inc within the spinlock. */ |
2286 | 2078 | ||
2287 | wait_event(mdev->misc_wait, inc_ap_bio_cond(mdev)); | 2079 | wait_event(device->misc_wait, inc_ap_bio_cond(device)); |
2288 | } | 2080 | } |
2289 | 2081 | ||
2290 | static inline void dec_ap_bio(struct drbd_conf *mdev) | 2082 | static inline void dec_ap_bio(struct drbd_device *device) |
2291 | { | 2083 | { |
2292 | int mxb = drbd_get_max_buffers(mdev); | 2084 | int mxb = drbd_get_max_buffers(device); |
2293 | int ap_bio = atomic_dec_return(&mdev->ap_bio_cnt); | 2085 | int ap_bio = atomic_dec_return(&device->ap_bio_cnt); |
2294 | 2086 | ||
2295 | D_ASSERT(ap_bio >= 0); | 2087 | D_ASSERT(device, ap_bio >= 0); |
2296 | 2088 | ||
2297 | if (ap_bio == 0 && test_bit(BITMAP_IO, &mdev->flags)) { | 2089 | if (ap_bio == 0 && test_bit(BITMAP_IO, &device->flags)) { |
2298 | if (!test_and_set_bit(BITMAP_IO_QUEUED, &mdev->flags)) | 2090 | if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags)) |
2299 | drbd_queue_work(&mdev->tconn->sender_work, &mdev->bm_io_work.w); | 2091 | drbd_queue_work(&first_peer_device(device)-> |
2092 | connection->sender_work, | ||
2093 | &device->bm_io_work.w); | ||
2300 | } | 2094 | } |
2301 | 2095 | ||
2302 | /* this currently does wake_up for every dec_ap_bio! | 2096 | /* this currently does wake_up for every dec_ap_bio! |
2303 | * maybe rather introduce some type of hysteresis? | 2097 | * maybe rather introduce some type of hysteresis? |
2304 | * e.g. (ap_bio == mxb/2 || ap_bio == 0) ? */ | 2098 | * e.g. (ap_bio == mxb/2 || ap_bio == 0) ? */ |
2305 | if (ap_bio < mxb) | 2099 | if (ap_bio < mxb) |
2306 | wake_up(&mdev->misc_wait); | 2100 | wake_up(&device->misc_wait); |
2307 | } | 2101 | } |
2308 | 2102 | ||
2309 | static inline bool verify_can_do_stop_sector(struct drbd_conf *mdev) | 2103 | static inline bool verify_can_do_stop_sector(struct drbd_device *device) |
2310 | { | 2104 | { |
2311 | return mdev->tconn->agreed_pro_version >= 97 && | 2105 | return first_peer_device(device)->connection->agreed_pro_version >= 97 && |
2312 | mdev->tconn->agreed_pro_version != 100; | 2106 | first_peer_device(device)->connection->agreed_pro_version != 100; |
2313 | } | 2107 | } |
2314 | 2108 | ||
2315 | static inline int drbd_set_ed_uuid(struct drbd_conf *mdev, u64 val) | 2109 | static inline int drbd_set_ed_uuid(struct drbd_device *device, u64 val) |
2316 | { | 2110 | { |
2317 | int changed = mdev->ed_uuid != val; | 2111 | int changed = device->ed_uuid != val; |
2318 | mdev->ed_uuid = val; | 2112 | device->ed_uuid = val; |
2319 | return changed; | 2113 | return changed; |
2320 | } | 2114 | } |
2321 | 2115 | ||
2322 | static inline int drbd_queue_order_type(struct drbd_conf *mdev) | 2116 | static inline int drbd_queue_order_type(struct drbd_device *device) |
2323 | { | 2117 | { |
2324 | /* sorry, we currently have no working implementation | 2118 | /* sorry, we currently have no working implementation |
2325 | * of distributed TCQ stuff */ | 2119 | * of distributed TCQ stuff */ |
@@ -2329,23 +2123,29 @@ static inline int drbd_queue_order_type(struct drbd_conf *mdev) | |||
2329 | return QUEUE_ORDERED_NONE; | 2123 | return QUEUE_ORDERED_NONE; |
2330 | } | 2124 | } |
2331 | 2125 | ||
2332 | static inline void drbd_md_flush(struct drbd_conf *mdev) | 2126 | static inline void drbd_md_flush(struct drbd_device *device) |
2333 | { | 2127 | { |
2334 | int r; | 2128 | int r; |
2335 | 2129 | ||
2336 | if (mdev->ldev == NULL) { | 2130 | if (device->ldev == NULL) { |
2337 | dev_warn(DEV, "mdev->ldev == NULL in drbd_md_flush\n"); | 2131 | drbd_warn(device, "device->ldev == NULL in drbd_md_flush\n"); |
2338 | return; | 2132 | return; |
2339 | } | 2133 | } |
2340 | 2134 | ||
2341 | if (test_bit(MD_NO_FUA, &mdev->flags)) | 2135 | if (test_bit(MD_NO_FUA, &device->flags)) |
2342 | return; | 2136 | return; |
2343 | 2137 | ||
2344 | r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_NOIO, NULL); | 2138 | r = blkdev_issue_flush(device->ldev->md_bdev, GFP_NOIO, NULL); |
2345 | if (r) { | 2139 | if (r) { |
2346 | set_bit(MD_NO_FUA, &mdev->flags); | 2140 | set_bit(MD_NO_FUA, &device->flags); |
2347 | dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r); | 2141 | drbd_err(device, "meta data flush failed with status %d, disabling md-flushes\n", r); |
2348 | } | 2142 | } |
2349 | } | 2143 | } |
2350 | 2144 | ||
2145 | static inline struct drbd_connection *first_connection(struct drbd_resource *resource) | ||
2146 | { | ||
2147 | return list_first_entry(&resource->connections, | ||
2148 | struct drbd_connection, connections); | ||
2149 | } | ||
2150 | |||
2351 | #endif | 2151 | #endif |
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 929468e1512a..331e5cc1227d 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c | |||
@@ -52,16 +52,12 @@ | |||
52 | 52 | ||
53 | #include <linux/drbd_limits.h> | 53 | #include <linux/drbd_limits.h> |
54 | #include "drbd_int.h" | 54 | #include "drbd_int.h" |
55 | #include "drbd_protocol.h" | ||
55 | #include "drbd_req.h" /* only for _req_mod in tl_release and tl_clear */ | 56 | #include "drbd_req.h" /* only for _req_mod in tl_release and tl_clear */ |
56 | 57 | ||
57 | #include "drbd_vli.h" | 58 | #include "drbd_vli.h" |
58 | 59 | ||
59 | static DEFINE_MUTEX(drbd_main_mutex); | 60 | static DEFINE_MUTEX(drbd_main_mutex); |
60 | int drbdd_init(struct drbd_thread *); | ||
61 | int drbd_worker(struct drbd_thread *); | ||
62 | int drbd_asender(struct drbd_thread *); | ||
63 | |||
64 | int drbd_init(void); | ||
65 | static int drbd_open(struct block_device *bdev, fmode_t mode); | 61 | static int drbd_open(struct block_device *bdev, fmode_t mode); |
66 | static void drbd_release(struct gendisk *gd, fmode_t mode); | 62 | static void drbd_release(struct gendisk *gd, fmode_t mode); |
67 | static int w_md_sync(struct drbd_work *w, int unused); | 63 | static int w_md_sync(struct drbd_work *w, int unused); |
@@ -118,8 +114,8 @@ module_param_string(usermode_helper, usermode_helper, sizeof(usermode_helper), 0 | |||
118 | /* in 2.6.x, our device mapping and config info contains our virtual gendisks | 114 | /* in 2.6.x, our device mapping and config info contains our virtual gendisks |
119 | * as member "struct gendisk *vdisk;" | 115 | * as member "struct gendisk *vdisk;" |
120 | */ | 116 | */ |
121 | struct idr minors; | 117 | struct idr drbd_devices; |
122 | struct list_head drbd_tconns; /* list of struct drbd_tconn */ | 118 | struct list_head drbd_resources; |
123 | 119 | ||
124 | struct kmem_cache *drbd_request_cache; | 120 | struct kmem_cache *drbd_request_cache; |
125 | struct kmem_cache *drbd_ee_cache; /* peer requests */ | 121 | struct kmem_cache *drbd_ee_cache; /* peer requests */ |
@@ -166,15 +162,15 @@ struct bio *bio_alloc_drbd(gfp_t gfp_mask) | |||
166 | /* When checking with sparse, and this is an inline function, sparse will | 162 | /* When checking with sparse, and this is an inline function, sparse will |
167 | give tons of false positives. When this is a real functions sparse works. | 163 | give tons of false positives. When this is a real functions sparse works. |
168 | */ | 164 | */ |
169 | int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins) | 165 | int _get_ldev_if_state(struct drbd_device *device, enum drbd_disk_state mins) |
170 | { | 166 | { |
171 | int io_allowed; | 167 | int io_allowed; |
172 | 168 | ||
173 | atomic_inc(&mdev->local_cnt); | 169 | atomic_inc(&device->local_cnt); |
174 | io_allowed = (mdev->state.disk >= mins); | 170 | io_allowed = (device->state.disk >= mins); |
175 | if (!io_allowed) { | 171 | if (!io_allowed) { |
176 | if (atomic_dec_and_test(&mdev->local_cnt)) | 172 | if (atomic_dec_and_test(&device->local_cnt)) |
177 | wake_up(&mdev->misc_wait); | 173 | wake_up(&device->misc_wait); |
178 | } | 174 | } |
179 | return io_allowed; | 175 | return io_allowed; |
180 | } | 176 | } |
@@ -183,7 +179,7 @@ int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins) | |||
183 | 179 | ||
184 | /** | 180 | /** |
185 | * tl_release() - mark as BARRIER_ACKED all requests in the corresponding transfer log epoch | 181 | * tl_release() - mark as BARRIER_ACKED all requests in the corresponding transfer log epoch |
186 | * @tconn: DRBD connection. | 182 | * @connection: DRBD connection. |
187 | * @barrier_nr: Expected identifier of the DRBD write barrier packet. | 183 | * @barrier_nr: Expected identifier of the DRBD write barrier packet. |
188 | * @set_size: Expected number of requests before that barrier. | 184 | * @set_size: Expected number of requests before that barrier. |
189 | * | 185 | * |
@@ -191,7 +187,7 @@ int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins) | |||
191 | * epoch of not yet barrier-acked requests, this function will cause a | 187 | * epoch of not yet barrier-acked requests, this function will cause a |
192 | * termination of the connection. | 188 | * termination of the connection. |
193 | */ | 189 | */ |
194 | void tl_release(struct drbd_tconn *tconn, unsigned int barrier_nr, | 190 | void tl_release(struct drbd_connection *connection, unsigned int barrier_nr, |
195 | unsigned int set_size) | 191 | unsigned int set_size) |
196 | { | 192 | { |
197 | struct drbd_request *r; | 193 | struct drbd_request *r; |
@@ -199,11 +195,11 @@ void tl_release(struct drbd_tconn *tconn, unsigned int barrier_nr, | |||
199 | int expect_epoch = 0; | 195 | int expect_epoch = 0; |
200 | int expect_size = 0; | 196 | int expect_size = 0; |
201 | 197 | ||
202 | spin_lock_irq(&tconn->req_lock); | 198 | spin_lock_irq(&connection->resource->req_lock); |
203 | 199 | ||
204 | /* find oldest not yet barrier-acked write request, | 200 | /* find oldest not yet barrier-acked write request, |
205 | * count writes in its epoch. */ | 201 | * count writes in its epoch. */ |
206 | list_for_each_entry(r, &tconn->transfer_log, tl_requests) { | 202 | list_for_each_entry(r, &connection->transfer_log, tl_requests) { |
207 | const unsigned s = r->rq_state; | 203 | const unsigned s = r->rq_state; |
208 | if (!req) { | 204 | if (!req) { |
209 | if (!(s & RQ_WRITE)) | 205 | if (!(s & RQ_WRITE)) |
@@ -228,18 +224,18 @@ void tl_release(struct drbd_tconn *tconn, unsigned int barrier_nr, | |||
228 | 224 | ||
229 | /* first some paranoia code */ | 225 | /* first some paranoia code */ |
230 | if (req == NULL) { | 226 | if (req == NULL) { |
231 | conn_err(tconn, "BAD! BarrierAck #%u received, but no epoch in tl!?\n", | 227 | drbd_err(connection, "BAD! BarrierAck #%u received, but no epoch in tl!?\n", |
232 | barrier_nr); | 228 | barrier_nr); |
233 | goto bail; | 229 | goto bail; |
234 | } | 230 | } |
235 | if (expect_epoch != barrier_nr) { | 231 | if (expect_epoch != barrier_nr) { |
236 | conn_err(tconn, "BAD! BarrierAck #%u received, expected #%u!\n", | 232 | drbd_err(connection, "BAD! BarrierAck #%u received, expected #%u!\n", |
237 | barrier_nr, expect_epoch); | 233 | barrier_nr, expect_epoch); |
238 | goto bail; | 234 | goto bail; |
239 | } | 235 | } |
240 | 236 | ||
241 | if (expect_size != set_size) { | 237 | if (expect_size != set_size) { |
242 | conn_err(tconn, "BAD! BarrierAck #%u received with n_writes=%u, expected n_writes=%u!\n", | 238 | drbd_err(connection, "BAD! BarrierAck #%u received with n_writes=%u, expected n_writes=%u!\n", |
243 | barrier_nr, set_size, expect_size); | 239 | barrier_nr, set_size, expect_size); |
244 | goto bail; | 240 | goto bail; |
245 | } | 241 | } |
@@ -248,90 +244,91 @@ void tl_release(struct drbd_tconn *tconn, unsigned int barrier_nr, | |||
248 | /* this extra list walk restart is paranoia, | 244 | /* this extra list walk restart is paranoia, |
249 | * to catch requests being barrier-acked "unexpectedly". | 245 | * to catch requests being barrier-acked "unexpectedly". |
250 | * It usually should find the same req again, or some READ preceding it. */ | 246 | * It usually should find the same req again, or some READ preceding it. */ |
251 | list_for_each_entry(req, &tconn->transfer_log, tl_requests) | 247 | list_for_each_entry(req, &connection->transfer_log, tl_requests) |
252 | if (req->epoch == expect_epoch) | 248 | if (req->epoch == expect_epoch) |
253 | break; | 249 | break; |
254 | list_for_each_entry_safe_from(req, r, &tconn->transfer_log, tl_requests) { | 250 | list_for_each_entry_safe_from(req, r, &connection->transfer_log, tl_requests) { |
255 | if (req->epoch != expect_epoch) | 251 | if (req->epoch != expect_epoch) |
256 | break; | 252 | break; |
257 | _req_mod(req, BARRIER_ACKED); | 253 | _req_mod(req, BARRIER_ACKED); |
258 | } | 254 | } |
259 | spin_unlock_irq(&tconn->req_lock); | 255 | spin_unlock_irq(&connection->resource->req_lock); |
260 | 256 | ||
261 | return; | 257 | return; |
262 | 258 | ||
263 | bail: | 259 | bail: |
264 | spin_unlock_irq(&tconn->req_lock); | 260 | spin_unlock_irq(&connection->resource->req_lock); |
265 | conn_request_state(tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); | 261 | conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
266 | } | 262 | } |
267 | 263 | ||
268 | 264 | ||
269 | /** | 265 | /** |
270 | * _tl_restart() - Walks the transfer log, and applies an action to all requests | 266 | * _tl_restart() - Walks the transfer log, and applies an action to all requests |
271 | * @mdev: DRBD device. | 267 | * @device: DRBD device. |
272 | * @what: The action/event to perform with all request objects | 268 | * @what: The action/event to perform with all request objects |
273 | * | 269 | * |
274 | * @what might be one of CONNECTION_LOST_WHILE_PENDING, RESEND, FAIL_FROZEN_DISK_IO, | 270 | * @what might be one of CONNECTION_LOST_WHILE_PENDING, RESEND, FAIL_FROZEN_DISK_IO, |
275 | * RESTART_FROZEN_DISK_IO. | 271 | * RESTART_FROZEN_DISK_IO. |
276 | */ | 272 | */ |
277 | /* must hold resource->req_lock */ | 273 | /* must hold resource->req_lock */ |
278 | void _tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what) | 274 | void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what) |
279 | { | 275 | { |
280 | struct drbd_request *req, *r; | 276 | struct drbd_request *req, *r; |
281 | 277 | ||
282 | list_for_each_entry_safe(req, r, &tconn->transfer_log, tl_requests) | 278 | list_for_each_entry_safe(req, r, &connection->transfer_log, tl_requests) |
283 | _req_mod(req, what); | 279 | _req_mod(req, what); |
284 | } | 280 | } |
285 | 281 | ||
286 | void tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what) | 282 | void tl_restart(struct drbd_connection *connection, enum drbd_req_event what) |
287 | { | 283 | { |
288 | spin_lock_irq(&tconn->req_lock); | 284 | spin_lock_irq(&connection->resource->req_lock); |
289 | _tl_restart(tconn, what); | 285 | _tl_restart(connection, what); |
290 | spin_unlock_irq(&tconn->req_lock); | 286 | spin_unlock_irq(&connection->resource->req_lock); |
291 | } | 287 | } |
292 | 288 | ||
293 | /** | 289 | /** |
294 | * tl_clear() - Clears all requests and &struct drbd_tl_epoch objects out of the TL | 290 | * tl_clear() - Clears all requests and &struct drbd_tl_epoch objects out of the TL |
295 | * @mdev: DRBD device. | 291 | * @device: DRBD device. |
296 | * | 292 | * |
297 | * This is called after the connection to the peer was lost. The storage covered | 293 | * This is called after the connection to the peer was lost. The storage covered |
298 | * by the requests on the transfer gets marked as our of sync. Called from the | 294 | * by the requests on the transfer gets marked as our of sync. Called from the |
299 | * receiver thread and the worker thread. | 295 | * receiver thread and the worker thread. |
300 | */ | 296 | */ |
301 | void tl_clear(struct drbd_tconn *tconn) | 297 | void tl_clear(struct drbd_connection *connection) |
302 | { | 298 | { |
303 | tl_restart(tconn, CONNECTION_LOST_WHILE_PENDING); | 299 | tl_restart(connection, CONNECTION_LOST_WHILE_PENDING); |
304 | } | 300 | } |
305 | 301 | ||
306 | /** | 302 | /** |
307 | * tl_abort_disk_io() - Abort disk I/O for all requests for a certain mdev in the TL | 303 | * tl_abort_disk_io() - Abort disk I/O for all requests for a certain device in the TL |
308 | * @mdev: DRBD device. | 304 | * @device: DRBD device. |
309 | */ | 305 | */ |
310 | void tl_abort_disk_io(struct drbd_conf *mdev) | 306 | void tl_abort_disk_io(struct drbd_device *device) |
311 | { | 307 | { |
312 | struct drbd_tconn *tconn = mdev->tconn; | 308 | struct drbd_connection *connection = first_peer_device(device)->connection; |
313 | struct drbd_request *req, *r; | 309 | struct drbd_request *req, *r; |
314 | 310 | ||
315 | spin_lock_irq(&tconn->req_lock); | 311 | spin_lock_irq(&connection->resource->req_lock); |
316 | list_for_each_entry_safe(req, r, &tconn->transfer_log, tl_requests) { | 312 | list_for_each_entry_safe(req, r, &connection->transfer_log, tl_requests) { |
317 | if (!(req->rq_state & RQ_LOCAL_PENDING)) | 313 | if (!(req->rq_state & RQ_LOCAL_PENDING)) |
318 | continue; | 314 | continue; |
319 | if (req->w.mdev != mdev) | 315 | if (req->device != device) |
320 | continue; | 316 | continue; |
321 | _req_mod(req, ABORT_DISK_IO); | 317 | _req_mod(req, ABORT_DISK_IO); |
322 | } | 318 | } |
323 | spin_unlock_irq(&tconn->req_lock); | 319 | spin_unlock_irq(&connection->resource->req_lock); |
324 | } | 320 | } |
325 | 321 | ||
326 | static int drbd_thread_setup(void *arg) | 322 | static int drbd_thread_setup(void *arg) |
327 | { | 323 | { |
328 | struct drbd_thread *thi = (struct drbd_thread *) arg; | 324 | struct drbd_thread *thi = (struct drbd_thread *) arg; |
329 | struct drbd_tconn *tconn = thi->tconn; | 325 | struct drbd_resource *resource = thi->resource; |
330 | unsigned long flags; | 326 | unsigned long flags; |
331 | int retval; | 327 | int retval; |
332 | 328 | ||
333 | snprintf(current->comm, sizeof(current->comm), "drbd_%c_%s", | 329 | snprintf(current->comm, sizeof(current->comm), "drbd_%c_%s", |
334 | thi->name[0], thi->tconn->name); | 330 | thi->name[0], |
331 | resource->name); | ||
335 | 332 | ||
336 | restart: | 333 | restart: |
337 | retval = thi->function(thi); | 334 | retval = thi->function(thi); |
@@ -349,7 +346,7 @@ restart: | |||
349 | */ | 346 | */ |
350 | 347 | ||
351 | if (thi->t_state == RESTARTING) { | 348 | if (thi->t_state == RESTARTING) { |
352 | conn_info(tconn, "Restarting %s thread\n", thi->name); | 349 | drbd_info(resource, "Restarting %s thread\n", thi->name); |
353 | thi->t_state = RUNNING; | 350 | thi->t_state = RUNNING; |
354 | spin_unlock_irqrestore(&thi->t_lock, flags); | 351 | spin_unlock_irqrestore(&thi->t_lock, flags); |
355 | goto restart; | 352 | goto restart; |
@@ -361,29 +358,32 @@ restart: | |||
361 | complete_all(&thi->stop); | 358 | complete_all(&thi->stop); |
362 | spin_unlock_irqrestore(&thi->t_lock, flags); | 359 | spin_unlock_irqrestore(&thi->t_lock, flags); |
363 | 360 | ||
364 | conn_info(tconn, "Terminating %s\n", current->comm); | 361 | drbd_info(resource, "Terminating %s\n", current->comm); |
365 | 362 | ||
366 | /* Release mod reference taken when thread was started */ | 363 | /* Release mod reference taken when thread was started */ |
367 | 364 | ||
368 | kref_put(&tconn->kref, &conn_destroy); | 365 | if (thi->connection) |
366 | kref_put(&thi->connection->kref, drbd_destroy_connection); | ||
367 | kref_put(&resource->kref, drbd_destroy_resource); | ||
369 | module_put(THIS_MODULE); | 368 | module_put(THIS_MODULE); |
370 | return retval; | 369 | return retval; |
371 | } | 370 | } |
372 | 371 | ||
373 | static void drbd_thread_init(struct drbd_tconn *tconn, struct drbd_thread *thi, | 372 | static void drbd_thread_init(struct drbd_resource *resource, struct drbd_thread *thi, |
374 | int (*func) (struct drbd_thread *), char *name) | 373 | int (*func) (struct drbd_thread *), const char *name) |
375 | { | 374 | { |
376 | spin_lock_init(&thi->t_lock); | 375 | spin_lock_init(&thi->t_lock); |
377 | thi->task = NULL; | 376 | thi->task = NULL; |
378 | thi->t_state = NONE; | 377 | thi->t_state = NONE; |
379 | thi->function = func; | 378 | thi->function = func; |
380 | thi->tconn = tconn; | 379 | thi->resource = resource; |
381 | strncpy(thi->name, name, ARRAY_SIZE(thi->name)); | 380 | thi->connection = NULL; |
381 | thi->name = name; | ||
382 | } | 382 | } |
383 | 383 | ||
384 | int drbd_thread_start(struct drbd_thread *thi) | 384 | int drbd_thread_start(struct drbd_thread *thi) |
385 | { | 385 | { |
386 | struct drbd_tconn *tconn = thi->tconn; | 386 | struct drbd_resource *resource = thi->resource; |
387 | struct task_struct *nt; | 387 | struct task_struct *nt; |
388 | unsigned long flags; | 388 | unsigned long flags; |
389 | 389 | ||
@@ -393,17 +393,19 @@ int drbd_thread_start(struct drbd_thread *thi) | |||
393 | 393 | ||
394 | switch (thi->t_state) { | 394 | switch (thi->t_state) { |
395 | case NONE: | 395 | case NONE: |
396 | conn_info(tconn, "Starting %s thread (from %s [%d])\n", | 396 | drbd_info(resource, "Starting %s thread (from %s [%d])\n", |
397 | thi->name, current->comm, current->pid); | 397 | thi->name, current->comm, current->pid); |
398 | 398 | ||
399 | /* Get ref on module for thread - this is released when thread exits */ | 399 | /* Get ref on module for thread - this is released when thread exits */ |
400 | if (!try_module_get(THIS_MODULE)) { | 400 | if (!try_module_get(THIS_MODULE)) { |
401 | conn_err(tconn, "Failed to get module reference in drbd_thread_start\n"); | 401 | drbd_err(resource, "Failed to get module reference in drbd_thread_start\n"); |
402 | spin_unlock_irqrestore(&thi->t_lock, flags); | 402 | spin_unlock_irqrestore(&thi->t_lock, flags); |
403 | return false; | 403 | return false; |
404 | } | 404 | } |
405 | 405 | ||
406 | kref_get(&thi->tconn->kref); | 406 | kref_get(&resource->kref); |
407 | if (thi->connection) | ||
408 | kref_get(&thi->connection->kref); | ||
407 | 409 | ||
408 | init_completion(&thi->stop); | 410 | init_completion(&thi->stop); |
409 | thi->reset_cpu_mask = 1; | 411 | thi->reset_cpu_mask = 1; |
@@ -412,12 +414,14 @@ int drbd_thread_start(struct drbd_thread *thi) | |||
412 | flush_signals(current); /* otherw. may get -ERESTARTNOINTR */ | 414 | flush_signals(current); /* otherw. may get -ERESTARTNOINTR */ |
413 | 415 | ||
414 | nt = kthread_create(drbd_thread_setup, (void *) thi, | 416 | nt = kthread_create(drbd_thread_setup, (void *) thi, |
415 | "drbd_%c_%s", thi->name[0], thi->tconn->name); | 417 | "drbd_%c_%s", thi->name[0], thi->resource->name); |
416 | 418 | ||
417 | if (IS_ERR(nt)) { | 419 | if (IS_ERR(nt)) { |
418 | conn_err(tconn, "Couldn't start thread\n"); | 420 | drbd_err(resource, "Couldn't start thread\n"); |
419 | 421 | ||
420 | kref_put(&tconn->kref, &conn_destroy); | 422 | if (thi->connection) |
423 | kref_put(&thi->connection->kref, drbd_destroy_connection); | ||
424 | kref_put(&resource->kref, drbd_destroy_resource); | ||
421 | module_put(THIS_MODULE); | 425 | module_put(THIS_MODULE); |
422 | return false; | 426 | return false; |
423 | } | 427 | } |
@@ -429,7 +433,7 @@ int drbd_thread_start(struct drbd_thread *thi) | |||
429 | break; | 433 | break; |
430 | case EXITING: | 434 | case EXITING: |
431 | thi->t_state = RESTARTING; | 435 | thi->t_state = RESTARTING; |
432 | conn_info(tconn, "Restarting %s thread (from %s [%d])\n", | 436 | drbd_info(resource, "Restarting %s thread (from %s [%d])\n", |
433 | thi->name, current->comm, current->pid); | 437 | thi->name, current->comm, current->pid); |
434 | /* fall through */ | 438 | /* fall through */ |
435 | case RUNNING: | 439 | case RUNNING: |
@@ -478,65 +482,60 @@ void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait) | |||
478 | wait_for_completion(&thi->stop); | 482 | wait_for_completion(&thi->stop); |
479 | } | 483 | } |
480 | 484 | ||
481 | static struct drbd_thread *drbd_task_to_thread(struct drbd_tconn *tconn, struct task_struct *task) | 485 | int conn_lowest_minor(struct drbd_connection *connection) |
482 | { | ||
483 | struct drbd_thread *thi = | ||
484 | task == tconn->receiver.task ? &tconn->receiver : | ||
485 | task == tconn->asender.task ? &tconn->asender : | ||
486 | task == tconn->worker.task ? &tconn->worker : NULL; | ||
487 | |||
488 | return thi; | ||
489 | } | ||
490 | |||
491 | char *drbd_task_to_thread_name(struct drbd_tconn *tconn, struct task_struct *task) | ||
492 | { | 486 | { |
493 | struct drbd_thread *thi = drbd_task_to_thread(tconn, task); | 487 | struct drbd_peer_device *peer_device; |
494 | return thi ? thi->name : task->comm; | 488 | int vnr = 0, minor = -1; |
495 | } | ||
496 | |||
497 | int conn_lowest_minor(struct drbd_tconn *tconn) | ||
498 | { | ||
499 | struct drbd_conf *mdev; | ||
500 | int vnr = 0, m; | ||
501 | 489 | ||
502 | rcu_read_lock(); | 490 | rcu_read_lock(); |
503 | mdev = idr_get_next(&tconn->volumes, &vnr); | 491 | peer_device = idr_get_next(&connection->peer_devices, &vnr); |
504 | m = mdev ? mdev_to_minor(mdev) : -1; | 492 | if (peer_device) |
493 | minor = device_to_minor(peer_device->device); | ||
505 | rcu_read_unlock(); | 494 | rcu_read_unlock(); |
506 | 495 | ||
507 | return m; | 496 | return minor; |
508 | } | 497 | } |
509 | 498 | ||
510 | #ifdef CONFIG_SMP | 499 | #ifdef CONFIG_SMP |
511 | /** | 500 | /** |
512 | * drbd_calc_cpu_mask() - Generate CPU masks, spread over all CPUs | 501 | * drbd_calc_cpu_mask() - Generate CPU masks, spread over all CPUs |
513 | * @mdev: DRBD device. | ||
514 | * | 502 | * |
515 | * Forces all threads of a device onto the same CPU. This is beneficial for | 503 | * Forces all threads of a resource onto the same CPU. This is beneficial for |
516 | * DRBD's performance. May be overwritten by user's configuration. | 504 | * DRBD's performance. May be overwritten by user's configuration. |
517 | */ | 505 | */ |
518 | void drbd_calc_cpu_mask(struct drbd_tconn *tconn) | 506 | static void drbd_calc_cpu_mask(cpumask_var_t *cpu_mask) |
519 | { | 507 | { |
520 | int ord, cpu; | 508 | unsigned int *resources_per_cpu, min_index = ~0; |
521 | 509 | ||
522 | /* user override. */ | 510 | resources_per_cpu = kzalloc(nr_cpu_ids * sizeof(*resources_per_cpu), GFP_KERNEL); |
523 | if (cpumask_weight(tconn->cpu_mask)) | 511 | if (resources_per_cpu) { |
524 | return; | 512 | struct drbd_resource *resource; |
513 | unsigned int cpu, min = ~0; | ||
525 | 514 | ||
526 | ord = conn_lowest_minor(tconn) % cpumask_weight(cpu_online_mask); | 515 | rcu_read_lock(); |
527 | for_each_online_cpu(cpu) { | 516 | for_each_resource_rcu(resource, &drbd_resources) { |
528 | if (ord-- == 0) { | 517 | for_each_cpu(cpu, resource->cpu_mask) |
529 | cpumask_set_cpu(cpu, tconn->cpu_mask); | 518 | resources_per_cpu[cpu]++; |
530 | return; | ||
531 | } | 519 | } |
520 | rcu_read_unlock(); | ||
521 | for_each_online_cpu(cpu) { | ||
522 | if (resources_per_cpu[cpu] < min) { | ||
523 | min = resources_per_cpu[cpu]; | ||
524 | min_index = cpu; | ||
525 | } | ||
526 | } | ||
527 | kfree(resources_per_cpu); | ||
532 | } | 528 | } |
533 | /* should not be reached */ | 529 | if (min_index == ~0) { |
534 | cpumask_setall(tconn->cpu_mask); | 530 | cpumask_setall(*cpu_mask); |
531 | return; | ||
532 | } | ||
533 | cpumask_set_cpu(min_index, *cpu_mask); | ||
535 | } | 534 | } |
536 | 535 | ||
537 | /** | 536 | /** |
538 | * drbd_thread_current_set_cpu() - modifies the cpu mask of the _current_ thread | 537 | * drbd_thread_current_set_cpu() - modifies the cpu mask of the _current_ thread |
539 | * @mdev: DRBD device. | 538 | * @device: DRBD device. |
540 | * @thi: drbd_thread object | 539 | * @thi: drbd_thread object |
541 | * | 540 | * |
542 | * call in the "main loop" of _all_ threads, no need for any mutex, current won't die | 541 | * call in the "main loop" of _all_ threads, no need for any mutex, current won't die |
@@ -544,13 +543,16 @@ void drbd_calc_cpu_mask(struct drbd_tconn *tconn) | |||
544 | */ | 543 | */ |
545 | void drbd_thread_current_set_cpu(struct drbd_thread *thi) | 544 | void drbd_thread_current_set_cpu(struct drbd_thread *thi) |
546 | { | 545 | { |
546 | struct drbd_resource *resource = thi->resource; | ||
547 | struct task_struct *p = current; | 547 | struct task_struct *p = current; |
548 | 548 | ||
549 | if (!thi->reset_cpu_mask) | 549 | if (!thi->reset_cpu_mask) |
550 | return; | 550 | return; |
551 | thi->reset_cpu_mask = 0; | 551 | thi->reset_cpu_mask = 0; |
552 | set_cpus_allowed_ptr(p, thi->tconn->cpu_mask); | 552 | set_cpus_allowed_ptr(p, resource->cpu_mask); |
553 | } | 553 | } |
554 | #else | ||
555 | #define drbd_calc_cpu_mask(A) ({}) | ||
554 | #endif | 556 | #endif |
555 | 557 | ||
556 | /** | 558 | /** |
@@ -560,9 +562,9 @@ void drbd_thread_current_set_cpu(struct drbd_thread *thi) | |||
560 | * word aligned on 64-bit architectures. (The bitmap send and receive code | 562 | * word aligned on 64-bit architectures. (The bitmap send and receive code |
561 | * relies on this.) | 563 | * relies on this.) |
562 | */ | 564 | */ |
563 | unsigned int drbd_header_size(struct drbd_tconn *tconn) | 565 | unsigned int drbd_header_size(struct drbd_connection *connection) |
564 | { | 566 | { |
565 | if (tconn->agreed_pro_version >= 100) { | 567 | if (connection->agreed_pro_version >= 100) { |
566 | BUILD_BUG_ON(!IS_ALIGNED(sizeof(struct p_header100), 8)); | 568 | BUILD_BUG_ON(!IS_ALIGNED(sizeof(struct p_header100), 8)); |
567 | return sizeof(struct p_header100); | 569 | return sizeof(struct p_header100); |
568 | } else { | 570 | } else { |
@@ -600,44 +602,44 @@ static unsigned int prepare_header100(struct p_header100 *h, enum drbd_packet cm | |||
600 | return sizeof(struct p_header100); | 602 | return sizeof(struct p_header100); |
601 | } | 603 | } |
602 | 604 | ||
603 | static unsigned int prepare_header(struct drbd_tconn *tconn, int vnr, | 605 | static unsigned int prepare_header(struct drbd_connection *connection, int vnr, |
604 | void *buffer, enum drbd_packet cmd, int size) | 606 | void *buffer, enum drbd_packet cmd, int size) |
605 | { | 607 | { |
606 | if (tconn->agreed_pro_version >= 100) | 608 | if (connection->agreed_pro_version >= 100) |
607 | return prepare_header100(buffer, cmd, size, vnr); | 609 | return prepare_header100(buffer, cmd, size, vnr); |
608 | else if (tconn->agreed_pro_version >= 95 && | 610 | else if (connection->agreed_pro_version >= 95 && |
609 | size > DRBD_MAX_SIZE_H80_PACKET) | 611 | size > DRBD_MAX_SIZE_H80_PACKET) |
610 | return prepare_header95(buffer, cmd, size); | 612 | return prepare_header95(buffer, cmd, size); |
611 | else | 613 | else |
612 | return prepare_header80(buffer, cmd, size); | 614 | return prepare_header80(buffer, cmd, size); |
613 | } | 615 | } |
614 | 616 | ||
615 | static void *__conn_prepare_command(struct drbd_tconn *tconn, | 617 | static void *__conn_prepare_command(struct drbd_connection *connection, |
616 | struct drbd_socket *sock) | 618 | struct drbd_socket *sock) |
617 | { | 619 | { |
618 | if (!sock->socket) | 620 | if (!sock->socket) |
619 | return NULL; | 621 | return NULL; |
620 | return sock->sbuf + drbd_header_size(tconn); | 622 | return sock->sbuf + drbd_header_size(connection); |
621 | } | 623 | } |
622 | 624 | ||
623 | void *conn_prepare_command(struct drbd_tconn *tconn, struct drbd_socket *sock) | 625 | void *conn_prepare_command(struct drbd_connection *connection, struct drbd_socket *sock) |
624 | { | 626 | { |
625 | void *p; | 627 | void *p; |
626 | 628 | ||
627 | mutex_lock(&sock->mutex); | 629 | mutex_lock(&sock->mutex); |
628 | p = __conn_prepare_command(tconn, sock); | 630 | p = __conn_prepare_command(connection, sock); |
629 | if (!p) | 631 | if (!p) |
630 | mutex_unlock(&sock->mutex); | 632 | mutex_unlock(&sock->mutex); |
631 | 633 | ||
632 | return p; | 634 | return p; |
633 | } | 635 | } |
634 | 636 | ||
635 | void *drbd_prepare_command(struct drbd_conf *mdev, struct drbd_socket *sock) | 637 | void *drbd_prepare_command(struct drbd_peer_device *peer_device, struct drbd_socket *sock) |
636 | { | 638 | { |
637 | return conn_prepare_command(mdev->tconn, sock); | 639 | return conn_prepare_command(peer_device->connection, sock); |
638 | } | 640 | } |
639 | 641 | ||
640 | static int __send_command(struct drbd_tconn *tconn, int vnr, | 642 | static int __send_command(struct drbd_connection *connection, int vnr, |
641 | struct drbd_socket *sock, enum drbd_packet cmd, | 643 | struct drbd_socket *sock, enum drbd_packet cmd, |
642 | unsigned int header_size, void *data, | 644 | unsigned int header_size, void *data, |
643 | unsigned int size) | 645 | unsigned int size) |
@@ -654,82 +656,82 @@ static int __send_command(struct drbd_tconn *tconn, int vnr, | |||
654 | */ | 656 | */ |
655 | msg_flags = data ? MSG_MORE : 0; | 657 | msg_flags = data ? MSG_MORE : 0; |
656 | 658 | ||
657 | header_size += prepare_header(tconn, vnr, sock->sbuf, cmd, | 659 | header_size += prepare_header(connection, vnr, sock->sbuf, cmd, |
658 | header_size + size); | 660 | header_size + size); |
659 | err = drbd_send_all(tconn, sock->socket, sock->sbuf, header_size, | 661 | err = drbd_send_all(connection, sock->socket, sock->sbuf, header_size, |
660 | msg_flags); | 662 | msg_flags); |
661 | if (data && !err) | 663 | if (data && !err) |
662 | err = drbd_send_all(tconn, sock->socket, data, size, 0); | 664 | err = drbd_send_all(connection, sock->socket, data, size, 0); |
663 | return err; | 665 | return err; |
664 | } | 666 | } |
665 | 667 | ||
666 | static int __conn_send_command(struct drbd_tconn *tconn, struct drbd_socket *sock, | 668 | static int __conn_send_command(struct drbd_connection *connection, struct drbd_socket *sock, |
667 | enum drbd_packet cmd, unsigned int header_size, | 669 | enum drbd_packet cmd, unsigned int header_size, |
668 | void *data, unsigned int size) | 670 | void *data, unsigned int size) |
669 | { | 671 | { |
670 | return __send_command(tconn, 0, sock, cmd, header_size, data, size); | 672 | return __send_command(connection, 0, sock, cmd, header_size, data, size); |
671 | } | 673 | } |
672 | 674 | ||
673 | int conn_send_command(struct drbd_tconn *tconn, struct drbd_socket *sock, | 675 | int conn_send_command(struct drbd_connection *connection, struct drbd_socket *sock, |
674 | enum drbd_packet cmd, unsigned int header_size, | 676 | enum drbd_packet cmd, unsigned int header_size, |
675 | void *data, unsigned int size) | 677 | void *data, unsigned int size) |
676 | { | 678 | { |
677 | int err; | 679 | int err; |
678 | 680 | ||
679 | err = __conn_send_command(tconn, sock, cmd, header_size, data, size); | 681 | err = __conn_send_command(connection, sock, cmd, header_size, data, size); |
680 | mutex_unlock(&sock->mutex); | 682 | mutex_unlock(&sock->mutex); |
681 | return err; | 683 | return err; |
682 | } | 684 | } |
683 | 685 | ||
684 | int drbd_send_command(struct drbd_conf *mdev, struct drbd_socket *sock, | 686 | int drbd_send_command(struct drbd_peer_device *peer_device, struct drbd_socket *sock, |
685 | enum drbd_packet cmd, unsigned int header_size, | 687 | enum drbd_packet cmd, unsigned int header_size, |
686 | void *data, unsigned int size) | 688 | void *data, unsigned int size) |
687 | { | 689 | { |
688 | int err; | 690 | int err; |
689 | 691 | ||
690 | err = __send_command(mdev->tconn, mdev->vnr, sock, cmd, header_size, | 692 | err = __send_command(peer_device->connection, peer_device->device->vnr, |
691 | data, size); | 693 | sock, cmd, header_size, data, size); |
692 | mutex_unlock(&sock->mutex); | 694 | mutex_unlock(&sock->mutex); |
693 | return err; | 695 | return err; |
694 | } | 696 | } |
695 | 697 | ||
696 | int drbd_send_ping(struct drbd_tconn *tconn) | 698 | int drbd_send_ping(struct drbd_connection *connection) |
697 | { | 699 | { |
698 | struct drbd_socket *sock; | 700 | struct drbd_socket *sock; |
699 | 701 | ||
700 | sock = &tconn->meta; | 702 | sock = &connection->meta; |
701 | if (!conn_prepare_command(tconn, sock)) | 703 | if (!conn_prepare_command(connection, sock)) |
702 | return -EIO; | 704 | return -EIO; |
703 | return conn_send_command(tconn, sock, P_PING, 0, NULL, 0); | 705 | return conn_send_command(connection, sock, P_PING, 0, NULL, 0); |
704 | } | 706 | } |
705 | 707 | ||
706 | int drbd_send_ping_ack(struct drbd_tconn *tconn) | 708 | int drbd_send_ping_ack(struct drbd_connection *connection) |
707 | { | 709 | { |
708 | struct drbd_socket *sock; | 710 | struct drbd_socket *sock; |
709 | 711 | ||
710 | sock = &tconn->meta; | 712 | sock = &connection->meta; |
711 | if (!conn_prepare_command(tconn, sock)) | 713 | if (!conn_prepare_command(connection, sock)) |
712 | return -EIO; | 714 | return -EIO; |
713 | return conn_send_command(tconn, sock, P_PING_ACK, 0, NULL, 0); | 715 | return conn_send_command(connection, sock, P_PING_ACK, 0, NULL, 0); |
714 | } | 716 | } |
715 | 717 | ||
716 | int drbd_send_sync_param(struct drbd_conf *mdev) | 718 | int drbd_send_sync_param(struct drbd_peer_device *peer_device) |
717 | { | 719 | { |
718 | struct drbd_socket *sock; | 720 | struct drbd_socket *sock; |
719 | struct p_rs_param_95 *p; | 721 | struct p_rs_param_95 *p; |
720 | int size; | 722 | int size; |
721 | const int apv = mdev->tconn->agreed_pro_version; | 723 | const int apv = peer_device->connection->agreed_pro_version; |
722 | enum drbd_packet cmd; | 724 | enum drbd_packet cmd; |
723 | struct net_conf *nc; | 725 | struct net_conf *nc; |
724 | struct disk_conf *dc; | 726 | struct disk_conf *dc; |
725 | 727 | ||
726 | sock = &mdev->tconn->data; | 728 | sock = &peer_device->connection->data; |
727 | p = drbd_prepare_command(mdev, sock); | 729 | p = drbd_prepare_command(peer_device, sock); |
728 | if (!p) | 730 | if (!p) |
729 | return -EIO; | 731 | return -EIO; |
730 | 732 | ||
731 | rcu_read_lock(); | 733 | rcu_read_lock(); |
732 | nc = rcu_dereference(mdev->tconn->net_conf); | 734 | nc = rcu_dereference(peer_device->connection->net_conf); |
733 | 735 | ||
734 | size = apv <= 87 ? sizeof(struct p_rs_param) | 736 | size = apv <= 87 ? sizeof(struct p_rs_param) |
735 | : apv == 88 ? sizeof(struct p_rs_param) | 737 | : apv == 88 ? sizeof(struct p_rs_param) |
@@ -742,14 +744,14 @@ int drbd_send_sync_param(struct drbd_conf *mdev) | |||
742 | /* initialize verify_alg and csums_alg */ | 744 | /* initialize verify_alg and csums_alg */ |
743 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); | 745 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); |
744 | 746 | ||
745 | if (get_ldev(mdev)) { | 747 | if (get_ldev(peer_device->device)) { |
746 | dc = rcu_dereference(mdev->ldev->disk_conf); | 748 | dc = rcu_dereference(peer_device->device->ldev->disk_conf); |
747 | p->resync_rate = cpu_to_be32(dc->resync_rate); | 749 | p->resync_rate = cpu_to_be32(dc->resync_rate); |
748 | p->c_plan_ahead = cpu_to_be32(dc->c_plan_ahead); | 750 | p->c_plan_ahead = cpu_to_be32(dc->c_plan_ahead); |
749 | p->c_delay_target = cpu_to_be32(dc->c_delay_target); | 751 | p->c_delay_target = cpu_to_be32(dc->c_delay_target); |
750 | p->c_fill_target = cpu_to_be32(dc->c_fill_target); | 752 | p->c_fill_target = cpu_to_be32(dc->c_fill_target); |
751 | p->c_max_rate = cpu_to_be32(dc->c_max_rate); | 753 | p->c_max_rate = cpu_to_be32(dc->c_max_rate); |
752 | put_ldev(mdev); | 754 | put_ldev(peer_device->device); |
753 | } else { | 755 | } else { |
754 | p->resync_rate = cpu_to_be32(DRBD_RESYNC_RATE_DEF); | 756 | p->resync_rate = cpu_to_be32(DRBD_RESYNC_RATE_DEF); |
755 | p->c_plan_ahead = cpu_to_be32(DRBD_C_PLAN_AHEAD_DEF); | 757 | p->c_plan_ahead = cpu_to_be32(DRBD_C_PLAN_AHEAD_DEF); |
@@ -764,33 +766,33 @@ int drbd_send_sync_param(struct drbd_conf *mdev) | |||
764 | strcpy(p->csums_alg, nc->csums_alg); | 766 | strcpy(p->csums_alg, nc->csums_alg); |
765 | rcu_read_unlock(); | 767 | rcu_read_unlock(); |
766 | 768 | ||
767 | return drbd_send_command(mdev, sock, cmd, size, NULL, 0); | 769 | return drbd_send_command(peer_device, sock, cmd, size, NULL, 0); |
768 | } | 770 | } |
769 | 771 | ||
770 | int __drbd_send_protocol(struct drbd_tconn *tconn, enum drbd_packet cmd) | 772 | int __drbd_send_protocol(struct drbd_connection *connection, enum drbd_packet cmd) |
771 | { | 773 | { |
772 | struct drbd_socket *sock; | 774 | struct drbd_socket *sock; |
773 | struct p_protocol *p; | 775 | struct p_protocol *p; |
774 | struct net_conf *nc; | 776 | struct net_conf *nc; |
775 | int size, cf; | 777 | int size, cf; |
776 | 778 | ||
777 | sock = &tconn->data; | 779 | sock = &connection->data; |
778 | p = __conn_prepare_command(tconn, sock); | 780 | p = __conn_prepare_command(connection, sock); |
779 | if (!p) | 781 | if (!p) |
780 | return -EIO; | 782 | return -EIO; |
781 | 783 | ||
782 | rcu_read_lock(); | 784 | rcu_read_lock(); |
783 | nc = rcu_dereference(tconn->net_conf); | 785 | nc = rcu_dereference(connection->net_conf); |
784 | 786 | ||
785 | if (nc->tentative && tconn->agreed_pro_version < 92) { | 787 | if (nc->tentative && connection->agreed_pro_version < 92) { |
786 | rcu_read_unlock(); | 788 | rcu_read_unlock(); |
787 | mutex_unlock(&sock->mutex); | 789 | mutex_unlock(&sock->mutex); |
788 | conn_err(tconn, "--dry-run is not supported by peer"); | 790 | drbd_err(connection, "--dry-run is not supported by peer"); |
789 | return -EOPNOTSUPP; | 791 | return -EOPNOTSUPP; |
790 | } | 792 | } |
791 | 793 | ||
792 | size = sizeof(*p); | 794 | size = sizeof(*p); |
793 | if (tconn->agreed_pro_version >= 87) | 795 | if (connection->agreed_pro_version >= 87) |
794 | size += strlen(nc->integrity_alg) + 1; | 796 | size += strlen(nc->integrity_alg) + 1; |
795 | 797 | ||
796 | p->protocol = cpu_to_be32(nc->wire_protocol); | 798 | p->protocol = cpu_to_be32(nc->wire_protocol); |
@@ -805,128 +807,131 @@ int __drbd_send_protocol(struct drbd_tconn *tconn, enum drbd_packet cmd) | |||
805 | cf |= CF_DRY_RUN; | 807 | cf |= CF_DRY_RUN; |
806 | p->conn_flags = cpu_to_be32(cf); | 808 | p->conn_flags = cpu_to_be32(cf); |
807 | 809 | ||
808 | if (tconn->agreed_pro_version >= 87) | 810 | if (connection->agreed_pro_version >= 87) |
809 | strcpy(p->integrity_alg, nc->integrity_alg); | 811 | strcpy(p->integrity_alg, nc->integrity_alg); |
810 | rcu_read_unlock(); | 812 | rcu_read_unlock(); |
811 | 813 | ||
812 | return __conn_send_command(tconn, sock, cmd, size, NULL, 0); | 814 | return __conn_send_command(connection, sock, cmd, size, NULL, 0); |
813 | } | 815 | } |
814 | 816 | ||
815 | int drbd_send_protocol(struct drbd_tconn *tconn) | 817 | int drbd_send_protocol(struct drbd_connection *connection) |
816 | { | 818 | { |
817 | int err; | 819 | int err; |
818 | 820 | ||
819 | mutex_lock(&tconn->data.mutex); | 821 | mutex_lock(&connection->data.mutex); |
820 | err = __drbd_send_protocol(tconn, P_PROTOCOL); | 822 | err = __drbd_send_protocol(connection, P_PROTOCOL); |
821 | mutex_unlock(&tconn->data.mutex); | 823 | mutex_unlock(&connection->data.mutex); |
822 | 824 | ||
823 | return err; | 825 | return err; |
824 | } | 826 | } |
825 | 827 | ||
826 | int _drbd_send_uuids(struct drbd_conf *mdev, u64 uuid_flags) | 828 | static int _drbd_send_uuids(struct drbd_peer_device *peer_device, u64 uuid_flags) |
827 | { | 829 | { |
830 | struct drbd_device *device = peer_device->device; | ||
828 | struct drbd_socket *sock; | 831 | struct drbd_socket *sock; |
829 | struct p_uuids *p; | 832 | struct p_uuids *p; |
830 | int i; | 833 | int i; |
831 | 834 | ||
832 | if (!get_ldev_if_state(mdev, D_NEGOTIATING)) | 835 | if (!get_ldev_if_state(device, D_NEGOTIATING)) |
833 | return 0; | 836 | return 0; |
834 | 837 | ||
835 | sock = &mdev->tconn->data; | 838 | sock = &peer_device->connection->data; |
836 | p = drbd_prepare_command(mdev, sock); | 839 | p = drbd_prepare_command(peer_device, sock); |
837 | if (!p) { | 840 | if (!p) { |
838 | put_ldev(mdev); | 841 | put_ldev(device); |
839 | return -EIO; | 842 | return -EIO; |
840 | } | 843 | } |
841 | spin_lock_irq(&mdev->ldev->md.uuid_lock); | 844 | spin_lock_irq(&device->ldev->md.uuid_lock); |
842 | for (i = UI_CURRENT; i < UI_SIZE; i++) | 845 | for (i = UI_CURRENT; i < UI_SIZE; i++) |
843 | p->uuid[i] = cpu_to_be64(mdev->ldev->md.uuid[i]); | 846 | p->uuid[i] = cpu_to_be64(device->ldev->md.uuid[i]); |
844 | spin_unlock_irq(&mdev->ldev->md.uuid_lock); | 847 | spin_unlock_irq(&device->ldev->md.uuid_lock); |
845 | 848 | ||
846 | mdev->comm_bm_set = drbd_bm_total_weight(mdev); | 849 | device->comm_bm_set = drbd_bm_total_weight(device); |
847 | p->uuid[UI_SIZE] = cpu_to_be64(mdev->comm_bm_set); | 850 | p->uuid[UI_SIZE] = cpu_to_be64(device->comm_bm_set); |
848 | rcu_read_lock(); | 851 | rcu_read_lock(); |
849 | uuid_flags |= rcu_dereference(mdev->tconn->net_conf)->discard_my_data ? 1 : 0; | 852 | uuid_flags |= rcu_dereference(peer_device->connection->net_conf)->discard_my_data ? 1 : 0; |
850 | rcu_read_unlock(); | 853 | rcu_read_unlock(); |
851 | uuid_flags |= test_bit(CRASHED_PRIMARY, &mdev->flags) ? 2 : 0; | 854 | uuid_flags |= test_bit(CRASHED_PRIMARY, &device->flags) ? 2 : 0; |
852 | uuid_flags |= mdev->new_state_tmp.disk == D_INCONSISTENT ? 4 : 0; | 855 | uuid_flags |= device->new_state_tmp.disk == D_INCONSISTENT ? 4 : 0; |
853 | p->uuid[UI_FLAGS] = cpu_to_be64(uuid_flags); | 856 | p->uuid[UI_FLAGS] = cpu_to_be64(uuid_flags); |
854 | 857 | ||
855 | put_ldev(mdev); | 858 | put_ldev(device); |
856 | return drbd_send_command(mdev, sock, P_UUIDS, sizeof(*p), NULL, 0); | 859 | return drbd_send_command(peer_device, sock, P_UUIDS, sizeof(*p), NULL, 0); |
857 | } | 860 | } |
858 | 861 | ||
859 | int drbd_send_uuids(struct drbd_conf *mdev) | 862 | int drbd_send_uuids(struct drbd_peer_device *peer_device) |
860 | { | 863 | { |
861 | return _drbd_send_uuids(mdev, 0); | 864 | return _drbd_send_uuids(peer_device, 0); |
862 | } | 865 | } |
863 | 866 | ||
864 | int drbd_send_uuids_skip_initial_sync(struct drbd_conf *mdev) | 867 | int drbd_send_uuids_skip_initial_sync(struct drbd_peer_device *peer_device) |
865 | { | 868 | { |
866 | return _drbd_send_uuids(mdev, 8); | 869 | return _drbd_send_uuids(peer_device, 8); |
867 | } | 870 | } |
868 | 871 | ||
869 | void drbd_print_uuids(struct drbd_conf *mdev, const char *text) | 872 | void drbd_print_uuids(struct drbd_device *device, const char *text) |
870 | { | 873 | { |
871 | if (get_ldev_if_state(mdev, D_NEGOTIATING)) { | 874 | if (get_ldev_if_state(device, D_NEGOTIATING)) { |
872 | u64 *uuid = mdev->ldev->md.uuid; | 875 | u64 *uuid = device->ldev->md.uuid; |
873 | dev_info(DEV, "%s %016llX:%016llX:%016llX:%016llX\n", | 876 | drbd_info(device, "%s %016llX:%016llX:%016llX:%016llX\n", |
874 | text, | 877 | text, |
875 | (unsigned long long)uuid[UI_CURRENT], | 878 | (unsigned long long)uuid[UI_CURRENT], |
876 | (unsigned long long)uuid[UI_BITMAP], | 879 | (unsigned long long)uuid[UI_BITMAP], |
877 | (unsigned long long)uuid[UI_HISTORY_START], | 880 | (unsigned long long)uuid[UI_HISTORY_START], |
878 | (unsigned long long)uuid[UI_HISTORY_END]); | 881 | (unsigned long long)uuid[UI_HISTORY_END]); |
879 | put_ldev(mdev); | 882 | put_ldev(device); |
880 | } else { | 883 | } else { |
881 | dev_info(DEV, "%s effective data uuid: %016llX\n", | 884 | drbd_info(device, "%s effective data uuid: %016llX\n", |
882 | text, | 885 | text, |
883 | (unsigned long long)mdev->ed_uuid); | 886 | (unsigned long long)device->ed_uuid); |
884 | } | 887 | } |
885 | } | 888 | } |
886 | 889 | ||
887 | void drbd_gen_and_send_sync_uuid(struct drbd_conf *mdev) | 890 | void drbd_gen_and_send_sync_uuid(struct drbd_peer_device *peer_device) |
888 | { | 891 | { |
892 | struct drbd_device *device = peer_device->device; | ||
889 | struct drbd_socket *sock; | 893 | struct drbd_socket *sock; |
890 | struct p_rs_uuid *p; | 894 | struct p_rs_uuid *p; |
891 | u64 uuid; | 895 | u64 uuid; |
892 | 896 | ||
893 | D_ASSERT(mdev->state.disk == D_UP_TO_DATE); | 897 | D_ASSERT(device, device->state.disk == D_UP_TO_DATE); |
894 | 898 | ||
895 | uuid = mdev->ldev->md.uuid[UI_BITMAP]; | 899 | uuid = device->ldev->md.uuid[UI_BITMAP]; |
896 | if (uuid && uuid != UUID_JUST_CREATED) | 900 | if (uuid && uuid != UUID_JUST_CREATED) |
897 | uuid = uuid + UUID_NEW_BM_OFFSET; | 901 | uuid = uuid + UUID_NEW_BM_OFFSET; |
898 | else | 902 | else |
899 | get_random_bytes(&uuid, sizeof(u64)); | 903 | get_random_bytes(&uuid, sizeof(u64)); |
900 | drbd_uuid_set(mdev, UI_BITMAP, uuid); | 904 | drbd_uuid_set(device, UI_BITMAP, uuid); |
901 | drbd_print_uuids(mdev, "updated sync UUID"); | 905 | drbd_print_uuids(device, "updated sync UUID"); |
902 | drbd_md_sync(mdev); | 906 | drbd_md_sync(device); |
903 | 907 | ||
904 | sock = &mdev->tconn->data; | 908 | sock = &peer_device->connection->data; |
905 | p = drbd_prepare_command(mdev, sock); | 909 | p = drbd_prepare_command(peer_device, sock); |
906 | if (p) { | 910 | if (p) { |
907 | p->uuid = cpu_to_be64(uuid); | 911 | p->uuid = cpu_to_be64(uuid); |
908 | drbd_send_command(mdev, sock, P_SYNC_UUID, sizeof(*p), NULL, 0); | 912 | drbd_send_command(peer_device, sock, P_SYNC_UUID, sizeof(*p), NULL, 0); |
909 | } | 913 | } |
910 | } | 914 | } |
911 | 915 | ||
912 | int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags flags) | 916 | int drbd_send_sizes(struct drbd_peer_device *peer_device, int trigger_reply, enum dds_flags flags) |
913 | { | 917 | { |
918 | struct drbd_device *device = peer_device->device; | ||
914 | struct drbd_socket *sock; | 919 | struct drbd_socket *sock; |
915 | struct p_sizes *p; | 920 | struct p_sizes *p; |
916 | sector_t d_size, u_size; | 921 | sector_t d_size, u_size; |
917 | int q_order_type; | 922 | int q_order_type; |
918 | unsigned int max_bio_size; | 923 | unsigned int max_bio_size; |
919 | 924 | ||
920 | if (get_ldev_if_state(mdev, D_NEGOTIATING)) { | 925 | if (get_ldev_if_state(device, D_NEGOTIATING)) { |
921 | D_ASSERT(mdev->ldev->backing_bdev); | 926 | D_ASSERT(device, device->ldev->backing_bdev); |
922 | d_size = drbd_get_max_capacity(mdev->ldev); | 927 | d_size = drbd_get_max_capacity(device->ldev); |
923 | rcu_read_lock(); | 928 | rcu_read_lock(); |
924 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; | 929 | u_size = rcu_dereference(device->ldev->disk_conf)->disk_size; |
925 | rcu_read_unlock(); | 930 | rcu_read_unlock(); |
926 | q_order_type = drbd_queue_order_type(mdev); | 931 | q_order_type = drbd_queue_order_type(device); |
927 | max_bio_size = queue_max_hw_sectors(mdev->ldev->backing_bdev->bd_disk->queue) << 9; | 932 | max_bio_size = queue_max_hw_sectors(device->ldev->backing_bdev->bd_disk->queue) << 9; |
928 | max_bio_size = min(max_bio_size, DRBD_MAX_BIO_SIZE); | 933 | max_bio_size = min(max_bio_size, DRBD_MAX_BIO_SIZE); |
929 | put_ldev(mdev); | 934 | put_ldev(device); |
930 | } else { | 935 | } else { |
931 | d_size = 0; | 936 | d_size = 0; |
932 | u_size = 0; | 937 | u_size = 0; |
@@ -934,45 +939,45 @@ int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags fl | |||
934 | max_bio_size = DRBD_MAX_BIO_SIZE; /* ... multiple BIOs per peer_request */ | 939 | max_bio_size = DRBD_MAX_BIO_SIZE; /* ... multiple BIOs per peer_request */ |
935 | } | 940 | } |
936 | 941 | ||
937 | sock = &mdev->tconn->data; | 942 | sock = &peer_device->connection->data; |
938 | p = drbd_prepare_command(mdev, sock); | 943 | p = drbd_prepare_command(peer_device, sock); |
939 | if (!p) | 944 | if (!p) |
940 | return -EIO; | 945 | return -EIO; |
941 | 946 | ||
942 | if (mdev->tconn->agreed_pro_version <= 94) | 947 | if (peer_device->connection->agreed_pro_version <= 94) |
943 | max_bio_size = min(max_bio_size, DRBD_MAX_SIZE_H80_PACKET); | 948 | max_bio_size = min(max_bio_size, DRBD_MAX_SIZE_H80_PACKET); |
944 | else if (mdev->tconn->agreed_pro_version < 100) | 949 | else if (peer_device->connection->agreed_pro_version < 100) |
945 | max_bio_size = min(max_bio_size, DRBD_MAX_BIO_SIZE_P95); | 950 | max_bio_size = min(max_bio_size, DRBD_MAX_BIO_SIZE_P95); |
946 | 951 | ||
947 | p->d_size = cpu_to_be64(d_size); | 952 | p->d_size = cpu_to_be64(d_size); |
948 | p->u_size = cpu_to_be64(u_size); | 953 | p->u_size = cpu_to_be64(u_size); |
949 | p->c_size = cpu_to_be64(trigger_reply ? 0 : drbd_get_capacity(mdev->this_bdev)); | 954 | p->c_size = cpu_to_be64(trigger_reply ? 0 : drbd_get_capacity(device->this_bdev)); |
950 | p->max_bio_size = cpu_to_be32(max_bio_size); | 955 | p->max_bio_size = cpu_to_be32(max_bio_size); |
951 | p->queue_order_type = cpu_to_be16(q_order_type); | 956 | p->queue_order_type = cpu_to_be16(q_order_type); |
952 | p->dds_flags = cpu_to_be16(flags); | 957 | p->dds_flags = cpu_to_be16(flags); |
953 | return drbd_send_command(mdev, sock, P_SIZES, sizeof(*p), NULL, 0); | 958 | return drbd_send_command(peer_device, sock, P_SIZES, sizeof(*p), NULL, 0); |
954 | } | 959 | } |
955 | 960 | ||
956 | /** | 961 | /** |
957 | * drbd_send_current_state() - Sends the drbd state to the peer | 962 | * drbd_send_current_state() - Sends the drbd state to the peer |
958 | * @mdev: DRBD device. | 963 | * @peer_device: DRBD peer device. |
959 | */ | 964 | */ |
960 | int drbd_send_current_state(struct drbd_conf *mdev) | 965 | int drbd_send_current_state(struct drbd_peer_device *peer_device) |
961 | { | 966 | { |
962 | struct drbd_socket *sock; | 967 | struct drbd_socket *sock; |
963 | struct p_state *p; | 968 | struct p_state *p; |
964 | 969 | ||
965 | sock = &mdev->tconn->data; | 970 | sock = &peer_device->connection->data; |
966 | p = drbd_prepare_command(mdev, sock); | 971 | p = drbd_prepare_command(peer_device, sock); |
967 | if (!p) | 972 | if (!p) |
968 | return -EIO; | 973 | return -EIO; |
969 | p->state = cpu_to_be32(mdev->state.i); /* Within the send mutex */ | 974 | p->state = cpu_to_be32(peer_device->device->state.i); /* Within the send mutex */ |
970 | return drbd_send_command(mdev, sock, P_STATE, sizeof(*p), NULL, 0); | 975 | return drbd_send_command(peer_device, sock, P_STATE, sizeof(*p), NULL, 0); |
971 | } | 976 | } |
972 | 977 | ||
973 | /** | 978 | /** |
974 | * drbd_send_state() - After a state change, sends the new state to the peer | 979 | * drbd_send_state() - After a state change, sends the new state to the peer |
975 | * @mdev: DRBD device. | 980 | * @peer_device: DRBD peer device. |
976 | * @state: the state to send, not necessarily the current state. | 981 | * @state: the state to send, not necessarily the current state. |
977 | * | 982 | * |
978 | * Each state change queues an "after_state_ch" work, which will eventually | 983 | * Each state change queues an "after_state_ch" work, which will eventually |
@@ -980,73 +985,73 @@ int drbd_send_current_state(struct drbd_conf *mdev) | |||
980 | * between queuing and processing of the after_state_ch work, we still | 985 | * between queuing and processing of the after_state_ch work, we still |
981 | * want to send each intermediary state in the order it occurred. | 986 | * want to send each intermediary state in the order it occurred. |
982 | */ | 987 | */ |
983 | int drbd_send_state(struct drbd_conf *mdev, union drbd_state state) | 988 | int drbd_send_state(struct drbd_peer_device *peer_device, union drbd_state state) |
984 | { | 989 | { |
985 | struct drbd_socket *sock; | 990 | struct drbd_socket *sock; |
986 | struct p_state *p; | 991 | struct p_state *p; |
987 | 992 | ||
988 | sock = &mdev->tconn->data; | 993 | sock = &peer_device->connection->data; |
989 | p = drbd_prepare_command(mdev, sock); | 994 | p = drbd_prepare_command(peer_device, sock); |
990 | if (!p) | 995 | if (!p) |
991 | return -EIO; | 996 | return -EIO; |
992 | p->state = cpu_to_be32(state.i); /* Within the send mutex */ | 997 | p->state = cpu_to_be32(state.i); /* Within the send mutex */ |
993 | return drbd_send_command(mdev, sock, P_STATE, sizeof(*p), NULL, 0); | 998 | return drbd_send_command(peer_device, sock, P_STATE, sizeof(*p), NULL, 0); |
994 | } | 999 | } |
995 | 1000 | ||
996 | int drbd_send_state_req(struct drbd_conf *mdev, union drbd_state mask, union drbd_state val) | 1001 | int drbd_send_state_req(struct drbd_peer_device *peer_device, union drbd_state mask, union drbd_state val) |
997 | { | 1002 | { |
998 | struct drbd_socket *sock; | 1003 | struct drbd_socket *sock; |
999 | struct p_req_state *p; | 1004 | struct p_req_state *p; |
1000 | 1005 | ||
1001 | sock = &mdev->tconn->data; | 1006 | sock = &peer_device->connection->data; |
1002 | p = drbd_prepare_command(mdev, sock); | 1007 | p = drbd_prepare_command(peer_device, sock); |
1003 | if (!p) | 1008 | if (!p) |
1004 | return -EIO; | 1009 | return -EIO; |
1005 | p->mask = cpu_to_be32(mask.i); | 1010 | p->mask = cpu_to_be32(mask.i); |
1006 | p->val = cpu_to_be32(val.i); | 1011 | p->val = cpu_to_be32(val.i); |
1007 | return drbd_send_command(mdev, sock, P_STATE_CHG_REQ, sizeof(*p), NULL, 0); | 1012 | return drbd_send_command(peer_device, sock, P_STATE_CHG_REQ, sizeof(*p), NULL, 0); |
1008 | } | 1013 | } |
1009 | 1014 | ||
1010 | int conn_send_state_req(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val) | 1015 | int conn_send_state_req(struct drbd_connection *connection, union drbd_state mask, union drbd_state val) |
1011 | { | 1016 | { |
1012 | enum drbd_packet cmd; | 1017 | enum drbd_packet cmd; |
1013 | struct drbd_socket *sock; | 1018 | struct drbd_socket *sock; |
1014 | struct p_req_state *p; | 1019 | struct p_req_state *p; |
1015 | 1020 | ||
1016 | cmd = tconn->agreed_pro_version < 100 ? P_STATE_CHG_REQ : P_CONN_ST_CHG_REQ; | 1021 | cmd = connection->agreed_pro_version < 100 ? P_STATE_CHG_REQ : P_CONN_ST_CHG_REQ; |
1017 | sock = &tconn->data; | 1022 | sock = &connection->data; |
1018 | p = conn_prepare_command(tconn, sock); | 1023 | p = conn_prepare_command(connection, sock); |
1019 | if (!p) | 1024 | if (!p) |
1020 | return -EIO; | 1025 | return -EIO; |
1021 | p->mask = cpu_to_be32(mask.i); | 1026 | p->mask = cpu_to_be32(mask.i); |
1022 | p->val = cpu_to_be32(val.i); | 1027 | p->val = cpu_to_be32(val.i); |
1023 | return conn_send_command(tconn, sock, cmd, sizeof(*p), NULL, 0); | 1028 | return conn_send_command(connection, sock, cmd, sizeof(*p), NULL, 0); |
1024 | } | 1029 | } |
1025 | 1030 | ||
1026 | void drbd_send_sr_reply(struct drbd_conf *mdev, enum drbd_state_rv retcode) | 1031 | void drbd_send_sr_reply(struct drbd_peer_device *peer_device, enum drbd_state_rv retcode) |
1027 | { | 1032 | { |
1028 | struct drbd_socket *sock; | 1033 | struct drbd_socket *sock; |
1029 | struct p_req_state_reply *p; | 1034 | struct p_req_state_reply *p; |
1030 | 1035 | ||
1031 | sock = &mdev->tconn->meta; | 1036 | sock = &peer_device->connection->meta; |
1032 | p = drbd_prepare_command(mdev, sock); | 1037 | p = drbd_prepare_command(peer_device, sock); |
1033 | if (p) { | 1038 | if (p) { |
1034 | p->retcode = cpu_to_be32(retcode); | 1039 | p->retcode = cpu_to_be32(retcode); |
1035 | drbd_send_command(mdev, sock, P_STATE_CHG_REPLY, sizeof(*p), NULL, 0); | 1040 | drbd_send_command(peer_device, sock, P_STATE_CHG_REPLY, sizeof(*p), NULL, 0); |
1036 | } | 1041 | } |
1037 | } | 1042 | } |
1038 | 1043 | ||
1039 | void conn_send_sr_reply(struct drbd_tconn *tconn, enum drbd_state_rv retcode) | 1044 | void conn_send_sr_reply(struct drbd_connection *connection, enum drbd_state_rv retcode) |
1040 | { | 1045 | { |
1041 | struct drbd_socket *sock; | 1046 | struct drbd_socket *sock; |
1042 | struct p_req_state_reply *p; | 1047 | struct p_req_state_reply *p; |
1043 | enum drbd_packet cmd = tconn->agreed_pro_version < 100 ? P_STATE_CHG_REPLY : P_CONN_ST_CHG_REPLY; | 1048 | enum drbd_packet cmd = connection->agreed_pro_version < 100 ? P_STATE_CHG_REPLY : P_CONN_ST_CHG_REPLY; |
1044 | 1049 | ||
1045 | sock = &tconn->meta; | 1050 | sock = &connection->meta; |
1046 | p = conn_prepare_command(tconn, sock); | 1051 | p = conn_prepare_command(connection, sock); |
1047 | if (p) { | 1052 | if (p) { |
1048 | p->retcode = cpu_to_be32(retcode); | 1053 | p->retcode = cpu_to_be32(retcode); |
1049 | conn_send_command(tconn, sock, cmd, sizeof(*p), NULL, 0); | 1054 | conn_send_command(connection, sock, cmd, sizeof(*p), NULL, 0); |
1050 | } | 1055 | } |
1051 | } | 1056 | } |
1052 | 1057 | ||
@@ -1067,7 +1072,7 @@ static void dcbp_set_pad_bits(struct p_compressed_bm *p, int n) | |||
1067 | p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4); | 1072 | p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4); |
1068 | } | 1073 | } |
1069 | 1074 | ||
1070 | int fill_bitmap_rle_bits(struct drbd_conf *mdev, | 1075 | static int fill_bitmap_rle_bits(struct drbd_device *device, |
1071 | struct p_compressed_bm *p, | 1076 | struct p_compressed_bm *p, |
1072 | unsigned int size, | 1077 | unsigned int size, |
1073 | struct bm_xfer_ctx *c) | 1078 | struct bm_xfer_ctx *c) |
@@ -1082,9 +1087,9 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev, | |||
1082 | 1087 | ||
1083 | /* may we use this feature? */ | 1088 | /* may we use this feature? */ |
1084 | rcu_read_lock(); | 1089 | rcu_read_lock(); |
1085 | use_rle = rcu_dereference(mdev->tconn->net_conf)->use_rle; | 1090 | use_rle = rcu_dereference(first_peer_device(device)->connection->net_conf)->use_rle; |
1086 | rcu_read_unlock(); | 1091 | rcu_read_unlock(); |
1087 | if (!use_rle || mdev->tconn->agreed_pro_version < 90) | 1092 | if (!use_rle || first_peer_device(device)->connection->agreed_pro_version < 90) |
1088 | return 0; | 1093 | return 0; |
1089 | 1094 | ||
1090 | if (c->bit_offset >= c->bm_bits) | 1095 | if (c->bit_offset >= c->bm_bits) |
@@ -1104,8 +1109,8 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev, | |||
1104 | /* see how much plain bits we can stuff into one packet | 1109 | /* see how much plain bits we can stuff into one packet |
1105 | * using RLE and VLI. */ | 1110 | * using RLE and VLI. */ |
1106 | do { | 1111 | do { |
1107 | tmp = (toggle == 0) ? _drbd_bm_find_next_zero(mdev, c->bit_offset) | 1112 | tmp = (toggle == 0) ? _drbd_bm_find_next_zero(device, c->bit_offset) |
1108 | : _drbd_bm_find_next(mdev, c->bit_offset); | 1113 | : _drbd_bm_find_next(device, c->bit_offset); |
1109 | if (tmp == -1UL) | 1114 | if (tmp == -1UL) |
1110 | tmp = c->bm_bits; | 1115 | tmp = c->bm_bits; |
1111 | rl = tmp - c->bit_offset; | 1116 | rl = tmp - c->bit_offset; |
@@ -1125,7 +1130,7 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev, | |||
1125 | /* paranoia: catch zero runlength. | 1130 | /* paranoia: catch zero runlength. |
1126 | * can only happen if bitmap is modified while we scan it. */ | 1131 | * can only happen if bitmap is modified while we scan it. */ |
1127 | if (rl == 0) { | 1132 | if (rl == 0) { |
1128 | dev_err(DEV, "unexpected zero runlength while encoding bitmap " | 1133 | drbd_err(device, "unexpected zero runlength while encoding bitmap " |
1129 | "t:%u bo:%lu\n", toggle, c->bit_offset); | 1134 | "t:%u bo:%lu\n", toggle, c->bit_offset); |
1130 | return -1; | 1135 | return -1; |
1131 | } | 1136 | } |
@@ -1134,7 +1139,7 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev, | |||
1134 | if (bits == -ENOBUFS) /* buffer full */ | 1139 | if (bits == -ENOBUFS) /* buffer full */ |
1135 | break; | 1140 | break; |
1136 | if (bits <= 0) { | 1141 | if (bits <= 0) { |
1137 | dev_err(DEV, "error while encoding bitmap: %d\n", bits); | 1142 | drbd_err(device, "error while encoding bitmap: %d\n", bits); |
1138 | return 0; | 1143 | return 0; |
1139 | } | 1144 | } |
1140 | 1145 | ||
@@ -1171,21 +1176,21 @@ int fill_bitmap_rle_bits(struct drbd_conf *mdev, | |||
1171 | * code upon failure. | 1176 | * code upon failure. |
1172 | */ | 1177 | */ |
1173 | static int | 1178 | static int |
1174 | send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) | 1179 | send_bitmap_rle_or_plain(struct drbd_device *device, struct bm_xfer_ctx *c) |
1175 | { | 1180 | { |
1176 | struct drbd_socket *sock = &mdev->tconn->data; | 1181 | struct drbd_socket *sock = &first_peer_device(device)->connection->data; |
1177 | unsigned int header_size = drbd_header_size(mdev->tconn); | 1182 | unsigned int header_size = drbd_header_size(first_peer_device(device)->connection); |
1178 | struct p_compressed_bm *p = sock->sbuf + header_size; | 1183 | struct p_compressed_bm *p = sock->sbuf + header_size; |
1179 | int len, err; | 1184 | int len, err; |
1180 | 1185 | ||
1181 | len = fill_bitmap_rle_bits(mdev, p, | 1186 | len = fill_bitmap_rle_bits(device, p, |
1182 | DRBD_SOCKET_BUFFER_SIZE - header_size - sizeof(*p), c); | 1187 | DRBD_SOCKET_BUFFER_SIZE - header_size - sizeof(*p), c); |
1183 | if (len < 0) | 1188 | if (len < 0) |
1184 | return -EIO; | 1189 | return -EIO; |
1185 | 1190 | ||
1186 | if (len) { | 1191 | if (len) { |
1187 | dcbp_set_code(p, RLE_VLI_Bits); | 1192 | dcbp_set_code(p, RLE_VLI_Bits); |
1188 | err = __send_command(mdev->tconn, mdev->vnr, sock, | 1193 | err = __send_command(first_peer_device(device)->connection, device->vnr, sock, |
1189 | P_COMPRESSED_BITMAP, sizeof(*p) + len, | 1194 | P_COMPRESSED_BITMAP, sizeof(*p) + len, |
1190 | NULL, 0); | 1195 | NULL, 0); |
1191 | c->packets[0]++; | 1196 | c->packets[0]++; |
@@ -1205,8 +1210,8 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) | |||
1205 | c->bm_words - c->word_offset); | 1210 | c->bm_words - c->word_offset); |
1206 | len = num_words * sizeof(*p); | 1211 | len = num_words * sizeof(*p); |
1207 | if (len) | 1212 | if (len) |
1208 | drbd_bm_get_lel(mdev, c->word_offset, num_words, p); | 1213 | drbd_bm_get_lel(device, c->word_offset, num_words, p); |
1209 | err = __send_command(mdev->tconn, mdev->vnr, sock, P_BITMAP, len, NULL, 0); | 1214 | err = __send_command(first_peer_device(device)->connection, device->vnr, sock, P_BITMAP, len, NULL, 0); |
1210 | c->word_offset += num_words; | 1215 | c->word_offset += num_words; |
1211 | c->bit_offset = c->word_offset * BITS_PER_LONG; | 1216 | c->bit_offset = c->word_offset * BITS_PER_LONG; |
1212 | 1217 | ||
@@ -1218,7 +1223,7 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) | |||
1218 | } | 1223 | } |
1219 | if (!err) { | 1224 | if (!err) { |
1220 | if (len == 0) { | 1225 | if (len == 0) { |
1221 | INFO_bm_xfer_stats(mdev, "send", c); | 1226 | INFO_bm_xfer_stats(device, "send", c); |
1222 | return 0; | 1227 | return 0; |
1223 | } else | 1228 | } else |
1224 | return 1; | 1229 | return 1; |
@@ -1227,128 +1232,128 @@ send_bitmap_rle_or_plain(struct drbd_conf *mdev, struct bm_xfer_ctx *c) | |||
1227 | } | 1232 | } |
1228 | 1233 | ||
1229 | /* See the comment at receive_bitmap() */ | 1234 | /* See the comment at receive_bitmap() */ |
1230 | static int _drbd_send_bitmap(struct drbd_conf *mdev) | 1235 | static int _drbd_send_bitmap(struct drbd_device *device) |
1231 | { | 1236 | { |
1232 | struct bm_xfer_ctx c; | 1237 | struct bm_xfer_ctx c; |
1233 | int err; | 1238 | int err; |
1234 | 1239 | ||
1235 | if (!expect(mdev->bitmap)) | 1240 | if (!expect(device->bitmap)) |
1236 | return false; | 1241 | return false; |
1237 | 1242 | ||
1238 | if (get_ldev(mdev)) { | 1243 | if (get_ldev(device)) { |
1239 | if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC)) { | 1244 | if (drbd_md_test_flag(device->ldev, MDF_FULL_SYNC)) { |
1240 | dev_info(DEV, "Writing the whole bitmap, MDF_FullSync was set.\n"); | 1245 | drbd_info(device, "Writing the whole bitmap, MDF_FullSync was set.\n"); |
1241 | drbd_bm_set_all(mdev); | 1246 | drbd_bm_set_all(device); |
1242 | if (drbd_bm_write(mdev)) { | 1247 | if (drbd_bm_write(device)) { |
1243 | /* write_bm did fail! Leave full sync flag set in Meta P_DATA | 1248 | /* write_bm did fail! Leave full sync flag set in Meta P_DATA |
1244 | * but otherwise process as per normal - need to tell other | 1249 | * but otherwise process as per normal - need to tell other |
1245 | * side that a full resync is required! */ | 1250 | * side that a full resync is required! */ |
1246 | dev_err(DEV, "Failed to write bitmap to disk!\n"); | 1251 | drbd_err(device, "Failed to write bitmap to disk!\n"); |
1247 | } else { | 1252 | } else { |
1248 | drbd_md_clear_flag(mdev, MDF_FULL_SYNC); | 1253 | drbd_md_clear_flag(device, MDF_FULL_SYNC); |
1249 | drbd_md_sync(mdev); | 1254 | drbd_md_sync(device); |
1250 | } | 1255 | } |
1251 | } | 1256 | } |
1252 | put_ldev(mdev); | 1257 | put_ldev(device); |
1253 | } | 1258 | } |
1254 | 1259 | ||
1255 | c = (struct bm_xfer_ctx) { | 1260 | c = (struct bm_xfer_ctx) { |
1256 | .bm_bits = drbd_bm_bits(mdev), | 1261 | .bm_bits = drbd_bm_bits(device), |
1257 | .bm_words = drbd_bm_words(mdev), | 1262 | .bm_words = drbd_bm_words(device), |
1258 | }; | 1263 | }; |
1259 | 1264 | ||
1260 | do { | 1265 | do { |
1261 | err = send_bitmap_rle_or_plain(mdev, &c); | 1266 | err = send_bitmap_rle_or_plain(device, &c); |
1262 | } while (err > 0); | 1267 | } while (err > 0); |
1263 | 1268 | ||
1264 | return err == 0; | 1269 | return err == 0; |
1265 | } | 1270 | } |
1266 | 1271 | ||
1267 | int drbd_send_bitmap(struct drbd_conf *mdev) | 1272 | int drbd_send_bitmap(struct drbd_device *device) |
1268 | { | 1273 | { |
1269 | struct drbd_socket *sock = &mdev->tconn->data; | 1274 | struct drbd_socket *sock = &first_peer_device(device)->connection->data; |
1270 | int err = -1; | 1275 | int err = -1; |
1271 | 1276 | ||
1272 | mutex_lock(&sock->mutex); | 1277 | mutex_lock(&sock->mutex); |
1273 | if (sock->socket) | 1278 | if (sock->socket) |
1274 | err = !_drbd_send_bitmap(mdev); | 1279 | err = !_drbd_send_bitmap(device); |
1275 | mutex_unlock(&sock->mutex); | 1280 | mutex_unlock(&sock->mutex); |
1276 | return err; | 1281 | return err; |
1277 | } | 1282 | } |
1278 | 1283 | ||
1279 | void drbd_send_b_ack(struct drbd_tconn *tconn, u32 barrier_nr, u32 set_size) | 1284 | void drbd_send_b_ack(struct drbd_connection *connection, u32 barrier_nr, u32 set_size) |
1280 | { | 1285 | { |
1281 | struct drbd_socket *sock; | 1286 | struct drbd_socket *sock; |
1282 | struct p_barrier_ack *p; | 1287 | struct p_barrier_ack *p; |
1283 | 1288 | ||
1284 | if (tconn->cstate < C_WF_REPORT_PARAMS) | 1289 | if (connection->cstate < C_WF_REPORT_PARAMS) |
1285 | return; | 1290 | return; |
1286 | 1291 | ||
1287 | sock = &tconn->meta; | 1292 | sock = &connection->meta; |
1288 | p = conn_prepare_command(tconn, sock); | 1293 | p = conn_prepare_command(connection, sock); |
1289 | if (!p) | 1294 | if (!p) |
1290 | return; | 1295 | return; |
1291 | p->barrier = barrier_nr; | 1296 | p->barrier = barrier_nr; |
1292 | p->set_size = cpu_to_be32(set_size); | 1297 | p->set_size = cpu_to_be32(set_size); |
1293 | conn_send_command(tconn, sock, P_BARRIER_ACK, sizeof(*p), NULL, 0); | 1298 | conn_send_command(connection, sock, P_BARRIER_ACK, sizeof(*p), NULL, 0); |
1294 | } | 1299 | } |
1295 | 1300 | ||
1296 | /** | 1301 | /** |
1297 | * _drbd_send_ack() - Sends an ack packet | 1302 | * _drbd_send_ack() - Sends an ack packet |
1298 | * @mdev: DRBD device. | 1303 | * @device: DRBD device. |
1299 | * @cmd: Packet command code. | 1304 | * @cmd: Packet command code. |
1300 | * @sector: sector, needs to be in big endian byte order | 1305 | * @sector: sector, needs to be in big endian byte order |
1301 | * @blksize: size in byte, needs to be in big endian byte order | 1306 | * @blksize: size in byte, needs to be in big endian byte order |
1302 | * @block_id: Id, big endian byte order | 1307 | * @block_id: Id, big endian byte order |
1303 | */ | 1308 | */ |
1304 | static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd, | 1309 | static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1305 | u64 sector, u32 blksize, u64 block_id) | 1310 | u64 sector, u32 blksize, u64 block_id) |
1306 | { | 1311 | { |
1307 | struct drbd_socket *sock; | 1312 | struct drbd_socket *sock; |
1308 | struct p_block_ack *p; | 1313 | struct p_block_ack *p; |
1309 | 1314 | ||
1310 | if (mdev->state.conn < C_CONNECTED) | 1315 | if (peer_device->device->state.conn < C_CONNECTED) |
1311 | return -EIO; | 1316 | return -EIO; |
1312 | 1317 | ||
1313 | sock = &mdev->tconn->meta; | 1318 | sock = &peer_device->connection->meta; |
1314 | p = drbd_prepare_command(mdev, sock); | 1319 | p = drbd_prepare_command(peer_device, sock); |
1315 | if (!p) | 1320 | if (!p) |
1316 | return -EIO; | 1321 | return -EIO; |
1317 | p->sector = sector; | 1322 | p->sector = sector; |
1318 | p->block_id = block_id; | 1323 | p->block_id = block_id; |
1319 | p->blksize = blksize; | 1324 | p->blksize = blksize; |
1320 | p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq)); | 1325 | p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq)); |
1321 | return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0); | 1326 | return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0); |
1322 | } | 1327 | } |
1323 | 1328 | ||
1324 | /* dp->sector and dp->block_id already/still in network byte order, | 1329 | /* dp->sector and dp->block_id already/still in network byte order, |
1325 | * data_size is payload size according to dp->head, | 1330 | * data_size is payload size according to dp->head, |
1326 | * and may need to be corrected for digest size. */ | 1331 | * and may need to be corrected for digest size. */ |
1327 | void drbd_send_ack_dp(struct drbd_conf *mdev, enum drbd_packet cmd, | 1332 | void drbd_send_ack_dp(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1328 | struct p_data *dp, int data_size) | 1333 | struct p_data *dp, int data_size) |
1329 | { | 1334 | { |
1330 | if (mdev->tconn->peer_integrity_tfm) | 1335 | if (peer_device->connection->peer_integrity_tfm) |
1331 | data_size -= crypto_hash_digestsize(mdev->tconn->peer_integrity_tfm); | 1336 | data_size -= crypto_hash_digestsize(peer_device->connection->peer_integrity_tfm); |
1332 | _drbd_send_ack(mdev, cmd, dp->sector, cpu_to_be32(data_size), | 1337 | _drbd_send_ack(peer_device, cmd, dp->sector, cpu_to_be32(data_size), |
1333 | dp->block_id); | 1338 | dp->block_id); |
1334 | } | 1339 | } |
1335 | 1340 | ||
1336 | void drbd_send_ack_rp(struct drbd_conf *mdev, enum drbd_packet cmd, | 1341 | void drbd_send_ack_rp(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1337 | struct p_block_req *rp) | 1342 | struct p_block_req *rp) |
1338 | { | 1343 | { |
1339 | _drbd_send_ack(mdev, cmd, rp->sector, rp->blksize, rp->block_id); | 1344 | _drbd_send_ack(peer_device, cmd, rp->sector, rp->blksize, rp->block_id); |
1340 | } | 1345 | } |
1341 | 1346 | ||
1342 | /** | 1347 | /** |
1343 | * drbd_send_ack() - Sends an ack packet | 1348 | * drbd_send_ack() - Sends an ack packet |
1344 | * @mdev: DRBD device | 1349 | * @device: DRBD device |
1345 | * @cmd: packet command code | 1350 | * @cmd: packet command code |
1346 | * @peer_req: peer request | 1351 | * @peer_req: peer request |
1347 | */ | 1352 | */ |
1348 | int drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd, | 1353 | int drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1349 | struct drbd_peer_request *peer_req) | 1354 | struct drbd_peer_request *peer_req) |
1350 | { | 1355 | { |
1351 | return _drbd_send_ack(mdev, cmd, | 1356 | return _drbd_send_ack(peer_device, cmd, |
1352 | cpu_to_be64(peer_req->i.sector), | 1357 | cpu_to_be64(peer_req->i.sector), |
1353 | cpu_to_be32(peer_req->i.size), | 1358 | cpu_to_be32(peer_req->i.size), |
1354 | peer_req->block_id); | 1359 | peer_req->block_id); |
@@ -1356,32 +1361,32 @@ int drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd, | |||
1356 | 1361 | ||
1357 | /* This function misuses the block_id field to signal if the blocks | 1362 | /* This function misuses the block_id field to signal if the blocks |
1358 | * are is sync or not. */ | 1363 | * are is sync or not. */ |
1359 | int drbd_send_ack_ex(struct drbd_conf *mdev, enum drbd_packet cmd, | 1364 | int drbd_send_ack_ex(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1360 | sector_t sector, int blksize, u64 block_id) | 1365 | sector_t sector, int blksize, u64 block_id) |
1361 | { | 1366 | { |
1362 | return _drbd_send_ack(mdev, cmd, | 1367 | return _drbd_send_ack(peer_device, cmd, |
1363 | cpu_to_be64(sector), | 1368 | cpu_to_be64(sector), |
1364 | cpu_to_be32(blksize), | 1369 | cpu_to_be32(blksize), |
1365 | cpu_to_be64(block_id)); | 1370 | cpu_to_be64(block_id)); |
1366 | } | 1371 | } |
1367 | 1372 | ||
1368 | int drbd_send_drequest(struct drbd_conf *mdev, int cmd, | 1373 | int drbd_send_drequest(struct drbd_peer_device *peer_device, int cmd, |
1369 | sector_t sector, int size, u64 block_id) | 1374 | sector_t sector, int size, u64 block_id) |
1370 | { | 1375 | { |
1371 | struct drbd_socket *sock; | 1376 | struct drbd_socket *sock; |
1372 | struct p_block_req *p; | 1377 | struct p_block_req *p; |
1373 | 1378 | ||
1374 | sock = &mdev->tconn->data; | 1379 | sock = &peer_device->connection->data; |
1375 | p = drbd_prepare_command(mdev, sock); | 1380 | p = drbd_prepare_command(peer_device, sock); |
1376 | if (!p) | 1381 | if (!p) |
1377 | return -EIO; | 1382 | return -EIO; |
1378 | p->sector = cpu_to_be64(sector); | 1383 | p->sector = cpu_to_be64(sector); |
1379 | p->block_id = block_id; | 1384 | p->block_id = block_id; |
1380 | p->blksize = cpu_to_be32(size); | 1385 | p->blksize = cpu_to_be32(size); |
1381 | return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0); | 1386 | return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0); |
1382 | } | 1387 | } |
1383 | 1388 | ||
1384 | int drbd_send_drequest_csum(struct drbd_conf *mdev, sector_t sector, int size, | 1389 | int drbd_send_drequest_csum(struct drbd_peer_device *peer_device, sector_t sector, int size, |
1385 | void *digest, int digest_size, enum drbd_packet cmd) | 1390 | void *digest, int digest_size, enum drbd_packet cmd) |
1386 | { | 1391 | { |
1387 | struct drbd_socket *sock; | 1392 | struct drbd_socket *sock; |
@@ -1389,64 +1394,63 @@ int drbd_send_drequest_csum(struct drbd_conf *mdev, sector_t sector, int size, | |||
1389 | 1394 | ||
1390 | /* FIXME: Put the digest into the preallocated socket buffer. */ | 1395 | /* FIXME: Put the digest into the preallocated socket buffer. */ |
1391 | 1396 | ||
1392 | sock = &mdev->tconn->data; | 1397 | sock = &peer_device->connection->data; |
1393 | p = drbd_prepare_command(mdev, sock); | 1398 | p = drbd_prepare_command(peer_device, sock); |
1394 | if (!p) | 1399 | if (!p) |
1395 | return -EIO; | 1400 | return -EIO; |
1396 | p->sector = cpu_to_be64(sector); | 1401 | p->sector = cpu_to_be64(sector); |
1397 | p->block_id = ID_SYNCER /* unused */; | 1402 | p->block_id = ID_SYNCER /* unused */; |
1398 | p->blksize = cpu_to_be32(size); | 1403 | p->blksize = cpu_to_be32(size); |
1399 | return drbd_send_command(mdev, sock, cmd, sizeof(*p), | 1404 | return drbd_send_command(peer_device, sock, cmd, sizeof(*p), digest, digest_size); |
1400 | digest, digest_size); | ||
1401 | } | 1405 | } |
1402 | 1406 | ||
1403 | int drbd_send_ov_request(struct drbd_conf *mdev, sector_t sector, int size) | 1407 | int drbd_send_ov_request(struct drbd_peer_device *peer_device, sector_t sector, int size) |
1404 | { | 1408 | { |
1405 | struct drbd_socket *sock; | 1409 | struct drbd_socket *sock; |
1406 | struct p_block_req *p; | 1410 | struct p_block_req *p; |
1407 | 1411 | ||
1408 | sock = &mdev->tconn->data; | 1412 | sock = &peer_device->connection->data; |
1409 | p = drbd_prepare_command(mdev, sock); | 1413 | p = drbd_prepare_command(peer_device, sock); |
1410 | if (!p) | 1414 | if (!p) |
1411 | return -EIO; | 1415 | return -EIO; |
1412 | p->sector = cpu_to_be64(sector); | 1416 | p->sector = cpu_to_be64(sector); |
1413 | p->block_id = ID_SYNCER /* unused */; | 1417 | p->block_id = ID_SYNCER /* unused */; |
1414 | p->blksize = cpu_to_be32(size); | 1418 | p->blksize = cpu_to_be32(size); |
1415 | return drbd_send_command(mdev, sock, P_OV_REQUEST, sizeof(*p), NULL, 0); | 1419 | return drbd_send_command(peer_device, sock, P_OV_REQUEST, sizeof(*p), NULL, 0); |
1416 | } | 1420 | } |
1417 | 1421 | ||
1418 | /* called on sndtimeo | 1422 | /* called on sndtimeo |
1419 | * returns false if we should retry, | 1423 | * returns false if we should retry, |
1420 | * true if we think connection is dead | 1424 | * true if we think connection is dead |
1421 | */ | 1425 | */ |
1422 | static int we_should_drop_the_connection(struct drbd_tconn *tconn, struct socket *sock) | 1426 | static int we_should_drop_the_connection(struct drbd_connection *connection, struct socket *sock) |
1423 | { | 1427 | { |
1424 | int drop_it; | 1428 | int drop_it; |
1425 | /* long elapsed = (long)(jiffies - mdev->last_received); */ | 1429 | /* long elapsed = (long)(jiffies - device->last_received); */ |
1426 | 1430 | ||
1427 | drop_it = tconn->meta.socket == sock | 1431 | drop_it = connection->meta.socket == sock |
1428 | || !tconn->asender.task | 1432 | || !connection->asender.task |
1429 | || get_t_state(&tconn->asender) != RUNNING | 1433 | || get_t_state(&connection->asender) != RUNNING |
1430 | || tconn->cstate < C_WF_REPORT_PARAMS; | 1434 | || connection->cstate < C_WF_REPORT_PARAMS; |
1431 | 1435 | ||
1432 | if (drop_it) | 1436 | if (drop_it) |
1433 | return true; | 1437 | return true; |
1434 | 1438 | ||
1435 | drop_it = !--tconn->ko_count; | 1439 | drop_it = !--connection->ko_count; |
1436 | if (!drop_it) { | 1440 | if (!drop_it) { |
1437 | conn_err(tconn, "[%s/%d] sock_sendmsg time expired, ko = %u\n", | 1441 | drbd_err(connection, "[%s/%d] sock_sendmsg time expired, ko = %u\n", |
1438 | current->comm, current->pid, tconn->ko_count); | 1442 | current->comm, current->pid, connection->ko_count); |
1439 | request_ping(tconn); | 1443 | request_ping(connection); |
1440 | } | 1444 | } |
1441 | 1445 | ||
1442 | return drop_it; /* && (mdev->state == R_PRIMARY) */; | 1446 | return drop_it; /* && (device->state == R_PRIMARY) */; |
1443 | } | 1447 | } |
1444 | 1448 | ||
1445 | static void drbd_update_congested(struct drbd_tconn *tconn) | 1449 | static void drbd_update_congested(struct drbd_connection *connection) |
1446 | { | 1450 | { |
1447 | struct sock *sk = tconn->data.socket->sk; | 1451 | struct sock *sk = connection->data.socket->sk; |
1448 | if (sk->sk_wmem_queued > sk->sk_sndbuf * 4 / 5) | 1452 | if (sk->sk_wmem_queued > sk->sk_sndbuf * 4 / 5) |
1449 | set_bit(NET_CONGESTED, &tconn->flags); | 1453 | set_bit(NET_CONGESTED, &connection->flags); |
1450 | } | 1454 | } |
1451 | 1455 | ||
1452 | /* The idea of sendpage seems to be to put some kind of reference | 1456 | /* The idea of sendpage seems to be to put some kind of reference |
@@ -1470,26 +1474,26 @@ static void drbd_update_congested(struct drbd_tconn *tconn) | |||
1470 | * As a workaround, we disable sendpage on pages | 1474 | * As a workaround, we disable sendpage on pages |
1471 | * with page_count == 0 or PageSlab. | 1475 | * with page_count == 0 or PageSlab. |
1472 | */ | 1476 | */ |
1473 | static int _drbd_no_send_page(struct drbd_conf *mdev, struct page *page, | 1477 | static int _drbd_no_send_page(struct drbd_peer_device *peer_device, struct page *page, |
1474 | int offset, size_t size, unsigned msg_flags) | 1478 | int offset, size_t size, unsigned msg_flags) |
1475 | { | 1479 | { |
1476 | struct socket *socket; | 1480 | struct socket *socket; |
1477 | void *addr; | 1481 | void *addr; |
1478 | int err; | 1482 | int err; |
1479 | 1483 | ||
1480 | socket = mdev->tconn->data.socket; | 1484 | socket = peer_device->connection->data.socket; |
1481 | addr = kmap(page) + offset; | 1485 | addr = kmap(page) + offset; |
1482 | err = drbd_send_all(mdev->tconn, socket, addr, size, msg_flags); | 1486 | err = drbd_send_all(peer_device->connection, socket, addr, size, msg_flags); |
1483 | kunmap(page); | 1487 | kunmap(page); |
1484 | if (!err) | 1488 | if (!err) |
1485 | mdev->send_cnt += size >> 9; | 1489 | peer_device->device->send_cnt += size >> 9; |
1486 | return err; | 1490 | return err; |
1487 | } | 1491 | } |
1488 | 1492 | ||
1489 | static int _drbd_send_page(struct drbd_conf *mdev, struct page *page, | 1493 | static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *page, |
1490 | int offset, size_t size, unsigned msg_flags) | 1494 | int offset, size_t size, unsigned msg_flags) |
1491 | { | 1495 | { |
1492 | struct socket *socket = mdev->tconn->data.socket; | 1496 | struct socket *socket = peer_device->connection->data.socket; |
1493 | mm_segment_t oldfs = get_fs(); | 1497 | mm_segment_t oldfs = get_fs(); |
1494 | int len = size; | 1498 | int len = size; |
1495 | int err = -EIO; | 1499 | int err = -EIO; |
@@ -1501,10 +1505,10 @@ static int _drbd_send_page(struct drbd_conf *mdev, struct page *page, | |||
1501 | * __page_cache_release a page that would actually still be referenced | 1505 | * __page_cache_release a page that would actually still be referenced |
1502 | * by someone, leading to some obscure delayed Oops somewhere else. */ | 1506 | * by someone, leading to some obscure delayed Oops somewhere else. */ |
1503 | if (disable_sendpage || (page_count(page) < 1) || PageSlab(page)) | 1507 | if (disable_sendpage || (page_count(page) < 1) || PageSlab(page)) |
1504 | return _drbd_no_send_page(mdev, page, offset, size, msg_flags); | 1508 | return _drbd_no_send_page(peer_device, page, offset, size, msg_flags); |
1505 | 1509 | ||
1506 | msg_flags |= MSG_NOSIGNAL; | 1510 | msg_flags |= MSG_NOSIGNAL; |
1507 | drbd_update_congested(mdev->tconn); | 1511 | drbd_update_congested(peer_device->connection); |
1508 | set_fs(KERNEL_DS); | 1512 | set_fs(KERNEL_DS); |
1509 | do { | 1513 | do { |
1510 | int sent; | 1514 | int sent; |
@@ -1512,11 +1516,11 @@ static int _drbd_send_page(struct drbd_conf *mdev, struct page *page, | |||
1512 | sent = socket->ops->sendpage(socket, page, offset, len, msg_flags); | 1516 | sent = socket->ops->sendpage(socket, page, offset, len, msg_flags); |
1513 | if (sent <= 0) { | 1517 | if (sent <= 0) { |
1514 | if (sent == -EAGAIN) { | 1518 | if (sent == -EAGAIN) { |
1515 | if (we_should_drop_the_connection(mdev->tconn, socket)) | 1519 | if (we_should_drop_the_connection(peer_device->connection, socket)) |
1516 | break; | 1520 | break; |
1517 | continue; | 1521 | continue; |
1518 | } | 1522 | } |
1519 | dev_warn(DEV, "%s: size=%d len=%d sent=%d\n", | 1523 | drbd_warn(peer_device->device, "%s: size=%d len=%d sent=%d\n", |
1520 | __func__, (int)size, len, sent); | 1524 | __func__, (int)size, len, sent); |
1521 | if (sent < 0) | 1525 | if (sent < 0) |
1522 | err = sent; | 1526 | err = sent; |
@@ -1524,18 +1528,18 @@ static int _drbd_send_page(struct drbd_conf *mdev, struct page *page, | |||
1524 | } | 1528 | } |
1525 | len -= sent; | 1529 | len -= sent; |
1526 | offset += sent; | 1530 | offset += sent; |
1527 | } while (len > 0 /* THINK && mdev->cstate >= C_CONNECTED*/); | 1531 | } while (len > 0 /* THINK && device->cstate >= C_CONNECTED*/); |
1528 | set_fs(oldfs); | 1532 | set_fs(oldfs); |
1529 | clear_bit(NET_CONGESTED, &mdev->tconn->flags); | 1533 | clear_bit(NET_CONGESTED, &peer_device->connection->flags); |
1530 | 1534 | ||
1531 | if (len == 0) { | 1535 | if (len == 0) { |
1532 | err = 0; | 1536 | err = 0; |
1533 | mdev->send_cnt += size >> 9; | 1537 | peer_device->device->send_cnt += size >> 9; |
1534 | } | 1538 | } |
1535 | return err; | 1539 | return err; |
1536 | } | 1540 | } |
1537 | 1541 | ||
1538 | static int _drbd_send_bio(struct drbd_conf *mdev, struct bio *bio) | 1542 | static int _drbd_send_bio(struct drbd_peer_device *peer_device, struct bio *bio) |
1539 | { | 1543 | { |
1540 | struct bio_vec bvec; | 1544 | struct bio_vec bvec; |
1541 | struct bvec_iter iter; | 1545 | struct bvec_iter iter; |
@@ -1544,7 +1548,7 @@ static int _drbd_send_bio(struct drbd_conf *mdev, struct bio *bio) | |||
1544 | bio_for_each_segment(bvec, bio, iter) { | 1548 | bio_for_each_segment(bvec, bio, iter) { |
1545 | int err; | 1549 | int err; |
1546 | 1550 | ||
1547 | err = _drbd_no_send_page(mdev, bvec.bv_page, | 1551 | err = _drbd_no_send_page(peer_device, bvec.bv_page, |
1548 | bvec.bv_offset, bvec.bv_len, | 1552 | bvec.bv_offset, bvec.bv_len, |
1549 | bio_iter_last(bvec, iter) | 1553 | bio_iter_last(bvec, iter) |
1550 | ? 0 : MSG_MORE); | 1554 | ? 0 : MSG_MORE); |
@@ -1554,7 +1558,7 @@ static int _drbd_send_bio(struct drbd_conf *mdev, struct bio *bio) | |||
1554 | return 0; | 1558 | return 0; |
1555 | } | 1559 | } |
1556 | 1560 | ||
1557 | static int _drbd_send_zc_bio(struct drbd_conf *mdev, struct bio *bio) | 1561 | static int _drbd_send_zc_bio(struct drbd_peer_device *peer_device, struct bio *bio) |
1558 | { | 1562 | { |
1559 | struct bio_vec bvec; | 1563 | struct bio_vec bvec; |
1560 | struct bvec_iter iter; | 1564 | struct bvec_iter iter; |
@@ -1563,7 +1567,7 @@ static int _drbd_send_zc_bio(struct drbd_conf *mdev, struct bio *bio) | |||
1563 | bio_for_each_segment(bvec, bio, iter) { | 1567 | bio_for_each_segment(bvec, bio, iter) { |
1564 | int err; | 1568 | int err; |
1565 | 1569 | ||
1566 | err = _drbd_send_page(mdev, bvec.bv_page, | 1570 | err = _drbd_send_page(peer_device, bvec.bv_page, |
1567 | bvec.bv_offset, bvec.bv_len, | 1571 | bvec.bv_offset, bvec.bv_len, |
1568 | bio_iter_last(bvec, iter) ? 0 : MSG_MORE); | 1572 | bio_iter_last(bvec, iter) ? 0 : MSG_MORE); |
1569 | if (err) | 1573 | if (err) |
@@ -1572,7 +1576,7 @@ static int _drbd_send_zc_bio(struct drbd_conf *mdev, struct bio *bio) | |||
1572 | return 0; | 1576 | return 0; |
1573 | } | 1577 | } |
1574 | 1578 | ||
1575 | static int _drbd_send_zc_ee(struct drbd_conf *mdev, | 1579 | static int _drbd_send_zc_ee(struct drbd_peer_device *peer_device, |
1576 | struct drbd_peer_request *peer_req) | 1580 | struct drbd_peer_request *peer_req) |
1577 | { | 1581 | { |
1578 | struct page *page = peer_req->pages; | 1582 | struct page *page = peer_req->pages; |
@@ -1583,7 +1587,7 @@ static int _drbd_send_zc_ee(struct drbd_conf *mdev, | |||
1583 | page_chain_for_each(page) { | 1587 | page_chain_for_each(page) { |
1584 | unsigned l = min_t(unsigned, len, PAGE_SIZE); | 1588 | unsigned l = min_t(unsigned, len, PAGE_SIZE); |
1585 | 1589 | ||
1586 | err = _drbd_send_page(mdev, page, 0, l, | 1590 | err = _drbd_send_page(peer_device, page, 0, l, |
1587 | page_chain_next(page) ? MSG_MORE : 0); | 1591 | page_chain_next(page) ? MSG_MORE : 0); |
1588 | if (err) | 1592 | if (err) |
1589 | return err; | 1593 | return err; |
@@ -1592,9 +1596,9 @@ static int _drbd_send_zc_ee(struct drbd_conf *mdev, | |||
1592 | return 0; | 1596 | return 0; |
1593 | } | 1597 | } |
1594 | 1598 | ||
1595 | static u32 bio_flags_to_wire(struct drbd_conf *mdev, unsigned long bi_rw) | 1599 | static u32 bio_flags_to_wire(struct drbd_connection *connection, unsigned long bi_rw) |
1596 | { | 1600 | { |
1597 | if (mdev->tconn->agreed_pro_version >= 95) | 1601 | if (connection->agreed_pro_version >= 95) |
1598 | return (bi_rw & REQ_SYNC ? DP_RW_SYNC : 0) | | 1602 | return (bi_rw & REQ_SYNC ? DP_RW_SYNC : 0) | |
1599 | (bi_rw & REQ_FUA ? DP_FUA : 0) | | 1603 | (bi_rw & REQ_FUA ? DP_FUA : 0) | |
1600 | (bi_rw & REQ_FLUSH ? DP_FLUSH : 0) | | 1604 | (bi_rw & REQ_FLUSH ? DP_FLUSH : 0) | |
@@ -1606,28 +1610,30 @@ static u32 bio_flags_to_wire(struct drbd_conf *mdev, unsigned long bi_rw) | |||
1606 | /* Used to send write requests | 1610 | /* Used to send write requests |
1607 | * R_PRIMARY -> Peer (P_DATA) | 1611 | * R_PRIMARY -> Peer (P_DATA) |
1608 | */ | 1612 | */ |
1609 | int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req) | 1613 | int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *req) |
1610 | { | 1614 | { |
1615 | struct drbd_device *device = peer_device->device; | ||
1611 | struct drbd_socket *sock; | 1616 | struct drbd_socket *sock; |
1612 | struct p_data *p; | 1617 | struct p_data *p; |
1613 | unsigned int dp_flags = 0; | 1618 | unsigned int dp_flags = 0; |
1614 | int dgs; | 1619 | int dgs; |
1615 | int err; | 1620 | int err; |
1616 | 1621 | ||
1617 | sock = &mdev->tconn->data; | 1622 | sock = &peer_device->connection->data; |
1618 | p = drbd_prepare_command(mdev, sock); | 1623 | p = drbd_prepare_command(peer_device, sock); |
1619 | dgs = mdev->tconn->integrity_tfm ? crypto_hash_digestsize(mdev->tconn->integrity_tfm) : 0; | 1624 | dgs = peer_device->connection->integrity_tfm ? |
1625 | crypto_hash_digestsize(peer_device->connection->integrity_tfm) : 0; | ||
1620 | 1626 | ||
1621 | if (!p) | 1627 | if (!p) |
1622 | return -EIO; | 1628 | return -EIO; |
1623 | p->sector = cpu_to_be64(req->i.sector); | 1629 | p->sector = cpu_to_be64(req->i.sector); |
1624 | p->block_id = (unsigned long)req; | 1630 | p->block_id = (unsigned long)req; |
1625 | p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq)); | 1631 | p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq)); |
1626 | dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw); | 1632 | dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw); |
1627 | if (mdev->state.conn >= C_SYNC_SOURCE && | 1633 | if (device->state.conn >= C_SYNC_SOURCE && |
1628 | mdev->state.conn <= C_PAUSED_SYNC_T) | 1634 | device->state.conn <= C_PAUSED_SYNC_T) |
1629 | dp_flags |= DP_MAY_SET_IN_SYNC; | 1635 | dp_flags |= DP_MAY_SET_IN_SYNC; |
1630 | if (mdev->tconn->agreed_pro_version >= 100) { | 1636 | if (peer_device->connection->agreed_pro_version >= 100) { |
1631 | if (req->rq_state & RQ_EXP_RECEIVE_ACK) | 1637 | if (req->rq_state & RQ_EXP_RECEIVE_ACK) |
1632 | dp_flags |= DP_SEND_RECEIVE_ACK; | 1638 | dp_flags |= DP_SEND_RECEIVE_ACK; |
1633 | if (req->rq_state & RQ_EXP_WRITE_ACK) | 1639 | if (req->rq_state & RQ_EXP_WRITE_ACK) |
@@ -1635,8 +1641,8 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req) | |||
1635 | } | 1641 | } |
1636 | p->dp_flags = cpu_to_be32(dp_flags); | 1642 | p->dp_flags = cpu_to_be32(dp_flags); |
1637 | if (dgs) | 1643 | if (dgs) |
1638 | drbd_csum_bio(mdev, mdev->tconn->integrity_tfm, req->master_bio, p + 1); | 1644 | drbd_csum_bio(peer_device->connection->integrity_tfm, req->master_bio, p + 1); |
1639 | err = __send_command(mdev->tconn, mdev->vnr, sock, P_DATA, sizeof(*p) + dgs, NULL, req->i.size); | 1645 | err = __send_command(peer_device->connection, device->vnr, sock, P_DATA, sizeof(*p) + dgs, NULL, req->i.size); |
1640 | if (!err) { | 1646 | if (!err) { |
1641 | /* For protocol A, we have to memcpy the payload into | 1647 | /* For protocol A, we have to memcpy the payload into |
1642 | * socket buffers, as we may complete right away | 1648 | * socket buffers, as we may complete right away |
@@ -1650,18 +1656,18 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req) | |||
1650 | * receiving side, we sure have detected corruption elsewhere. | 1656 | * receiving side, we sure have detected corruption elsewhere. |
1651 | */ | 1657 | */ |
1652 | if (!(req->rq_state & (RQ_EXP_RECEIVE_ACK | RQ_EXP_WRITE_ACK)) || dgs) | 1658 | if (!(req->rq_state & (RQ_EXP_RECEIVE_ACK | RQ_EXP_WRITE_ACK)) || dgs) |
1653 | err = _drbd_send_bio(mdev, req->master_bio); | 1659 | err = _drbd_send_bio(peer_device, req->master_bio); |
1654 | else | 1660 | else |
1655 | err = _drbd_send_zc_bio(mdev, req->master_bio); | 1661 | err = _drbd_send_zc_bio(peer_device, req->master_bio); |
1656 | 1662 | ||
1657 | /* double check digest, sometimes buffers have been modified in flight. */ | 1663 | /* double check digest, sometimes buffers have been modified in flight. */ |
1658 | if (dgs > 0 && dgs <= 64) { | 1664 | if (dgs > 0 && dgs <= 64) { |
1659 | /* 64 byte, 512 bit, is the largest digest size | 1665 | /* 64 byte, 512 bit, is the largest digest size |
1660 | * currently supported in kernel crypto. */ | 1666 | * currently supported in kernel crypto. */ |
1661 | unsigned char digest[64]; | 1667 | unsigned char digest[64]; |
1662 | drbd_csum_bio(mdev, mdev->tconn->integrity_tfm, req->master_bio, digest); | 1668 | drbd_csum_bio(peer_device->connection->integrity_tfm, req->master_bio, digest); |
1663 | if (memcmp(p + 1, digest, dgs)) { | 1669 | if (memcmp(p + 1, digest, dgs)) { |
1664 | dev_warn(DEV, | 1670 | drbd_warn(device, |
1665 | "Digest mismatch, buffer modified by upper layers during write: %llus +%u\n", | 1671 | "Digest mismatch, buffer modified by upper layers during write: %llus +%u\n", |
1666 | (unsigned long long)req->i.sector, req->i.size); | 1672 | (unsigned long long)req->i.sector, req->i.size); |
1667 | } | 1673 | } |
@@ -1678,18 +1684,20 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req) | |||
1678 | * Peer -> (diskless) R_PRIMARY (P_DATA_REPLY) | 1684 | * Peer -> (diskless) R_PRIMARY (P_DATA_REPLY) |
1679 | * C_SYNC_SOURCE -> C_SYNC_TARGET (P_RS_DATA_REPLY) | 1685 | * C_SYNC_SOURCE -> C_SYNC_TARGET (P_RS_DATA_REPLY) |
1680 | */ | 1686 | */ |
1681 | int drbd_send_block(struct drbd_conf *mdev, enum drbd_packet cmd, | 1687 | int drbd_send_block(struct drbd_peer_device *peer_device, enum drbd_packet cmd, |
1682 | struct drbd_peer_request *peer_req) | 1688 | struct drbd_peer_request *peer_req) |
1683 | { | 1689 | { |
1690 | struct drbd_device *device = peer_device->device; | ||
1684 | struct drbd_socket *sock; | 1691 | struct drbd_socket *sock; |
1685 | struct p_data *p; | 1692 | struct p_data *p; |
1686 | int err; | 1693 | int err; |
1687 | int dgs; | 1694 | int dgs; |
1688 | 1695 | ||
1689 | sock = &mdev->tconn->data; | 1696 | sock = &peer_device->connection->data; |
1690 | p = drbd_prepare_command(mdev, sock); | 1697 | p = drbd_prepare_command(peer_device, sock); |
1691 | 1698 | ||
1692 | dgs = mdev->tconn->integrity_tfm ? crypto_hash_digestsize(mdev->tconn->integrity_tfm) : 0; | 1699 | dgs = peer_device->connection->integrity_tfm ? |
1700 | crypto_hash_digestsize(peer_device->connection->integrity_tfm) : 0; | ||
1693 | 1701 | ||
1694 | if (!p) | 1702 | if (!p) |
1695 | return -EIO; | 1703 | return -EIO; |
@@ -1698,27 +1706,27 @@ int drbd_send_block(struct drbd_conf *mdev, enum drbd_packet cmd, | |||
1698 | p->seq_num = 0; /* unused */ | 1706 | p->seq_num = 0; /* unused */ |
1699 | p->dp_flags = 0; | 1707 | p->dp_flags = 0; |
1700 | if (dgs) | 1708 | if (dgs) |
1701 | drbd_csum_ee(mdev, mdev->tconn->integrity_tfm, peer_req, p + 1); | 1709 | drbd_csum_ee(peer_device->connection->integrity_tfm, peer_req, p + 1); |
1702 | err = __send_command(mdev->tconn, mdev->vnr, sock, cmd, sizeof(*p) + dgs, NULL, peer_req->i.size); | 1710 | err = __send_command(peer_device->connection, device->vnr, sock, cmd, sizeof(*p) + dgs, NULL, peer_req->i.size); |
1703 | if (!err) | 1711 | if (!err) |
1704 | err = _drbd_send_zc_ee(mdev, peer_req); | 1712 | err = _drbd_send_zc_ee(peer_device, peer_req); |
1705 | mutex_unlock(&sock->mutex); /* locked by drbd_prepare_command() */ | 1713 | mutex_unlock(&sock->mutex); /* locked by drbd_prepare_command() */ |
1706 | 1714 | ||
1707 | return err; | 1715 | return err; |
1708 | } | 1716 | } |
1709 | 1717 | ||
1710 | int drbd_send_out_of_sync(struct drbd_conf *mdev, struct drbd_request *req) | 1718 | int drbd_send_out_of_sync(struct drbd_peer_device *peer_device, struct drbd_request *req) |
1711 | { | 1719 | { |
1712 | struct drbd_socket *sock; | 1720 | struct drbd_socket *sock; |
1713 | struct p_block_desc *p; | 1721 | struct p_block_desc *p; |
1714 | 1722 | ||
1715 | sock = &mdev->tconn->data; | 1723 | sock = &peer_device->connection->data; |
1716 | p = drbd_prepare_command(mdev, sock); | 1724 | p = drbd_prepare_command(peer_device, sock); |
1717 | if (!p) | 1725 | if (!p) |
1718 | return -EIO; | 1726 | return -EIO; |
1719 | p->sector = cpu_to_be64(req->i.sector); | 1727 | p->sector = cpu_to_be64(req->i.sector); |
1720 | p->blksize = cpu_to_be32(req->i.size); | 1728 | p->blksize = cpu_to_be32(req->i.size); |
1721 | return drbd_send_command(mdev, sock, P_OUT_OF_SYNC, sizeof(*p), NULL, 0); | 1729 | return drbd_send_command(peer_device, sock, P_OUT_OF_SYNC, sizeof(*p), NULL, 0); |
1722 | } | 1730 | } |
1723 | 1731 | ||
1724 | /* | 1732 | /* |
@@ -1737,7 +1745,7 @@ int drbd_send_out_of_sync(struct drbd_conf *mdev, struct drbd_request *req) | |||
1737 | /* | 1745 | /* |
1738 | * you must have down()ed the appropriate [m]sock_mutex elsewhere! | 1746 | * you must have down()ed the appropriate [m]sock_mutex elsewhere! |
1739 | */ | 1747 | */ |
1740 | int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | 1748 | int drbd_send(struct drbd_connection *connection, struct socket *sock, |
1741 | void *buf, size_t size, unsigned msg_flags) | 1749 | void *buf, size_t size, unsigned msg_flags) |
1742 | { | 1750 | { |
1743 | struct kvec iov; | 1751 | struct kvec iov; |
@@ -1758,11 +1766,11 @@ int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | |||
1758 | msg.msg_controllen = 0; | 1766 | msg.msg_controllen = 0; |
1759 | msg.msg_flags = msg_flags | MSG_NOSIGNAL; | 1767 | msg.msg_flags = msg_flags | MSG_NOSIGNAL; |
1760 | 1768 | ||
1761 | if (sock == tconn->data.socket) { | 1769 | if (sock == connection->data.socket) { |
1762 | rcu_read_lock(); | 1770 | rcu_read_lock(); |
1763 | tconn->ko_count = rcu_dereference(tconn->net_conf)->ko_count; | 1771 | connection->ko_count = rcu_dereference(connection->net_conf)->ko_count; |
1764 | rcu_read_unlock(); | 1772 | rcu_read_unlock(); |
1765 | drbd_update_congested(tconn); | 1773 | drbd_update_congested(connection); |
1766 | } | 1774 | } |
1767 | do { | 1775 | do { |
1768 | /* STRANGE | 1776 | /* STRANGE |
@@ -1776,7 +1784,7 @@ int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | |||
1776 | */ | 1784 | */ |
1777 | rv = kernel_sendmsg(sock, &msg, &iov, 1, size); | 1785 | rv = kernel_sendmsg(sock, &msg, &iov, 1, size); |
1778 | if (rv == -EAGAIN) { | 1786 | if (rv == -EAGAIN) { |
1779 | if (we_should_drop_the_connection(tconn, sock)) | 1787 | if (we_should_drop_the_connection(connection, sock)) |
1780 | break; | 1788 | break; |
1781 | else | 1789 | else |
1782 | continue; | 1790 | continue; |
@@ -1792,17 +1800,17 @@ int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | |||
1792 | iov.iov_len -= rv; | 1800 | iov.iov_len -= rv; |
1793 | } while (sent < size); | 1801 | } while (sent < size); |
1794 | 1802 | ||
1795 | if (sock == tconn->data.socket) | 1803 | if (sock == connection->data.socket) |
1796 | clear_bit(NET_CONGESTED, &tconn->flags); | 1804 | clear_bit(NET_CONGESTED, &connection->flags); |
1797 | 1805 | ||
1798 | if (rv <= 0) { | 1806 | if (rv <= 0) { |
1799 | if (rv != -EAGAIN) { | 1807 | if (rv != -EAGAIN) { |
1800 | conn_err(tconn, "%s_sendmsg returned %d\n", | 1808 | drbd_err(connection, "%s_sendmsg returned %d\n", |
1801 | sock == tconn->meta.socket ? "msock" : "sock", | 1809 | sock == connection->meta.socket ? "msock" : "sock", |
1802 | rv); | 1810 | rv); |
1803 | conn_request_state(tconn, NS(conn, C_BROKEN_PIPE), CS_HARD); | 1811 | conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD); |
1804 | } else | 1812 | } else |
1805 | conn_request_state(tconn, NS(conn, C_TIMEOUT), CS_HARD); | 1813 | conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD); |
1806 | } | 1814 | } |
1807 | 1815 | ||
1808 | return sent; | 1816 | return sent; |
@@ -1813,12 +1821,12 @@ int drbd_send(struct drbd_tconn *tconn, struct socket *sock, | |||
1813 | * | 1821 | * |
1814 | * Returns 0 upon success and a negative error value otherwise. | 1822 | * Returns 0 upon success and a negative error value otherwise. |
1815 | */ | 1823 | */ |
1816 | int drbd_send_all(struct drbd_tconn *tconn, struct socket *sock, void *buffer, | 1824 | int drbd_send_all(struct drbd_connection *connection, struct socket *sock, void *buffer, |
1817 | size_t size, unsigned msg_flags) | 1825 | size_t size, unsigned msg_flags) |
1818 | { | 1826 | { |
1819 | int err; | 1827 | int err; |
1820 | 1828 | ||
1821 | err = drbd_send(tconn, sock, buffer, size, msg_flags); | 1829 | err = drbd_send(connection, sock, buffer, size, msg_flags); |
1822 | if (err < 0) | 1830 | if (err < 0) |
1823 | return err; | 1831 | return err; |
1824 | if (err != size) | 1832 | if (err != size) |
@@ -1828,16 +1836,16 @@ int drbd_send_all(struct drbd_tconn *tconn, struct socket *sock, void *buffer, | |||
1828 | 1836 | ||
1829 | static int drbd_open(struct block_device *bdev, fmode_t mode) | 1837 | static int drbd_open(struct block_device *bdev, fmode_t mode) |
1830 | { | 1838 | { |
1831 | struct drbd_conf *mdev = bdev->bd_disk->private_data; | 1839 | struct drbd_device *device = bdev->bd_disk->private_data; |
1832 | unsigned long flags; | 1840 | unsigned long flags; |
1833 | int rv = 0; | 1841 | int rv = 0; |
1834 | 1842 | ||
1835 | mutex_lock(&drbd_main_mutex); | 1843 | mutex_lock(&drbd_main_mutex); |
1836 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 1844 | spin_lock_irqsave(&device->resource->req_lock, flags); |
1837 | /* to have a stable mdev->state.role | 1845 | /* to have a stable device->state.role |
1838 | * and no race with updating open_cnt */ | 1846 | * and no race with updating open_cnt */ |
1839 | 1847 | ||
1840 | if (mdev->state.role != R_PRIMARY) { | 1848 | if (device->state.role != R_PRIMARY) { |
1841 | if (mode & FMODE_WRITE) | 1849 | if (mode & FMODE_WRITE) |
1842 | rv = -EROFS; | 1850 | rv = -EROFS; |
1843 | else if (!allow_oos) | 1851 | else if (!allow_oos) |
@@ -1845,8 +1853,8 @@ static int drbd_open(struct block_device *bdev, fmode_t mode) | |||
1845 | } | 1853 | } |
1846 | 1854 | ||
1847 | if (!rv) | 1855 | if (!rv) |
1848 | mdev->open_cnt++; | 1856 | device->open_cnt++; |
1849 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 1857 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
1850 | mutex_unlock(&drbd_main_mutex); | 1858 | mutex_unlock(&drbd_main_mutex); |
1851 | 1859 | ||
1852 | return rv; | 1860 | return rv; |
@@ -1854,17 +1862,17 @@ static int drbd_open(struct block_device *bdev, fmode_t mode) | |||
1854 | 1862 | ||
1855 | static void drbd_release(struct gendisk *gd, fmode_t mode) | 1863 | static void drbd_release(struct gendisk *gd, fmode_t mode) |
1856 | { | 1864 | { |
1857 | struct drbd_conf *mdev = gd->private_data; | 1865 | struct drbd_device *device = gd->private_data; |
1858 | mutex_lock(&drbd_main_mutex); | 1866 | mutex_lock(&drbd_main_mutex); |
1859 | mdev->open_cnt--; | 1867 | device->open_cnt--; |
1860 | mutex_unlock(&drbd_main_mutex); | 1868 | mutex_unlock(&drbd_main_mutex); |
1861 | } | 1869 | } |
1862 | 1870 | ||
1863 | static void drbd_set_defaults(struct drbd_conf *mdev) | 1871 | static void drbd_set_defaults(struct drbd_device *device) |
1864 | { | 1872 | { |
1865 | /* Beware! The actual layout differs | 1873 | /* Beware! The actual layout differs |
1866 | * between big endian and little endian */ | 1874 | * between big endian and little endian */ |
1867 | mdev->state = (union drbd_dev_state) { | 1875 | device->state = (union drbd_dev_state) { |
1868 | { .role = R_SECONDARY, | 1876 | { .role = R_SECONDARY, |
1869 | .peer = R_UNKNOWN, | 1877 | .peer = R_UNKNOWN, |
1870 | .conn = C_STANDALONE, | 1878 | .conn = C_STANDALONE, |
@@ -1873,130 +1881,123 @@ static void drbd_set_defaults(struct drbd_conf *mdev) | |||
1873 | } }; | 1881 | } }; |
1874 | } | 1882 | } |
1875 | 1883 | ||
1876 | void drbd_init_set_defaults(struct drbd_conf *mdev) | 1884 | void drbd_init_set_defaults(struct drbd_device *device) |
1877 | { | 1885 | { |
1878 | /* the memset(,0,) did most of this. | 1886 | /* the memset(,0,) did most of this. |
1879 | * note: only assignments, no allocation in here */ | 1887 | * note: only assignments, no allocation in here */ |
1880 | 1888 | ||
1881 | drbd_set_defaults(mdev); | 1889 | drbd_set_defaults(device); |
1882 | 1890 | ||
1883 | atomic_set(&mdev->ap_bio_cnt, 0); | 1891 | atomic_set(&device->ap_bio_cnt, 0); |
1884 | atomic_set(&mdev->ap_pending_cnt, 0); | 1892 | atomic_set(&device->ap_pending_cnt, 0); |
1885 | atomic_set(&mdev->rs_pending_cnt, 0); | 1893 | atomic_set(&device->rs_pending_cnt, 0); |
1886 | atomic_set(&mdev->unacked_cnt, 0); | 1894 | atomic_set(&device->unacked_cnt, 0); |
1887 | atomic_set(&mdev->local_cnt, 0); | 1895 | atomic_set(&device->local_cnt, 0); |
1888 | atomic_set(&mdev->pp_in_use_by_net, 0); | 1896 | atomic_set(&device->pp_in_use_by_net, 0); |
1889 | atomic_set(&mdev->rs_sect_in, 0); | 1897 | atomic_set(&device->rs_sect_in, 0); |
1890 | atomic_set(&mdev->rs_sect_ev, 0); | 1898 | atomic_set(&device->rs_sect_ev, 0); |
1891 | atomic_set(&mdev->ap_in_flight, 0); | 1899 | atomic_set(&device->ap_in_flight, 0); |
1892 | atomic_set(&mdev->md_io_in_use, 0); | 1900 | atomic_set(&device->md_io_in_use, 0); |
1893 | 1901 | ||
1894 | mutex_init(&mdev->own_state_mutex); | 1902 | mutex_init(&device->own_state_mutex); |
1895 | mdev->state_mutex = &mdev->own_state_mutex; | 1903 | device->state_mutex = &device->own_state_mutex; |
1896 | 1904 | ||
1897 | spin_lock_init(&mdev->al_lock); | 1905 | spin_lock_init(&device->al_lock); |
1898 | spin_lock_init(&mdev->peer_seq_lock); | 1906 | spin_lock_init(&device->peer_seq_lock); |
1899 | 1907 | ||
1900 | INIT_LIST_HEAD(&mdev->active_ee); | 1908 | INIT_LIST_HEAD(&device->active_ee); |
1901 | INIT_LIST_HEAD(&mdev->sync_ee); | 1909 | INIT_LIST_HEAD(&device->sync_ee); |
1902 | INIT_LIST_HEAD(&mdev->done_ee); | 1910 | INIT_LIST_HEAD(&device->done_ee); |
1903 | INIT_LIST_HEAD(&mdev->read_ee); | 1911 | INIT_LIST_HEAD(&device->read_ee); |
1904 | INIT_LIST_HEAD(&mdev->net_ee); | 1912 | INIT_LIST_HEAD(&device->net_ee); |
1905 | INIT_LIST_HEAD(&mdev->resync_reads); | 1913 | INIT_LIST_HEAD(&device->resync_reads); |
1906 | INIT_LIST_HEAD(&mdev->resync_work.list); | 1914 | INIT_LIST_HEAD(&device->resync_work.list); |
1907 | INIT_LIST_HEAD(&mdev->unplug_work.list); | 1915 | INIT_LIST_HEAD(&device->unplug_work.list); |
1908 | INIT_LIST_HEAD(&mdev->go_diskless.list); | 1916 | INIT_LIST_HEAD(&device->go_diskless.list); |
1909 | INIT_LIST_HEAD(&mdev->md_sync_work.list); | 1917 | INIT_LIST_HEAD(&device->md_sync_work.list); |
1910 | INIT_LIST_HEAD(&mdev->start_resync_work.list); | 1918 | INIT_LIST_HEAD(&device->start_resync_work.list); |
1911 | INIT_LIST_HEAD(&mdev->bm_io_work.w.list); | 1919 | INIT_LIST_HEAD(&device->bm_io_work.w.list); |
1912 | 1920 | ||
1913 | mdev->resync_work.cb = w_resync_timer; | 1921 | device->resync_work.cb = w_resync_timer; |
1914 | mdev->unplug_work.cb = w_send_write_hint; | 1922 | device->unplug_work.cb = w_send_write_hint; |
1915 | mdev->go_diskless.cb = w_go_diskless; | 1923 | device->go_diskless.cb = w_go_diskless; |
1916 | mdev->md_sync_work.cb = w_md_sync; | 1924 | device->md_sync_work.cb = w_md_sync; |
1917 | mdev->bm_io_work.w.cb = w_bitmap_io; | 1925 | device->bm_io_work.w.cb = w_bitmap_io; |
1918 | mdev->start_resync_work.cb = w_start_resync; | 1926 | device->start_resync_work.cb = w_start_resync; |
1919 | 1927 | ||
1920 | mdev->resync_work.mdev = mdev; | 1928 | init_timer(&device->resync_timer); |
1921 | mdev->unplug_work.mdev = mdev; | 1929 | init_timer(&device->md_sync_timer); |
1922 | mdev->go_diskless.mdev = mdev; | 1930 | init_timer(&device->start_resync_timer); |
1923 | mdev->md_sync_work.mdev = mdev; | 1931 | init_timer(&device->request_timer); |
1924 | mdev->bm_io_work.w.mdev = mdev; | 1932 | device->resync_timer.function = resync_timer_fn; |
1925 | mdev->start_resync_work.mdev = mdev; | 1933 | device->resync_timer.data = (unsigned long) device; |
1926 | 1934 | device->md_sync_timer.function = md_sync_timer_fn; | |
1927 | init_timer(&mdev->resync_timer); | 1935 | device->md_sync_timer.data = (unsigned long) device; |
1928 | init_timer(&mdev->md_sync_timer); | 1936 | device->start_resync_timer.function = start_resync_timer_fn; |
1929 | init_timer(&mdev->start_resync_timer); | 1937 | device->start_resync_timer.data = (unsigned long) device; |
1930 | init_timer(&mdev->request_timer); | 1938 | device->request_timer.function = request_timer_fn; |
1931 | mdev->resync_timer.function = resync_timer_fn; | 1939 | device->request_timer.data = (unsigned long) device; |
1932 | mdev->resync_timer.data = (unsigned long) mdev; | 1940 | |
1933 | mdev->md_sync_timer.function = md_sync_timer_fn; | 1941 | init_waitqueue_head(&device->misc_wait); |
1934 | mdev->md_sync_timer.data = (unsigned long) mdev; | 1942 | init_waitqueue_head(&device->state_wait); |
1935 | mdev->start_resync_timer.function = start_resync_timer_fn; | 1943 | init_waitqueue_head(&device->ee_wait); |
1936 | mdev->start_resync_timer.data = (unsigned long) mdev; | 1944 | init_waitqueue_head(&device->al_wait); |
1937 | mdev->request_timer.function = request_timer_fn; | 1945 | init_waitqueue_head(&device->seq_wait); |
1938 | mdev->request_timer.data = (unsigned long) mdev; | 1946 | |
1939 | 1947 | device->resync_wenr = LC_FREE; | |
1940 | init_waitqueue_head(&mdev->misc_wait); | 1948 | device->peer_max_bio_size = DRBD_MAX_BIO_SIZE_SAFE; |
1941 | init_waitqueue_head(&mdev->state_wait); | 1949 | device->local_max_bio_size = DRBD_MAX_BIO_SIZE_SAFE; |
1942 | init_waitqueue_head(&mdev->ee_wait); | 1950 | } |
1943 | init_waitqueue_head(&mdev->al_wait); | 1951 | |
1944 | init_waitqueue_head(&mdev->seq_wait); | 1952 | void drbd_device_cleanup(struct drbd_device *device) |
1945 | |||
1946 | mdev->resync_wenr = LC_FREE; | ||
1947 | mdev->peer_max_bio_size = DRBD_MAX_BIO_SIZE_SAFE; | ||
1948 | mdev->local_max_bio_size = DRBD_MAX_BIO_SIZE_SAFE; | ||
1949 | } | ||
1950 | |||
1951 | void drbd_mdev_cleanup(struct drbd_conf *mdev) | ||
1952 | { | 1953 | { |
1953 | int i; | 1954 | int i; |
1954 | if (mdev->tconn->receiver.t_state != NONE) | 1955 | if (first_peer_device(device)->connection->receiver.t_state != NONE) |
1955 | dev_err(DEV, "ASSERT FAILED: receiver t_state == %d expected 0.\n", | 1956 | drbd_err(device, "ASSERT FAILED: receiver t_state == %d expected 0.\n", |
1956 | mdev->tconn->receiver.t_state); | 1957 | first_peer_device(device)->connection->receiver.t_state); |
1957 | 1958 | ||
1958 | mdev->al_writ_cnt = | 1959 | device->al_writ_cnt = |
1959 | mdev->bm_writ_cnt = | 1960 | device->bm_writ_cnt = |
1960 | mdev->read_cnt = | 1961 | device->read_cnt = |
1961 | mdev->recv_cnt = | 1962 | device->recv_cnt = |
1962 | mdev->send_cnt = | 1963 | device->send_cnt = |
1963 | mdev->writ_cnt = | 1964 | device->writ_cnt = |
1964 | mdev->p_size = | 1965 | device->p_size = |
1965 | mdev->rs_start = | 1966 | device->rs_start = |
1966 | mdev->rs_total = | 1967 | device->rs_total = |
1967 | mdev->rs_failed = 0; | 1968 | device->rs_failed = 0; |
1968 | mdev->rs_last_events = 0; | 1969 | device->rs_last_events = 0; |
1969 | mdev->rs_last_sect_ev = 0; | 1970 | device->rs_last_sect_ev = 0; |
1970 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { | 1971 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
1971 | mdev->rs_mark_left[i] = 0; | 1972 | device->rs_mark_left[i] = 0; |
1972 | mdev->rs_mark_time[i] = 0; | 1973 | device->rs_mark_time[i] = 0; |
1973 | } | 1974 | } |
1974 | D_ASSERT(mdev->tconn->net_conf == NULL); | 1975 | D_ASSERT(device, first_peer_device(device)->connection->net_conf == NULL); |
1975 | 1976 | ||
1976 | drbd_set_my_capacity(mdev, 0); | 1977 | drbd_set_my_capacity(device, 0); |
1977 | if (mdev->bitmap) { | 1978 | if (device->bitmap) { |
1978 | /* maybe never allocated. */ | 1979 | /* maybe never allocated. */ |
1979 | drbd_bm_resize(mdev, 0, 1); | 1980 | drbd_bm_resize(device, 0, 1); |
1980 | drbd_bm_cleanup(mdev); | 1981 | drbd_bm_cleanup(device); |
1981 | } | 1982 | } |
1982 | 1983 | ||
1983 | drbd_free_bc(mdev->ldev); | 1984 | drbd_free_bc(device->ldev); |
1984 | mdev->ldev = NULL; | 1985 | device->ldev = NULL; |
1985 | 1986 | ||
1986 | clear_bit(AL_SUSPENDED, &mdev->flags); | 1987 | clear_bit(AL_SUSPENDED, &device->flags); |
1987 | 1988 | ||
1988 | D_ASSERT(list_empty(&mdev->active_ee)); | 1989 | D_ASSERT(device, list_empty(&device->active_ee)); |
1989 | D_ASSERT(list_empty(&mdev->sync_ee)); | 1990 | D_ASSERT(device, list_empty(&device->sync_ee)); |
1990 | D_ASSERT(list_empty(&mdev->done_ee)); | 1991 | D_ASSERT(device, list_empty(&device->done_ee)); |
1991 | D_ASSERT(list_empty(&mdev->read_ee)); | 1992 | D_ASSERT(device, list_empty(&device->read_ee)); |
1992 | D_ASSERT(list_empty(&mdev->net_ee)); | 1993 | D_ASSERT(device, list_empty(&device->net_ee)); |
1993 | D_ASSERT(list_empty(&mdev->resync_reads)); | 1994 | D_ASSERT(device, list_empty(&device->resync_reads)); |
1994 | D_ASSERT(list_empty(&mdev->tconn->sender_work.q)); | 1995 | D_ASSERT(device, list_empty(&first_peer_device(device)->connection->sender_work.q)); |
1995 | D_ASSERT(list_empty(&mdev->resync_work.list)); | 1996 | D_ASSERT(device, list_empty(&device->resync_work.list)); |
1996 | D_ASSERT(list_empty(&mdev->unplug_work.list)); | 1997 | D_ASSERT(device, list_empty(&device->unplug_work.list)); |
1997 | D_ASSERT(list_empty(&mdev->go_diskless.list)); | 1998 | D_ASSERT(device, list_empty(&device->go_diskless.list)); |
1998 | 1999 | ||
1999 | drbd_set_defaults(mdev); | 2000 | drbd_set_defaults(device); |
2000 | } | 2001 | } |
2001 | 2002 | ||
2002 | 2003 | ||
@@ -2011,7 +2012,7 @@ static void drbd_destroy_mempools(void) | |||
2011 | drbd_pp_vacant--; | 2012 | drbd_pp_vacant--; |
2012 | } | 2013 | } |
2013 | 2014 | ||
2014 | /* D_ASSERT(atomic_read(&drbd_pp_vacant)==0); */ | 2015 | /* D_ASSERT(device, atomic_read(&drbd_pp_vacant)==0); */ |
2015 | 2016 | ||
2016 | if (drbd_md_io_bio_set) | 2017 | if (drbd_md_io_bio_set) |
2017 | bioset_free(drbd_md_io_bio_set); | 2018 | bioset_free(drbd_md_io_bio_set); |
@@ -2131,69 +2132,73 @@ static struct notifier_block drbd_notifier = { | |||
2131 | .notifier_call = drbd_notify_sys, | 2132 | .notifier_call = drbd_notify_sys, |
2132 | }; | 2133 | }; |
2133 | 2134 | ||
2134 | static void drbd_release_all_peer_reqs(struct drbd_conf *mdev) | 2135 | static void drbd_release_all_peer_reqs(struct drbd_device *device) |
2135 | { | 2136 | { |
2136 | int rr; | 2137 | int rr; |
2137 | 2138 | ||
2138 | rr = drbd_free_peer_reqs(mdev, &mdev->active_ee); | 2139 | rr = drbd_free_peer_reqs(device, &device->active_ee); |
2139 | if (rr) | 2140 | if (rr) |
2140 | dev_err(DEV, "%d EEs in active list found!\n", rr); | 2141 | drbd_err(device, "%d EEs in active list found!\n", rr); |
2141 | 2142 | ||
2142 | rr = drbd_free_peer_reqs(mdev, &mdev->sync_ee); | 2143 | rr = drbd_free_peer_reqs(device, &device->sync_ee); |
2143 | if (rr) | 2144 | if (rr) |
2144 | dev_err(DEV, "%d EEs in sync list found!\n", rr); | 2145 | drbd_err(device, "%d EEs in sync list found!\n", rr); |
2145 | 2146 | ||
2146 | rr = drbd_free_peer_reqs(mdev, &mdev->read_ee); | 2147 | rr = drbd_free_peer_reqs(device, &device->read_ee); |
2147 | if (rr) | 2148 | if (rr) |
2148 | dev_err(DEV, "%d EEs in read list found!\n", rr); | 2149 | drbd_err(device, "%d EEs in read list found!\n", rr); |
2149 | 2150 | ||
2150 | rr = drbd_free_peer_reqs(mdev, &mdev->done_ee); | 2151 | rr = drbd_free_peer_reqs(device, &device->done_ee); |
2151 | if (rr) | 2152 | if (rr) |
2152 | dev_err(DEV, "%d EEs in done list found!\n", rr); | 2153 | drbd_err(device, "%d EEs in done list found!\n", rr); |
2153 | 2154 | ||
2154 | rr = drbd_free_peer_reqs(mdev, &mdev->net_ee); | 2155 | rr = drbd_free_peer_reqs(device, &device->net_ee); |
2155 | if (rr) | 2156 | if (rr) |
2156 | dev_err(DEV, "%d EEs in net list found!\n", rr); | 2157 | drbd_err(device, "%d EEs in net list found!\n", rr); |
2157 | } | 2158 | } |
2158 | 2159 | ||
2159 | /* caution. no locking. */ | 2160 | /* caution. no locking. */ |
2160 | void drbd_minor_destroy(struct kref *kref) | 2161 | void drbd_destroy_device(struct kref *kref) |
2161 | { | 2162 | { |
2162 | struct drbd_conf *mdev = container_of(kref, struct drbd_conf, kref); | 2163 | struct drbd_device *device = container_of(kref, struct drbd_device, kref); |
2163 | struct drbd_tconn *tconn = mdev->tconn; | 2164 | struct drbd_resource *resource = device->resource; |
2165 | struct drbd_connection *connection; | ||
2164 | 2166 | ||
2165 | del_timer_sync(&mdev->request_timer); | 2167 | del_timer_sync(&device->request_timer); |
2166 | 2168 | ||
2167 | /* paranoia asserts */ | 2169 | /* paranoia asserts */ |
2168 | D_ASSERT(mdev->open_cnt == 0); | 2170 | D_ASSERT(device, device->open_cnt == 0); |
2169 | /* end paranoia asserts */ | 2171 | /* end paranoia asserts */ |
2170 | 2172 | ||
2171 | /* cleanup stuff that may have been allocated during | 2173 | /* cleanup stuff that may have been allocated during |
2172 | * device (re-)configuration or state changes */ | 2174 | * device (re-)configuration or state changes */ |
2173 | 2175 | ||
2174 | if (mdev->this_bdev) | 2176 | if (device->this_bdev) |
2175 | bdput(mdev->this_bdev); | 2177 | bdput(device->this_bdev); |
2176 | 2178 | ||
2177 | drbd_free_bc(mdev->ldev); | 2179 | drbd_free_bc(device->ldev); |
2178 | mdev->ldev = NULL; | 2180 | device->ldev = NULL; |
2179 | 2181 | ||
2180 | drbd_release_all_peer_reqs(mdev); | 2182 | drbd_release_all_peer_reqs(device); |
2181 | 2183 | ||
2182 | lc_destroy(mdev->act_log); | 2184 | lc_destroy(device->act_log); |
2183 | lc_destroy(mdev->resync); | 2185 | lc_destroy(device->resync); |
2184 | 2186 | ||
2185 | kfree(mdev->p_uuid); | 2187 | kfree(device->p_uuid); |
2186 | /* mdev->p_uuid = NULL; */ | 2188 | /* device->p_uuid = NULL; */ |
2187 | 2189 | ||
2188 | if (mdev->bitmap) /* should no longer be there. */ | 2190 | if (device->bitmap) /* should no longer be there. */ |
2189 | drbd_bm_cleanup(mdev); | 2191 | drbd_bm_cleanup(device); |
2190 | __free_page(mdev->md_io_page); | 2192 | __free_page(device->md_io_page); |
2191 | put_disk(mdev->vdisk); | 2193 | put_disk(device->vdisk); |
2192 | blk_cleanup_queue(mdev->rq_queue); | 2194 | blk_cleanup_queue(device->rq_queue); |
2193 | kfree(mdev->rs_plan_s); | 2195 | kfree(device->rs_plan_s); |
2194 | kfree(mdev); | 2196 | kfree(first_peer_device(device)); |
2197 | kfree(device); | ||
2195 | 2198 | ||
2196 | kref_put(&tconn->kref, &conn_destroy); | 2199 | for_each_connection(connection, resource) |
2200 | kref_put(&connection->kref, drbd_destroy_connection); | ||
2201 | kref_put(&resource->kref, drbd_destroy_resource); | ||
2197 | } | 2202 | } |
2198 | 2203 | ||
2199 | /* One global retry thread, if we need to push back some bio and have it | 2204 | /* One global retry thread, if we need to push back some bio and have it |
@@ -2218,19 +2223,19 @@ static void do_retry(struct work_struct *ws) | |||
2218 | spin_unlock_irq(&retry->lock); | 2223 | spin_unlock_irq(&retry->lock); |
2219 | 2224 | ||
2220 | list_for_each_entry_safe(req, tmp, &writes, tl_requests) { | 2225 | list_for_each_entry_safe(req, tmp, &writes, tl_requests) { |
2221 | struct drbd_conf *mdev = req->w.mdev; | 2226 | struct drbd_device *device = req->device; |
2222 | struct bio *bio = req->master_bio; | 2227 | struct bio *bio = req->master_bio; |
2223 | unsigned long start_time = req->start_time; | 2228 | unsigned long start_time = req->start_time; |
2224 | bool expected; | 2229 | bool expected; |
2225 | 2230 | ||
2226 | expected = | 2231 | expected = |
2227 | expect(atomic_read(&req->completion_ref) == 0) && | 2232 | expect(atomic_read(&req->completion_ref) == 0) && |
2228 | expect(req->rq_state & RQ_POSTPONED) && | 2233 | expect(req->rq_state & RQ_POSTPONED) && |
2229 | expect((req->rq_state & RQ_LOCAL_PENDING) == 0 || | 2234 | expect((req->rq_state & RQ_LOCAL_PENDING) == 0 || |
2230 | (req->rq_state & RQ_LOCAL_ABORTED) != 0); | 2235 | (req->rq_state & RQ_LOCAL_ABORTED) != 0); |
2231 | 2236 | ||
2232 | if (!expected) | 2237 | if (!expected) |
2233 | dev_err(DEV, "req=%p completion_ref=%d rq_state=%x\n", | 2238 | drbd_err(device, "req=%p completion_ref=%d rq_state=%x\n", |
2234 | req, atomic_read(&req->completion_ref), | 2239 | req, atomic_read(&req->completion_ref), |
2235 | req->rq_state); | 2240 | req->rq_state); |
2236 | 2241 | ||
@@ -2254,8 +2259,8 @@ static void do_retry(struct work_struct *ws) | |||
2254 | 2259 | ||
2255 | /* We are not just doing generic_make_request(), | 2260 | /* We are not just doing generic_make_request(), |
2256 | * as we want to keep the start_time information. */ | 2261 | * as we want to keep the start_time information. */ |
2257 | inc_ap_bio(mdev); | 2262 | inc_ap_bio(device); |
2258 | __drbd_make_request(mdev, bio, start_time); | 2263 | __drbd_make_request(device, bio, start_time); |
2259 | } | 2264 | } |
2260 | } | 2265 | } |
2261 | 2266 | ||
@@ -2269,17 +2274,38 @@ void drbd_restart_request(struct drbd_request *req) | |||
2269 | /* Drop the extra reference that would otherwise | 2274 | /* Drop the extra reference that would otherwise |
2270 | * have been dropped by complete_master_bio. | 2275 | * have been dropped by complete_master_bio. |
2271 | * do_retry() needs to grab a new one. */ | 2276 | * do_retry() needs to grab a new one. */ |
2272 | dec_ap_bio(req->w.mdev); | 2277 | dec_ap_bio(req->device); |
2273 | 2278 | ||
2274 | queue_work(retry.wq, &retry.worker); | 2279 | queue_work(retry.wq, &retry.worker); |
2275 | } | 2280 | } |
2276 | 2281 | ||
2282 | void drbd_destroy_resource(struct kref *kref) | ||
2283 | { | ||
2284 | struct drbd_resource *resource = | ||
2285 | container_of(kref, struct drbd_resource, kref); | ||
2286 | |||
2287 | idr_destroy(&resource->devices); | ||
2288 | free_cpumask_var(resource->cpu_mask); | ||
2289 | kfree(resource->name); | ||
2290 | kfree(resource); | ||
2291 | } | ||
2292 | |||
2293 | void drbd_free_resource(struct drbd_resource *resource) | ||
2294 | { | ||
2295 | struct drbd_connection *connection, *tmp; | ||
2296 | |||
2297 | for_each_connection_safe(connection, tmp, resource) { | ||
2298 | list_del(&connection->connections); | ||
2299 | kref_put(&connection->kref, drbd_destroy_connection); | ||
2300 | } | ||
2301 | kref_put(&resource->kref, drbd_destroy_resource); | ||
2302 | } | ||
2277 | 2303 | ||
2278 | static void drbd_cleanup(void) | 2304 | static void drbd_cleanup(void) |
2279 | { | 2305 | { |
2280 | unsigned int i; | 2306 | unsigned int i; |
2281 | struct drbd_conf *mdev; | 2307 | struct drbd_device *device; |
2282 | struct drbd_tconn *tconn, *tmp; | 2308 | struct drbd_resource *resource, *tmp; |
2283 | 2309 | ||
2284 | unregister_reboot_notifier(&drbd_notifier); | 2310 | unregister_reboot_notifier(&drbd_notifier); |
2285 | 2311 | ||
@@ -2299,26 +2325,19 @@ static void drbd_cleanup(void) | |||
2299 | 2325 | ||
2300 | drbd_genl_unregister(); | 2326 | drbd_genl_unregister(); |
2301 | 2327 | ||
2302 | idr_for_each_entry(&minors, mdev, i) { | 2328 | idr_for_each_entry(&drbd_devices, device, i) |
2303 | idr_remove(&minors, mdev_to_minor(mdev)); | 2329 | drbd_delete_device(device); |
2304 | idr_remove(&mdev->tconn->volumes, mdev->vnr); | ||
2305 | destroy_workqueue(mdev->submit.wq); | ||
2306 | del_gendisk(mdev->vdisk); | ||
2307 | /* synchronize_rcu(); No other threads running at this point */ | ||
2308 | kref_put(&mdev->kref, &drbd_minor_destroy); | ||
2309 | } | ||
2310 | 2330 | ||
2311 | /* not _rcu since, no other updater anymore. Genl already unregistered */ | 2331 | /* not _rcu since, no other updater anymore. Genl already unregistered */ |
2312 | list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) { | 2332 | for_each_resource_safe(resource, tmp, &drbd_resources) { |
2313 | list_del(&tconn->all_tconn); /* not _rcu no proc, not other threads */ | 2333 | list_del(&resource->resources); |
2314 | /* synchronize_rcu(); */ | 2334 | drbd_free_resource(resource); |
2315 | kref_put(&tconn->kref, &conn_destroy); | ||
2316 | } | 2335 | } |
2317 | 2336 | ||
2318 | drbd_destroy_mempools(); | 2337 | drbd_destroy_mempools(); |
2319 | unregister_blkdev(DRBD_MAJOR, "drbd"); | 2338 | unregister_blkdev(DRBD_MAJOR, "drbd"); |
2320 | 2339 | ||
2321 | idr_destroy(&minors); | 2340 | idr_destroy(&drbd_devices); |
2322 | 2341 | ||
2323 | printk(KERN_INFO "drbd: module cleanup done.\n"); | 2342 | printk(KERN_INFO "drbd: module cleanup done.\n"); |
2324 | } | 2343 | } |
@@ -2332,49 +2351,50 @@ static void drbd_cleanup(void) | |||
2332 | */ | 2351 | */ |
2333 | static int drbd_congested(void *congested_data, int bdi_bits) | 2352 | static int drbd_congested(void *congested_data, int bdi_bits) |
2334 | { | 2353 | { |
2335 | struct drbd_conf *mdev = congested_data; | 2354 | struct drbd_device *device = congested_data; |
2336 | struct request_queue *q; | 2355 | struct request_queue *q; |
2337 | char reason = '-'; | 2356 | char reason = '-'; |
2338 | int r = 0; | 2357 | int r = 0; |
2339 | 2358 | ||
2340 | if (!may_inc_ap_bio(mdev)) { | 2359 | if (!may_inc_ap_bio(device)) { |
2341 | /* DRBD has frozen IO */ | 2360 | /* DRBD has frozen IO */ |
2342 | r = bdi_bits; | 2361 | r = bdi_bits; |
2343 | reason = 'd'; | 2362 | reason = 'd'; |
2344 | goto out; | 2363 | goto out; |
2345 | } | 2364 | } |
2346 | 2365 | ||
2347 | if (test_bit(CALLBACK_PENDING, &mdev->tconn->flags)) { | 2366 | if (test_bit(CALLBACK_PENDING, &first_peer_device(device)->connection->flags)) { |
2348 | r |= (1 << BDI_async_congested); | 2367 | r |= (1 << BDI_async_congested); |
2349 | /* Without good local data, we would need to read from remote, | 2368 | /* Without good local data, we would need to read from remote, |
2350 | * and that would need the worker thread as well, which is | 2369 | * and that would need the worker thread as well, which is |
2351 | * currently blocked waiting for that usermode helper to | 2370 | * currently blocked waiting for that usermode helper to |
2352 | * finish. | 2371 | * finish. |
2353 | */ | 2372 | */ |
2354 | if (!get_ldev_if_state(mdev, D_UP_TO_DATE)) | 2373 | if (!get_ldev_if_state(device, D_UP_TO_DATE)) |
2355 | r |= (1 << BDI_sync_congested); | 2374 | r |= (1 << BDI_sync_congested); |
2356 | else | 2375 | else |
2357 | put_ldev(mdev); | 2376 | put_ldev(device); |
2358 | r &= bdi_bits; | 2377 | r &= bdi_bits; |
2359 | reason = 'c'; | 2378 | reason = 'c'; |
2360 | goto out; | 2379 | goto out; |
2361 | } | 2380 | } |
2362 | 2381 | ||
2363 | if (get_ldev(mdev)) { | 2382 | if (get_ldev(device)) { |
2364 | q = bdev_get_queue(mdev->ldev->backing_bdev); | 2383 | q = bdev_get_queue(device->ldev->backing_bdev); |
2365 | r = bdi_congested(&q->backing_dev_info, bdi_bits); | 2384 | r = bdi_congested(&q->backing_dev_info, bdi_bits); |
2366 | put_ldev(mdev); | 2385 | put_ldev(device); |
2367 | if (r) | 2386 | if (r) |
2368 | reason = 'b'; | 2387 | reason = 'b'; |
2369 | } | 2388 | } |
2370 | 2389 | ||
2371 | if (bdi_bits & (1 << BDI_async_congested) && test_bit(NET_CONGESTED, &mdev->tconn->flags)) { | 2390 | if (bdi_bits & (1 << BDI_async_congested) && |
2391 | test_bit(NET_CONGESTED, &first_peer_device(device)->connection->flags)) { | ||
2372 | r |= (1 << BDI_async_congested); | 2392 | r |= (1 << BDI_async_congested); |
2373 | reason = reason == 'b' ? 'a' : 'n'; | 2393 | reason = reason == 'b' ? 'a' : 'n'; |
2374 | } | 2394 | } |
2375 | 2395 | ||
2376 | out: | 2396 | out: |
2377 | mdev->congestion_reason = reason; | 2397 | device->congestion_reason = reason; |
2378 | return r; | 2398 | return r; |
2379 | } | 2399 | } |
2380 | 2400 | ||
@@ -2385,45 +2405,72 @@ static void drbd_init_workqueue(struct drbd_work_queue* wq) | |||
2385 | init_waitqueue_head(&wq->q_wait); | 2405 | init_waitqueue_head(&wq->q_wait); |
2386 | } | 2406 | } |
2387 | 2407 | ||
2388 | struct drbd_tconn *conn_get_by_name(const char *name) | 2408 | struct completion_work { |
2409 | struct drbd_work w; | ||
2410 | struct completion done; | ||
2411 | }; | ||
2412 | |||
2413 | static int w_complete(struct drbd_work *w, int cancel) | ||
2414 | { | ||
2415 | struct completion_work *completion_work = | ||
2416 | container_of(w, struct completion_work, w); | ||
2417 | |||
2418 | complete(&completion_work->done); | ||
2419 | return 0; | ||
2420 | } | ||
2421 | |||
2422 | void drbd_flush_workqueue(struct drbd_work_queue *work_queue) | ||
2423 | { | ||
2424 | struct completion_work completion_work; | ||
2425 | |||
2426 | completion_work.w.cb = w_complete; | ||
2427 | init_completion(&completion_work.done); | ||
2428 | drbd_queue_work(work_queue, &completion_work.w); | ||
2429 | wait_for_completion(&completion_work.done); | ||
2430 | } | ||
2431 | |||
2432 | struct drbd_resource *drbd_find_resource(const char *name) | ||
2389 | { | 2433 | { |
2390 | struct drbd_tconn *tconn; | 2434 | struct drbd_resource *resource; |
2391 | 2435 | ||
2392 | if (!name || !name[0]) | 2436 | if (!name || !name[0]) |
2393 | return NULL; | 2437 | return NULL; |
2394 | 2438 | ||
2395 | rcu_read_lock(); | 2439 | rcu_read_lock(); |
2396 | list_for_each_entry_rcu(tconn, &drbd_tconns, all_tconn) { | 2440 | for_each_resource_rcu(resource, &drbd_resources) { |
2397 | if (!strcmp(tconn->name, name)) { | 2441 | if (!strcmp(resource->name, name)) { |
2398 | kref_get(&tconn->kref); | 2442 | kref_get(&resource->kref); |
2399 | goto found; | 2443 | goto found; |
2400 | } | 2444 | } |
2401 | } | 2445 | } |
2402 | tconn = NULL; | 2446 | resource = NULL; |
2403 | found: | 2447 | found: |
2404 | rcu_read_unlock(); | 2448 | rcu_read_unlock(); |
2405 | return tconn; | 2449 | return resource; |
2406 | } | 2450 | } |
2407 | 2451 | ||
2408 | struct drbd_tconn *conn_get_by_addrs(void *my_addr, int my_addr_len, | 2452 | struct drbd_connection *conn_get_by_addrs(void *my_addr, int my_addr_len, |
2409 | void *peer_addr, int peer_addr_len) | 2453 | void *peer_addr, int peer_addr_len) |
2410 | { | 2454 | { |
2411 | struct drbd_tconn *tconn; | 2455 | struct drbd_resource *resource; |
2456 | struct drbd_connection *connection; | ||
2412 | 2457 | ||
2413 | rcu_read_lock(); | 2458 | rcu_read_lock(); |
2414 | list_for_each_entry_rcu(tconn, &drbd_tconns, all_tconn) { | 2459 | for_each_resource_rcu(resource, &drbd_resources) { |
2415 | if (tconn->my_addr_len == my_addr_len && | 2460 | for_each_connection_rcu(connection, resource) { |
2416 | tconn->peer_addr_len == peer_addr_len && | 2461 | if (connection->my_addr_len == my_addr_len && |
2417 | !memcmp(&tconn->my_addr, my_addr, my_addr_len) && | 2462 | connection->peer_addr_len == peer_addr_len && |
2418 | !memcmp(&tconn->peer_addr, peer_addr, peer_addr_len)) { | 2463 | !memcmp(&connection->my_addr, my_addr, my_addr_len) && |
2419 | kref_get(&tconn->kref); | 2464 | !memcmp(&connection->peer_addr, peer_addr, peer_addr_len)) { |
2420 | goto found; | 2465 | kref_get(&connection->kref); |
2466 | goto found; | ||
2467 | } | ||
2421 | } | 2468 | } |
2422 | } | 2469 | } |
2423 | tconn = NULL; | 2470 | connection = NULL; |
2424 | found: | 2471 | found: |
2425 | rcu_read_unlock(); | 2472 | rcu_read_unlock(); |
2426 | return tconn; | 2473 | return connection; |
2427 | } | 2474 | } |
2428 | 2475 | ||
2429 | static int drbd_alloc_socket(struct drbd_socket *socket) | 2476 | static int drbd_alloc_socket(struct drbd_socket *socket) |
@@ -2443,29 +2490,30 @@ static void drbd_free_socket(struct drbd_socket *socket) | |||
2443 | free_page((unsigned long) socket->rbuf); | 2490 | free_page((unsigned long) socket->rbuf); |
2444 | } | 2491 | } |
2445 | 2492 | ||
2446 | void conn_free_crypto(struct drbd_tconn *tconn) | 2493 | void conn_free_crypto(struct drbd_connection *connection) |
2447 | { | 2494 | { |
2448 | drbd_free_sock(tconn); | 2495 | drbd_free_sock(connection); |
2449 | 2496 | ||
2450 | crypto_free_hash(tconn->csums_tfm); | 2497 | crypto_free_hash(connection->csums_tfm); |
2451 | crypto_free_hash(tconn->verify_tfm); | 2498 | crypto_free_hash(connection->verify_tfm); |
2452 | crypto_free_hash(tconn->cram_hmac_tfm); | 2499 | crypto_free_hash(connection->cram_hmac_tfm); |
2453 | crypto_free_hash(tconn->integrity_tfm); | 2500 | crypto_free_hash(connection->integrity_tfm); |
2454 | crypto_free_hash(tconn->peer_integrity_tfm); | 2501 | crypto_free_hash(connection->peer_integrity_tfm); |
2455 | kfree(tconn->int_dig_in); | 2502 | kfree(connection->int_dig_in); |
2456 | kfree(tconn->int_dig_vv); | 2503 | kfree(connection->int_dig_vv); |
2457 | 2504 | ||
2458 | tconn->csums_tfm = NULL; | 2505 | connection->csums_tfm = NULL; |
2459 | tconn->verify_tfm = NULL; | 2506 | connection->verify_tfm = NULL; |
2460 | tconn->cram_hmac_tfm = NULL; | 2507 | connection->cram_hmac_tfm = NULL; |
2461 | tconn->integrity_tfm = NULL; | 2508 | connection->integrity_tfm = NULL; |
2462 | tconn->peer_integrity_tfm = NULL; | 2509 | connection->peer_integrity_tfm = NULL; |
2463 | tconn->int_dig_in = NULL; | 2510 | connection->int_dig_in = NULL; |
2464 | tconn->int_dig_vv = NULL; | 2511 | connection->int_dig_vv = NULL; |
2465 | } | 2512 | } |
2466 | 2513 | ||
2467 | int set_resource_options(struct drbd_tconn *tconn, struct res_opts *res_opts) | 2514 | int set_resource_options(struct drbd_resource *resource, struct res_opts *res_opts) |
2468 | { | 2515 | { |
2516 | struct drbd_connection *connection; | ||
2469 | cpumask_var_t new_cpu_mask; | 2517 | cpumask_var_t new_cpu_mask; |
2470 | int err; | 2518 | int err; |
2471 | 2519 | ||
@@ -2478,22 +2526,24 @@ int set_resource_options(struct drbd_tconn *tconn, struct res_opts *res_opts) | |||
2478 | 2526 | ||
2479 | /* silently ignore cpu mask on UP kernel */ | 2527 | /* silently ignore cpu mask on UP kernel */ |
2480 | if (nr_cpu_ids > 1 && res_opts->cpu_mask[0] != 0) { | 2528 | if (nr_cpu_ids > 1 && res_opts->cpu_mask[0] != 0) { |
2481 | /* FIXME: Get rid of constant 32 here */ | 2529 | err = bitmap_parse(res_opts->cpu_mask, DRBD_CPU_MASK_SIZE, |
2482 | err = bitmap_parse(res_opts->cpu_mask, 32, | ||
2483 | cpumask_bits(new_cpu_mask), nr_cpu_ids); | 2530 | cpumask_bits(new_cpu_mask), nr_cpu_ids); |
2484 | if (err) { | 2531 | if (err) { |
2485 | conn_warn(tconn, "bitmap_parse() failed with %d\n", err); | 2532 | drbd_warn(resource, "bitmap_parse() failed with %d\n", err); |
2486 | /* retcode = ERR_CPU_MASK_PARSE; */ | 2533 | /* retcode = ERR_CPU_MASK_PARSE; */ |
2487 | goto fail; | 2534 | goto fail; |
2488 | } | 2535 | } |
2489 | } | 2536 | } |
2490 | tconn->res_opts = *res_opts; | 2537 | resource->res_opts = *res_opts; |
2491 | if (!cpumask_equal(tconn->cpu_mask, new_cpu_mask)) { | 2538 | if (cpumask_empty(new_cpu_mask)) |
2492 | cpumask_copy(tconn->cpu_mask, new_cpu_mask); | 2539 | drbd_calc_cpu_mask(&new_cpu_mask); |
2493 | drbd_calc_cpu_mask(tconn); | 2540 | if (!cpumask_equal(resource->cpu_mask, new_cpu_mask)) { |
2494 | tconn->receiver.reset_cpu_mask = 1; | 2541 | cpumask_copy(resource->cpu_mask, new_cpu_mask); |
2495 | tconn->asender.reset_cpu_mask = 1; | 2542 | for_each_connection_rcu(connection, resource) { |
2496 | tconn->worker.reset_cpu_mask = 1; | 2543 | connection->receiver.reset_cpu_mask = 1; |
2544 | connection->asender.reset_cpu_mask = 1; | ||
2545 | connection->worker.reset_cpu_mask = 1; | ||
2546 | } | ||
2497 | } | 2547 | } |
2498 | err = 0; | 2548 | err = 0; |
2499 | 2549 | ||
@@ -2503,146 +2553,177 @@ fail: | |||
2503 | 2553 | ||
2504 | } | 2554 | } |
2505 | 2555 | ||
2556 | struct drbd_resource *drbd_create_resource(const char *name) | ||
2557 | { | ||
2558 | struct drbd_resource *resource; | ||
2559 | |||
2560 | resource = kzalloc(sizeof(struct drbd_resource), GFP_KERNEL); | ||
2561 | if (!resource) | ||
2562 | goto fail; | ||
2563 | resource->name = kstrdup(name, GFP_KERNEL); | ||
2564 | if (!resource->name) | ||
2565 | goto fail_free_resource; | ||
2566 | if (!zalloc_cpumask_var(&resource->cpu_mask, GFP_KERNEL)) | ||
2567 | goto fail_free_name; | ||
2568 | kref_init(&resource->kref); | ||
2569 | idr_init(&resource->devices); | ||
2570 | INIT_LIST_HEAD(&resource->connections); | ||
2571 | list_add_tail_rcu(&resource->resources, &drbd_resources); | ||
2572 | mutex_init(&resource->conf_update); | ||
2573 | spin_lock_init(&resource->req_lock); | ||
2574 | return resource; | ||
2575 | |||
2576 | fail_free_name: | ||
2577 | kfree(resource->name); | ||
2578 | fail_free_resource: | ||
2579 | kfree(resource); | ||
2580 | fail: | ||
2581 | return NULL; | ||
2582 | } | ||
2583 | |||
2506 | /* caller must be under genl_lock() */ | 2584 | /* caller must be under genl_lock() */ |
2507 | struct drbd_tconn *conn_create(const char *name, struct res_opts *res_opts) | 2585 | struct drbd_connection *conn_create(const char *name, struct res_opts *res_opts) |
2508 | { | 2586 | { |
2509 | struct drbd_tconn *tconn; | 2587 | struct drbd_resource *resource; |
2588 | struct drbd_connection *connection; | ||
2510 | 2589 | ||
2511 | tconn = kzalloc(sizeof(struct drbd_tconn), GFP_KERNEL); | 2590 | connection = kzalloc(sizeof(struct drbd_connection), GFP_KERNEL); |
2512 | if (!tconn) | 2591 | if (!connection) |
2513 | return NULL; | 2592 | return NULL; |
2514 | 2593 | ||
2515 | tconn->name = kstrdup(name, GFP_KERNEL); | 2594 | if (drbd_alloc_socket(&connection->data)) |
2516 | if (!tconn->name) | ||
2517 | goto fail; | 2595 | goto fail; |
2518 | 2596 | if (drbd_alloc_socket(&connection->meta)) | |
2519 | if (drbd_alloc_socket(&tconn->data)) | ||
2520 | goto fail; | ||
2521 | if (drbd_alloc_socket(&tconn->meta)) | ||
2522 | goto fail; | 2597 | goto fail; |
2523 | 2598 | ||
2524 | if (!zalloc_cpumask_var(&tconn->cpu_mask, GFP_KERNEL)) | 2599 | connection->current_epoch = kzalloc(sizeof(struct drbd_epoch), GFP_KERNEL); |
2600 | if (!connection->current_epoch) | ||
2525 | goto fail; | 2601 | goto fail; |
2526 | 2602 | ||
2527 | if (set_resource_options(tconn, res_opts)) | 2603 | INIT_LIST_HEAD(&connection->transfer_log); |
2528 | goto fail; | ||
2529 | 2604 | ||
2530 | tconn->current_epoch = kzalloc(sizeof(struct drbd_epoch), GFP_KERNEL); | 2605 | INIT_LIST_HEAD(&connection->current_epoch->list); |
2531 | if (!tconn->current_epoch) | 2606 | connection->epochs = 1; |
2532 | goto fail; | 2607 | spin_lock_init(&connection->epoch_lock); |
2608 | connection->write_ordering = WO_bdev_flush; | ||
2533 | 2609 | ||
2534 | INIT_LIST_HEAD(&tconn->transfer_log); | 2610 | connection->send.seen_any_write_yet = false; |
2611 | connection->send.current_epoch_nr = 0; | ||
2612 | connection->send.current_epoch_writes = 0; | ||
2535 | 2613 | ||
2536 | INIT_LIST_HEAD(&tconn->current_epoch->list); | 2614 | resource = drbd_create_resource(name); |
2537 | tconn->epochs = 1; | 2615 | if (!resource) |
2538 | spin_lock_init(&tconn->epoch_lock); | 2616 | goto fail; |
2539 | tconn->write_ordering = WO_bdev_flush; | ||
2540 | 2617 | ||
2541 | tconn->send.seen_any_write_yet = false; | 2618 | connection->cstate = C_STANDALONE; |
2542 | tconn->send.current_epoch_nr = 0; | 2619 | mutex_init(&connection->cstate_mutex); |
2543 | tconn->send.current_epoch_writes = 0; | 2620 | init_waitqueue_head(&connection->ping_wait); |
2621 | idr_init(&connection->peer_devices); | ||
2544 | 2622 | ||
2545 | tconn->cstate = C_STANDALONE; | 2623 | drbd_init_workqueue(&connection->sender_work); |
2546 | mutex_init(&tconn->cstate_mutex); | 2624 | mutex_init(&connection->data.mutex); |
2547 | spin_lock_init(&tconn->req_lock); | 2625 | mutex_init(&connection->meta.mutex); |
2548 | mutex_init(&tconn->conf_update); | ||
2549 | init_waitqueue_head(&tconn->ping_wait); | ||
2550 | idr_init(&tconn->volumes); | ||
2551 | 2626 | ||
2552 | drbd_init_workqueue(&tconn->sender_work); | 2627 | drbd_thread_init(resource, &connection->receiver, drbd_receiver, "receiver"); |
2553 | mutex_init(&tconn->data.mutex); | 2628 | connection->receiver.connection = connection; |
2554 | mutex_init(&tconn->meta.mutex); | 2629 | drbd_thread_init(resource, &connection->worker, drbd_worker, "worker"); |
2630 | connection->worker.connection = connection; | ||
2631 | drbd_thread_init(resource, &connection->asender, drbd_asender, "asender"); | ||
2632 | connection->asender.connection = connection; | ||
2555 | 2633 | ||
2556 | drbd_thread_init(tconn, &tconn->receiver, drbdd_init, "receiver"); | 2634 | kref_init(&connection->kref); |
2557 | drbd_thread_init(tconn, &tconn->worker, drbd_worker, "worker"); | ||
2558 | drbd_thread_init(tconn, &tconn->asender, drbd_asender, "asender"); | ||
2559 | 2635 | ||
2560 | kref_init(&tconn->kref); | 2636 | connection->resource = resource; |
2561 | list_add_tail_rcu(&tconn->all_tconn, &drbd_tconns); | ||
2562 | 2637 | ||
2563 | return tconn; | 2638 | if (set_resource_options(resource, res_opts)) |
2639 | goto fail_resource; | ||
2564 | 2640 | ||
2565 | fail: | 2641 | kref_get(&resource->kref); |
2566 | kfree(tconn->current_epoch); | 2642 | list_add_tail_rcu(&connection->connections, &resource->connections); |
2567 | free_cpumask_var(tconn->cpu_mask); | 2643 | return connection; |
2568 | drbd_free_socket(&tconn->meta); | ||
2569 | drbd_free_socket(&tconn->data); | ||
2570 | kfree(tconn->name); | ||
2571 | kfree(tconn); | ||
2572 | 2644 | ||
2645 | fail_resource: | ||
2646 | list_del(&resource->resources); | ||
2647 | drbd_free_resource(resource); | ||
2648 | fail: | ||
2649 | kfree(connection->current_epoch); | ||
2650 | drbd_free_socket(&connection->meta); | ||
2651 | drbd_free_socket(&connection->data); | ||
2652 | kfree(connection); | ||
2573 | return NULL; | 2653 | return NULL; |
2574 | } | 2654 | } |
2575 | 2655 | ||
2576 | void conn_destroy(struct kref *kref) | 2656 | void drbd_destroy_connection(struct kref *kref) |
2577 | { | 2657 | { |
2578 | struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref); | 2658 | struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref); |
2659 | struct drbd_resource *resource = connection->resource; | ||
2579 | 2660 | ||
2580 | if (atomic_read(&tconn->current_epoch->epoch_size) != 0) | 2661 | if (atomic_read(&connection->current_epoch->epoch_size) != 0) |
2581 | conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size)); | 2662 | drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size)); |
2582 | kfree(tconn->current_epoch); | 2663 | kfree(connection->current_epoch); |
2583 | 2664 | ||
2584 | idr_destroy(&tconn->volumes); | 2665 | idr_destroy(&connection->peer_devices); |
2585 | 2666 | ||
2586 | free_cpumask_var(tconn->cpu_mask); | 2667 | drbd_free_socket(&connection->meta); |
2587 | drbd_free_socket(&tconn->meta); | 2668 | drbd_free_socket(&connection->data); |
2588 | drbd_free_socket(&tconn->data); | 2669 | kfree(connection->int_dig_in); |
2589 | kfree(tconn->name); | 2670 | kfree(connection->int_dig_vv); |
2590 | kfree(tconn->int_dig_in); | 2671 | kfree(connection); |
2591 | kfree(tconn->int_dig_vv); | 2672 | kref_put(&resource->kref, drbd_destroy_resource); |
2592 | kfree(tconn); | ||
2593 | } | 2673 | } |
2594 | 2674 | ||
2595 | int init_submitter(struct drbd_conf *mdev) | 2675 | static int init_submitter(struct drbd_device *device) |
2596 | { | 2676 | { |
2597 | /* opencoded create_singlethread_workqueue(), | 2677 | /* opencoded create_singlethread_workqueue(), |
2598 | * to be able to say "drbd%d", ..., minor */ | 2678 | * to be able to say "drbd%d", ..., minor */ |
2599 | mdev->submit.wq = alloc_workqueue("drbd%u_submit", | 2679 | device->submit.wq = alloc_workqueue("drbd%u_submit", |
2600 | WQ_UNBOUND | WQ_MEM_RECLAIM, 1, mdev->minor); | 2680 | WQ_UNBOUND | WQ_MEM_RECLAIM, 1, device->minor); |
2601 | if (!mdev->submit.wq) | 2681 | if (!device->submit.wq) |
2602 | return -ENOMEM; | 2682 | return -ENOMEM; |
2603 | 2683 | ||
2604 | INIT_WORK(&mdev->submit.worker, do_submit); | 2684 | INIT_WORK(&device->submit.worker, do_submit); |
2605 | spin_lock_init(&mdev->submit.lock); | 2685 | spin_lock_init(&device->submit.lock); |
2606 | INIT_LIST_HEAD(&mdev->submit.writes); | 2686 | INIT_LIST_HEAD(&device->submit.writes); |
2607 | return 0; | 2687 | return 0; |
2608 | } | 2688 | } |
2609 | 2689 | ||
2610 | enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, int vnr) | 2690 | enum drbd_ret_code drbd_create_device(struct drbd_resource *resource, unsigned int minor, int vnr) |
2611 | { | 2691 | { |
2612 | struct drbd_conf *mdev; | 2692 | struct drbd_connection *connection; |
2693 | struct drbd_device *device; | ||
2694 | struct drbd_peer_device *peer_device, *tmp_peer_device; | ||
2613 | struct gendisk *disk; | 2695 | struct gendisk *disk; |
2614 | struct request_queue *q; | 2696 | struct request_queue *q; |
2615 | int vnr_got = vnr; | 2697 | int id; |
2616 | int minor_got = minor; | ||
2617 | enum drbd_ret_code err = ERR_NOMEM; | 2698 | enum drbd_ret_code err = ERR_NOMEM; |
2618 | 2699 | ||
2619 | mdev = minor_to_mdev(minor); | 2700 | device = minor_to_device(minor); |
2620 | if (mdev) | 2701 | if (device) |
2621 | return ERR_MINOR_EXISTS; | 2702 | return ERR_MINOR_EXISTS; |
2622 | 2703 | ||
2623 | /* GFP_KERNEL, we are outside of all write-out paths */ | 2704 | /* GFP_KERNEL, we are outside of all write-out paths */ |
2624 | mdev = kzalloc(sizeof(struct drbd_conf), GFP_KERNEL); | 2705 | device = kzalloc(sizeof(struct drbd_device), GFP_KERNEL); |
2625 | if (!mdev) | 2706 | if (!device) |
2626 | return ERR_NOMEM; | 2707 | return ERR_NOMEM; |
2708 | kref_init(&device->kref); | ||
2627 | 2709 | ||
2628 | kref_get(&tconn->kref); | 2710 | kref_get(&resource->kref); |
2629 | mdev->tconn = tconn; | 2711 | device->resource = resource; |
2712 | device->minor = minor; | ||
2713 | device->vnr = vnr; | ||
2630 | 2714 | ||
2631 | mdev->minor = minor; | 2715 | drbd_init_set_defaults(device); |
2632 | mdev->vnr = vnr; | ||
2633 | |||
2634 | drbd_init_set_defaults(mdev); | ||
2635 | 2716 | ||
2636 | q = blk_alloc_queue(GFP_KERNEL); | 2717 | q = blk_alloc_queue(GFP_KERNEL); |
2637 | if (!q) | 2718 | if (!q) |
2638 | goto out_no_q; | 2719 | goto out_no_q; |
2639 | mdev->rq_queue = q; | 2720 | device->rq_queue = q; |
2640 | q->queuedata = mdev; | 2721 | q->queuedata = device; |
2641 | 2722 | ||
2642 | disk = alloc_disk(1); | 2723 | disk = alloc_disk(1); |
2643 | if (!disk) | 2724 | if (!disk) |
2644 | goto out_no_disk; | 2725 | goto out_no_disk; |
2645 | mdev->vdisk = disk; | 2726 | device->vdisk = disk; |
2646 | 2727 | ||
2647 | set_disk_ro(disk, true); | 2728 | set_disk_ro(disk, true); |
2648 | 2729 | ||
@@ -2651,14 +2732,14 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, | |||
2651 | disk->first_minor = minor; | 2732 | disk->first_minor = minor; |
2652 | disk->fops = &drbd_ops; | 2733 | disk->fops = &drbd_ops; |
2653 | sprintf(disk->disk_name, "drbd%d", minor); | 2734 | sprintf(disk->disk_name, "drbd%d", minor); |
2654 | disk->private_data = mdev; | 2735 | disk->private_data = device; |
2655 | 2736 | ||
2656 | mdev->this_bdev = bdget(MKDEV(DRBD_MAJOR, minor)); | 2737 | device->this_bdev = bdget(MKDEV(DRBD_MAJOR, minor)); |
2657 | /* we have no partitions. we contain only ourselves. */ | 2738 | /* we have no partitions. we contain only ourselves. */ |
2658 | mdev->this_bdev->bd_contains = mdev->this_bdev; | 2739 | device->this_bdev->bd_contains = device->this_bdev; |
2659 | 2740 | ||
2660 | q->backing_dev_info.congested_fn = drbd_congested; | 2741 | q->backing_dev_info.congested_fn = drbd_congested; |
2661 | q->backing_dev_info.congested_data = mdev; | 2742 | q->backing_dev_info.congested_data = device; |
2662 | 2743 | ||
2663 | blk_queue_make_request(q, drbd_make_request); | 2744 | blk_queue_make_request(q, drbd_make_request); |
2664 | blk_queue_flush(q, REQ_FLUSH | REQ_FUA); | 2745 | blk_queue_flush(q, REQ_FLUSH | REQ_FUA); |
@@ -2667,70 +2748,125 @@ enum drbd_ret_code conn_new_minor(struct drbd_tconn *tconn, unsigned int minor, | |||
2667 | blk_queue_max_hw_sectors(q, DRBD_MAX_BIO_SIZE_SAFE >> 8); | 2748 | blk_queue_max_hw_sectors(q, DRBD_MAX_BIO_SIZE_SAFE >> 8); |
2668 | blk_queue_bounce_limit(q, BLK_BOUNCE_ANY); | 2749 | blk_queue_bounce_limit(q, BLK_BOUNCE_ANY); |
2669 | blk_queue_merge_bvec(q, drbd_merge_bvec); | 2750 | blk_queue_merge_bvec(q, drbd_merge_bvec); |
2670 | q->queue_lock = &mdev->tconn->req_lock; /* needed since we use */ | 2751 | q->queue_lock = &resource->req_lock; |
2671 | 2752 | ||
2672 | mdev->md_io_page = alloc_page(GFP_KERNEL); | 2753 | device->md_io_page = alloc_page(GFP_KERNEL); |
2673 | if (!mdev->md_io_page) | 2754 | if (!device->md_io_page) |
2674 | goto out_no_io_page; | 2755 | goto out_no_io_page; |
2675 | 2756 | ||
2676 | if (drbd_bm_init(mdev)) | 2757 | if (drbd_bm_init(device)) |
2677 | goto out_no_bitmap; | 2758 | goto out_no_bitmap; |
2678 | mdev->read_requests = RB_ROOT; | 2759 | device->read_requests = RB_ROOT; |
2679 | mdev->write_requests = RB_ROOT; | 2760 | device->write_requests = RB_ROOT; |
2680 | 2761 | ||
2681 | minor_got = idr_alloc(&minors, mdev, minor, minor + 1, GFP_KERNEL); | 2762 | id = idr_alloc(&drbd_devices, device, minor, minor + 1, GFP_KERNEL); |
2682 | if (minor_got < 0) { | 2763 | if (id < 0) { |
2683 | if (minor_got == -ENOSPC) { | 2764 | if (id == -ENOSPC) { |
2684 | err = ERR_MINOR_EXISTS; | 2765 | err = ERR_MINOR_EXISTS; |
2685 | drbd_msg_put_info("requested minor exists already"); | 2766 | drbd_msg_put_info("requested minor exists already"); |
2686 | } | 2767 | } |
2687 | goto out_no_minor_idr; | 2768 | goto out_no_minor_idr; |
2688 | } | 2769 | } |
2770 | kref_get(&device->kref); | ||
2689 | 2771 | ||
2690 | vnr_got = idr_alloc(&tconn->volumes, mdev, vnr, vnr + 1, GFP_KERNEL); | 2772 | id = idr_alloc(&resource->devices, device, vnr, vnr + 1, GFP_KERNEL); |
2691 | if (vnr_got < 0) { | 2773 | if (id < 0) { |
2692 | if (vnr_got == -ENOSPC) { | 2774 | if (id == -ENOSPC) { |
2693 | err = ERR_INVALID_REQUEST; | 2775 | err = ERR_MINOR_EXISTS; |
2694 | drbd_msg_put_info("requested volume exists already"); | 2776 | drbd_msg_put_info("requested minor exists already"); |
2695 | } | 2777 | } |
2696 | goto out_idr_remove_minor; | 2778 | goto out_idr_remove_minor; |
2697 | } | 2779 | } |
2780 | kref_get(&device->kref); | ||
2781 | |||
2782 | INIT_LIST_HEAD(&device->peer_devices); | ||
2783 | for_each_connection(connection, resource) { | ||
2784 | peer_device = kzalloc(sizeof(struct drbd_peer_device), GFP_KERNEL); | ||
2785 | if (!peer_device) | ||
2786 | goto out_idr_remove_from_resource; | ||
2787 | peer_device->connection = connection; | ||
2788 | peer_device->device = device; | ||
2789 | |||
2790 | list_add(&peer_device->peer_devices, &device->peer_devices); | ||
2791 | kref_get(&device->kref); | ||
2698 | 2792 | ||
2699 | if (init_submitter(mdev)) { | 2793 | id = idr_alloc(&connection->peer_devices, peer_device, vnr, vnr + 1, GFP_KERNEL); |
2794 | if (id < 0) { | ||
2795 | if (id == -ENOSPC) { | ||
2796 | err = ERR_INVALID_REQUEST; | ||
2797 | drbd_msg_put_info("requested volume exists already"); | ||
2798 | } | ||
2799 | goto out_idr_remove_from_resource; | ||
2800 | } | ||
2801 | kref_get(&connection->kref); | ||
2802 | } | ||
2803 | |||
2804 | if (init_submitter(device)) { | ||
2700 | err = ERR_NOMEM; | 2805 | err = ERR_NOMEM; |
2701 | drbd_msg_put_info("unable to create submit workqueue"); | 2806 | drbd_msg_put_info("unable to create submit workqueue"); |
2702 | goto out_idr_remove_vol; | 2807 | goto out_idr_remove_vol; |
2703 | } | 2808 | } |
2704 | 2809 | ||
2705 | add_disk(disk); | 2810 | add_disk(disk); |
2706 | kref_init(&mdev->kref); /* one ref for both idrs and the the add_disk */ | ||
2707 | 2811 | ||
2708 | /* inherit the connection state */ | 2812 | /* inherit the connection state */ |
2709 | mdev->state.conn = tconn->cstate; | 2813 | device->state.conn = first_connection(resource)->cstate; |
2710 | if (mdev->state.conn == C_WF_REPORT_PARAMS) | 2814 | if (device->state.conn == C_WF_REPORT_PARAMS) { |
2711 | drbd_connected(mdev); | 2815 | for_each_peer_device(peer_device, device) |
2816 | drbd_connected(peer_device); | ||
2817 | } | ||
2712 | 2818 | ||
2713 | return NO_ERROR; | 2819 | return NO_ERROR; |
2714 | 2820 | ||
2715 | out_idr_remove_vol: | 2821 | out_idr_remove_vol: |
2716 | idr_remove(&tconn->volumes, vnr_got); | 2822 | idr_remove(&connection->peer_devices, vnr); |
2823 | out_idr_remove_from_resource: | ||
2824 | for_each_connection(connection, resource) { | ||
2825 | peer_device = idr_find(&connection->peer_devices, vnr); | ||
2826 | if (peer_device) { | ||
2827 | idr_remove(&connection->peer_devices, vnr); | ||
2828 | kref_put(&connection->kref, drbd_destroy_connection); | ||
2829 | } | ||
2830 | } | ||
2831 | for_each_peer_device_safe(peer_device, tmp_peer_device, device) { | ||
2832 | list_del(&peer_device->peer_devices); | ||
2833 | kfree(peer_device); | ||
2834 | } | ||
2835 | idr_remove(&resource->devices, vnr); | ||
2717 | out_idr_remove_minor: | 2836 | out_idr_remove_minor: |
2718 | idr_remove(&minors, minor_got); | 2837 | idr_remove(&drbd_devices, minor); |
2719 | synchronize_rcu(); | 2838 | synchronize_rcu(); |
2720 | out_no_minor_idr: | 2839 | out_no_minor_idr: |
2721 | drbd_bm_cleanup(mdev); | 2840 | drbd_bm_cleanup(device); |
2722 | out_no_bitmap: | 2841 | out_no_bitmap: |
2723 | __free_page(mdev->md_io_page); | 2842 | __free_page(device->md_io_page); |
2724 | out_no_io_page: | 2843 | out_no_io_page: |
2725 | put_disk(disk); | 2844 | put_disk(disk); |
2726 | out_no_disk: | 2845 | out_no_disk: |
2727 | blk_cleanup_queue(q); | 2846 | blk_cleanup_queue(q); |
2728 | out_no_q: | 2847 | out_no_q: |
2729 | kfree(mdev); | 2848 | kref_put(&resource->kref, drbd_destroy_resource); |
2730 | kref_put(&tconn->kref, &conn_destroy); | 2849 | kfree(device); |
2731 | return err; | 2850 | return err; |
2732 | } | 2851 | } |
2733 | 2852 | ||
2853 | void drbd_delete_device(struct drbd_device *device) | ||
2854 | { | ||
2855 | struct drbd_resource *resource = device->resource; | ||
2856 | struct drbd_connection *connection; | ||
2857 | int refs = 3; | ||
2858 | |||
2859 | for_each_connection(connection, resource) { | ||
2860 | idr_remove(&connection->peer_devices, device->vnr); | ||
2861 | refs++; | ||
2862 | } | ||
2863 | idr_remove(&resource->devices, device->vnr); | ||
2864 | idr_remove(&drbd_devices, device_to_minor(device)); | ||
2865 | del_gendisk(device->vdisk); | ||
2866 | synchronize_rcu(); | ||
2867 | kref_sub(&device->kref, refs, drbd_destroy_device); | ||
2868 | } | ||
2869 | |||
2734 | int __init drbd_init(void) | 2870 | int __init drbd_init(void) |
2735 | { | 2871 | { |
2736 | int err; | 2872 | int err; |
@@ -2761,10 +2897,10 @@ int __init drbd_init(void) | |||
2761 | init_waitqueue_head(&drbd_pp_wait); | 2897 | init_waitqueue_head(&drbd_pp_wait); |
2762 | 2898 | ||
2763 | drbd_proc = NULL; /* play safe for drbd_cleanup */ | 2899 | drbd_proc = NULL; /* play safe for drbd_cleanup */ |
2764 | idr_init(&minors); | 2900 | idr_init(&drbd_devices); |
2765 | 2901 | ||
2766 | rwlock_init(&global_state_lock); | 2902 | rwlock_init(&global_state_lock); |
2767 | INIT_LIST_HEAD(&drbd_tconns); | 2903 | INIT_LIST_HEAD(&drbd_resources); |
2768 | 2904 | ||
2769 | err = drbd_genl_register(); | 2905 | err = drbd_genl_register(); |
2770 | if (err) { | 2906 | if (err) { |
@@ -2822,37 +2958,39 @@ void drbd_free_bc(struct drbd_backing_dev *ldev) | |||
2822 | kfree(ldev); | 2958 | kfree(ldev); |
2823 | } | 2959 | } |
2824 | 2960 | ||
2825 | void drbd_free_sock(struct drbd_tconn *tconn) | 2961 | void drbd_free_sock(struct drbd_connection *connection) |
2826 | { | 2962 | { |
2827 | if (tconn->data.socket) { | 2963 | if (connection->data.socket) { |
2828 | mutex_lock(&tconn->data.mutex); | 2964 | mutex_lock(&connection->data.mutex); |
2829 | kernel_sock_shutdown(tconn->data.socket, SHUT_RDWR); | 2965 | kernel_sock_shutdown(connection->data.socket, SHUT_RDWR); |
2830 | sock_release(tconn->data.socket); | 2966 | sock_release(connection->data.socket); |
2831 | tconn->data.socket = NULL; | 2967 | connection->data.socket = NULL; |
2832 | mutex_unlock(&tconn->data.mutex); | 2968 | mutex_unlock(&connection->data.mutex); |
2833 | } | 2969 | } |
2834 | if (tconn->meta.socket) { | 2970 | if (connection->meta.socket) { |
2835 | mutex_lock(&tconn->meta.mutex); | 2971 | mutex_lock(&connection->meta.mutex); |
2836 | kernel_sock_shutdown(tconn->meta.socket, SHUT_RDWR); | 2972 | kernel_sock_shutdown(connection->meta.socket, SHUT_RDWR); |
2837 | sock_release(tconn->meta.socket); | 2973 | sock_release(connection->meta.socket); |
2838 | tconn->meta.socket = NULL; | 2974 | connection->meta.socket = NULL; |
2839 | mutex_unlock(&tconn->meta.mutex); | 2975 | mutex_unlock(&connection->meta.mutex); |
2840 | } | 2976 | } |
2841 | } | 2977 | } |
2842 | 2978 | ||
2843 | /* meta data management */ | 2979 | /* meta data management */ |
2844 | 2980 | ||
2845 | void conn_md_sync(struct drbd_tconn *tconn) | 2981 | void conn_md_sync(struct drbd_connection *connection) |
2846 | { | 2982 | { |
2847 | struct drbd_conf *mdev; | 2983 | struct drbd_peer_device *peer_device; |
2848 | int vnr; | 2984 | int vnr; |
2849 | 2985 | ||
2850 | rcu_read_lock(); | 2986 | rcu_read_lock(); |
2851 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 2987 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
2852 | kref_get(&mdev->kref); | 2988 | struct drbd_device *device = peer_device->device; |
2989 | |||
2990 | kref_get(&device->kref); | ||
2853 | rcu_read_unlock(); | 2991 | rcu_read_unlock(); |
2854 | drbd_md_sync(mdev); | 2992 | drbd_md_sync(device); |
2855 | kref_put(&mdev->kref, &drbd_minor_destroy); | 2993 | kref_put(&device->kref, drbd_destroy_device); |
2856 | rcu_read_lock(); | 2994 | rcu_read_lock(); |
2857 | } | 2995 | } |
2858 | rcu_read_unlock(); | 2996 | rcu_read_unlock(); |
@@ -2883,7 +3021,7 @@ struct meta_data_on_disk { | |||
2883 | 3021 | ||
2884 | 3022 | ||
2885 | 3023 | ||
2886 | void drbd_md_write(struct drbd_conf *mdev, void *b) | 3024 | void drbd_md_write(struct drbd_device *device, void *b) |
2887 | { | 3025 | { |
2888 | struct meta_data_on_disk *buffer = b; | 3026 | struct meta_data_on_disk *buffer = b; |
2889 | sector_t sector; | 3027 | sector_t sector; |
@@ -2891,39 +3029,39 @@ void drbd_md_write(struct drbd_conf *mdev, void *b) | |||
2891 | 3029 | ||
2892 | memset(buffer, 0, sizeof(*buffer)); | 3030 | memset(buffer, 0, sizeof(*buffer)); |
2893 | 3031 | ||
2894 | buffer->la_size_sect = cpu_to_be64(drbd_get_capacity(mdev->this_bdev)); | 3032 | buffer->la_size_sect = cpu_to_be64(drbd_get_capacity(device->this_bdev)); |
2895 | for (i = UI_CURRENT; i < UI_SIZE; i++) | 3033 | for (i = UI_CURRENT; i < UI_SIZE; i++) |
2896 | buffer->uuid[i] = cpu_to_be64(mdev->ldev->md.uuid[i]); | 3034 | buffer->uuid[i] = cpu_to_be64(device->ldev->md.uuid[i]); |
2897 | buffer->flags = cpu_to_be32(mdev->ldev->md.flags); | 3035 | buffer->flags = cpu_to_be32(device->ldev->md.flags); |
2898 | buffer->magic = cpu_to_be32(DRBD_MD_MAGIC_84_UNCLEAN); | 3036 | buffer->magic = cpu_to_be32(DRBD_MD_MAGIC_84_UNCLEAN); |
2899 | 3037 | ||
2900 | buffer->md_size_sect = cpu_to_be32(mdev->ldev->md.md_size_sect); | 3038 | buffer->md_size_sect = cpu_to_be32(device->ldev->md.md_size_sect); |
2901 | buffer->al_offset = cpu_to_be32(mdev->ldev->md.al_offset); | 3039 | buffer->al_offset = cpu_to_be32(device->ldev->md.al_offset); |
2902 | buffer->al_nr_extents = cpu_to_be32(mdev->act_log->nr_elements); | 3040 | buffer->al_nr_extents = cpu_to_be32(device->act_log->nr_elements); |
2903 | buffer->bm_bytes_per_bit = cpu_to_be32(BM_BLOCK_SIZE); | 3041 | buffer->bm_bytes_per_bit = cpu_to_be32(BM_BLOCK_SIZE); |
2904 | buffer->device_uuid = cpu_to_be64(mdev->ldev->md.device_uuid); | 3042 | buffer->device_uuid = cpu_to_be64(device->ldev->md.device_uuid); |
2905 | 3043 | ||
2906 | buffer->bm_offset = cpu_to_be32(mdev->ldev->md.bm_offset); | 3044 | buffer->bm_offset = cpu_to_be32(device->ldev->md.bm_offset); |
2907 | buffer->la_peer_max_bio_size = cpu_to_be32(mdev->peer_max_bio_size); | 3045 | buffer->la_peer_max_bio_size = cpu_to_be32(device->peer_max_bio_size); |
2908 | 3046 | ||
2909 | buffer->al_stripes = cpu_to_be32(mdev->ldev->md.al_stripes); | 3047 | buffer->al_stripes = cpu_to_be32(device->ldev->md.al_stripes); |
2910 | buffer->al_stripe_size_4k = cpu_to_be32(mdev->ldev->md.al_stripe_size_4k); | 3048 | buffer->al_stripe_size_4k = cpu_to_be32(device->ldev->md.al_stripe_size_4k); |
2911 | 3049 | ||
2912 | D_ASSERT(drbd_md_ss(mdev->ldev) == mdev->ldev->md.md_offset); | 3050 | D_ASSERT(device, drbd_md_ss(device->ldev) == device->ldev->md.md_offset); |
2913 | sector = mdev->ldev->md.md_offset; | 3051 | sector = device->ldev->md.md_offset; |
2914 | 3052 | ||
2915 | if (drbd_md_sync_page_io(mdev, mdev->ldev, sector, WRITE)) { | 3053 | if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) { |
2916 | /* this was a try anyways ... */ | 3054 | /* this was a try anyways ... */ |
2917 | dev_err(DEV, "meta data update failed!\n"); | 3055 | drbd_err(device, "meta data update failed!\n"); |
2918 | drbd_chk_io_error(mdev, 1, DRBD_META_IO_ERROR); | 3056 | drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR); |
2919 | } | 3057 | } |
2920 | } | 3058 | } |
2921 | 3059 | ||
2922 | /** | 3060 | /** |
2923 | * drbd_md_sync() - Writes the meta data super block if the MD_DIRTY flag bit is set | 3061 | * drbd_md_sync() - Writes the meta data super block if the MD_DIRTY flag bit is set |
2924 | * @mdev: DRBD device. | 3062 | * @device: DRBD device. |
2925 | */ | 3063 | */ |
2926 | void drbd_md_sync(struct drbd_conf *mdev) | 3064 | void drbd_md_sync(struct drbd_device *device) |
2927 | { | 3065 | { |
2928 | struct meta_data_on_disk *buffer; | 3066 | struct meta_data_on_disk *buffer; |
2929 | 3067 | ||
@@ -2931,32 +3069,32 @@ void drbd_md_sync(struct drbd_conf *mdev) | |||
2931 | BUILD_BUG_ON(UI_SIZE != 4); | 3069 | BUILD_BUG_ON(UI_SIZE != 4); |
2932 | BUILD_BUG_ON(sizeof(struct meta_data_on_disk) != 4096); | 3070 | BUILD_BUG_ON(sizeof(struct meta_data_on_disk) != 4096); |
2933 | 3071 | ||
2934 | del_timer(&mdev->md_sync_timer); | 3072 | del_timer(&device->md_sync_timer); |
2935 | /* timer may be rearmed by drbd_md_mark_dirty() now. */ | 3073 | /* timer may be rearmed by drbd_md_mark_dirty() now. */ |
2936 | if (!test_and_clear_bit(MD_DIRTY, &mdev->flags)) | 3074 | if (!test_and_clear_bit(MD_DIRTY, &device->flags)) |
2937 | return; | 3075 | return; |
2938 | 3076 | ||
2939 | /* We use here D_FAILED and not D_ATTACHING because we try to write | 3077 | /* We use here D_FAILED and not D_ATTACHING because we try to write |
2940 | * metadata even if we detach due to a disk failure! */ | 3078 | * metadata even if we detach due to a disk failure! */ |
2941 | if (!get_ldev_if_state(mdev, D_FAILED)) | 3079 | if (!get_ldev_if_state(device, D_FAILED)) |
2942 | return; | 3080 | return; |
2943 | 3081 | ||
2944 | buffer = drbd_md_get_buffer(mdev); | 3082 | buffer = drbd_md_get_buffer(device); |
2945 | if (!buffer) | 3083 | if (!buffer) |
2946 | goto out; | 3084 | goto out; |
2947 | 3085 | ||
2948 | drbd_md_write(mdev, buffer); | 3086 | drbd_md_write(device, buffer); |
2949 | 3087 | ||
2950 | /* Update mdev->ldev->md.la_size_sect, | 3088 | /* Update device->ldev->md.la_size_sect, |
2951 | * since we updated it on metadata. */ | 3089 | * since we updated it on metadata. */ |
2952 | mdev->ldev->md.la_size_sect = drbd_get_capacity(mdev->this_bdev); | 3090 | device->ldev->md.la_size_sect = drbd_get_capacity(device->this_bdev); |
2953 | 3091 | ||
2954 | drbd_md_put_buffer(mdev); | 3092 | drbd_md_put_buffer(device); |
2955 | out: | 3093 | out: |
2956 | put_ldev(mdev); | 3094 | put_ldev(device); |
2957 | } | 3095 | } |
2958 | 3096 | ||
2959 | static int check_activity_log_stripe_size(struct drbd_conf *mdev, | 3097 | static int check_activity_log_stripe_size(struct drbd_device *device, |
2960 | struct meta_data_on_disk *on_disk, | 3098 | struct meta_data_on_disk *on_disk, |
2961 | struct drbd_md *in_core) | 3099 | struct drbd_md *in_core) |
2962 | { | 3100 | { |
@@ -2996,12 +3134,12 @@ static int check_activity_log_stripe_size(struct drbd_conf *mdev, | |||
2996 | 3134 | ||
2997 | return 0; | 3135 | return 0; |
2998 | err: | 3136 | err: |
2999 | dev_err(DEV, "invalid activity log striping: al_stripes=%u, al_stripe_size_4k=%u\n", | 3137 | drbd_err(device, "invalid activity log striping: al_stripes=%u, al_stripe_size_4k=%u\n", |
3000 | al_stripes, al_stripe_size_4k); | 3138 | al_stripes, al_stripe_size_4k); |
3001 | return -EINVAL; | 3139 | return -EINVAL; |
3002 | } | 3140 | } |
3003 | 3141 | ||
3004 | static int check_offsets_and_sizes(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | 3142 | static int check_offsets_and_sizes(struct drbd_device *device, struct drbd_backing_dev *bdev) |
3005 | { | 3143 | { |
3006 | sector_t capacity = drbd_get_capacity(bdev->md_bdev); | 3144 | sector_t capacity = drbd_get_capacity(bdev->md_bdev); |
3007 | struct drbd_md *in_core = &bdev->md; | 3145 | struct drbd_md *in_core = &bdev->md; |
@@ -3068,7 +3206,7 @@ static int check_offsets_and_sizes(struct drbd_conf *mdev, struct drbd_backing_d | |||
3068 | return 0; | 3206 | return 0; |
3069 | 3207 | ||
3070 | err: | 3208 | err: |
3071 | dev_err(DEV, "meta data offsets don't make sense: idx=%d " | 3209 | drbd_err(device, "meta data offsets don't make sense: idx=%d " |
3072 | "al_s=%u, al_sz4k=%u, al_offset=%d, bm_offset=%d, " | 3210 | "al_s=%u, al_sz4k=%u, al_offset=%d, bm_offset=%d, " |
3073 | "md_size_sect=%u, la_size=%llu, md_capacity=%llu\n", | 3211 | "md_size_sect=%u, la_size=%llu, md_capacity=%llu\n", |
3074 | in_core->meta_dev_idx, | 3212 | in_core->meta_dev_idx, |
@@ -3083,25 +3221,25 @@ err: | |||
3083 | 3221 | ||
3084 | /** | 3222 | /** |
3085 | * drbd_md_read() - Reads in the meta data super block | 3223 | * drbd_md_read() - Reads in the meta data super block |
3086 | * @mdev: DRBD device. | 3224 | * @device: DRBD device. |
3087 | * @bdev: Device from which the meta data should be read in. | 3225 | * @bdev: Device from which the meta data should be read in. |
3088 | * | 3226 | * |
3089 | * Return NO_ERROR on success, and an enum drbd_ret_code in case | 3227 | * Return NO_ERROR on success, and an enum drbd_ret_code in case |
3090 | * something goes wrong. | 3228 | * something goes wrong. |
3091 | * | 3229 | * |
3092 | * Called exactly once during drbd_adm_attach(), while still being D_DISKLESS, | 3230 | * Called exactly once during drbd_adm_attach(), while still being D_DISKLESS, |
3093 | * even before @bdev is assigned to @mdev->ldev. | 3231 | * even before @bdev is assigned to @device->ldev. |
3094 | */ | 3232 | */ |
3095 | int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | 3233 | int drbd_md_read(struct drbd_device *device, struct drbd_backing_dev *bdev) |
3096 | { | 3234 | { |
3097 | struct meta_data_on_disk *buffer; | 3235 | struct meta_data_on_disk *buffer; |
3098 | u32 magic, flags; | 3236 | u32 magic, flags; |
3099 | int i, rv = NO_ERROR; | 3237 | int i, rv = NO_ERROR; |
3100 | 3238 | ||
3101 | if (mdev->state.disk != D_DISKLESS) | 3239 | if (device->state.disk != D_DISKLESS) |
3102 | return ERR_DISK_CONFIGURED; | 3240 | return ERR_DISK_CONFIGURED; |
3103 | 3241 | ||
3104 | buffer = drbd_md_get_buffer(mdev); | 3242 | buffer = drbd_md_get_buffer(device); |
3105 | if (!buffer) | 3243 | if (!buffer) |
3106 | return ERR_NOMEM; | 3244 | return ERR_NOMEM; |
3107 | 3245 | ||
@@ -3110,10 +3248,10 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | |||
3110 | bdev->md.meta_dev_idx = bdev->disk_conf->meta_dev_idx; | 3248 | bdev->md.meta_dev_idx = bdev->disk_conf->meta_dev_idx; |
3111 | bdev->md.md_offset = drbd_md_ss(bdev); | 3249 | bdev->md.md_offset = drbd_md_ss(bdev); |
3112 | 3250 | ||
3113 | if (drbd_md_sync_page_io(mdev, bdev, bdev->md.md_offset, READ)) { | 3251 | if (drbd_md_sync_page_io(device, bdev, bdev->md.md_offset, READ)) { |
3114 | /* NOTE: can't do normal error processing here as this is | 3252 | /* NOTE: can't do normal error processing here as this is |
3115 | called BEFORE disk is attached */ | 3253 | called BEFORE disk is attached */ |
3116 | dev_err(DEV, "Error while reading metadata.\n"); | 3254 | drbd_err(device, "Error while reading metadata.\n"); |
3117 | rv = ERR_IO_MD_DISK; | 3255 | rv = ERR_IO_MD_DISK; |
3118 | goto err; | 3256 | goto err; |
3119 | } | 3257 | } |
@@ -3123,7 +3261,7 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | |||
3123 | if (magic == DRBD_MD_MAGIC_84_UNCLEAN || | 3261 | if (magic == DRBD_MD_MAGIC_84_UNCLEAN || |
3124 | (magic == DRBD_MD_MAGIC_08 && !(flags & MDF_AL_CLEAN))) { | 3262 | (magic == DRBD_MD_MAGIC_08 && !(flags & MDF_AL_CLEAN))) { |
3125 | /* btw: that's Activity Log clean, not "all" clean. */ | 3263 | /* btw: that's Activity Log clean, not "all" clean. */ |
3126 | dev_err(DEV, "Found unclean meta data. Did you \"drbdadm apply-al\"?\n"); | 3264 | drbd_err(device, "Found unclean meta data. Did you \"drbdadm apply-al\"?\n"); |
3127 | rv = ERR_MD_UNCLEAN; | 3265 | rv = ERR_MD_UNCLEAN; |
3128 | goto err; | 3266 | goto err; |
3129 | } | 3267 | } |
@@ -3131,14 +3269,14 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | |||
3131 | rv = ERR_MD_INVALID; | 3269 | rv = ERR_MD_INVALID; |
3132 | if (magic != DRBD_MD_MAGIC_08) { | 3270 | if (magic != DRBD_MD_MAGIC_08) { |
3133 | if (magic == DRBD_MD_MAGIC_07) | 3271 | if (magic == DRBD_MD_MAGIC_07) |
3134 | dev_err(DEV, "Found old (0.7) meta data magic. Did you \"drbdadm create-md\"?\n"); | 3272 | drbd_err(device, "Found old (0.7) meta data magic. Did you \"drbdadm create-md\"?\n"); |
3135 | else | 3273 | else |
3136 | dev_err(DEV, "Meta data magic not found. Did you \"drbdadm create-md\"?\n"); | 3274 | drbd_err(device, "Meta data magic not found. Did you \"drbdadm create-md\"?\n"); |
3137 | goto err; | 3275 | goto err; |
3138 | } | 3276 | } |
3139 | 3277 | ||
3140 | if (be32_to_cpu(buffer->bm_bytes_per_bit) != BM_BLOCK_SIZE) { | 3278 | if (be32_to_cpu(buffer->bm_bytes_per_bit) != BM_BLOCK_SIZE) { |
3141 | dev_err(DEV, "unexpected bm_bytes_per_bit: %u (expected %u)\n", | 3279 | drbd_err(device, "unexpected bm_bytes_per_bit: %u (expected %u)\n", |
3142 | be32_to_cpu(buffer->bm_bytes_per_bit), BM_BLOCK_SIZE); | 3280 | be32_to_cpu(buffer->bm_bytes_per_bit), BM_BLOCK_SIZE); |
3143 | goto err; | 3281 | goto err; |
3144 | } | 3282 | } |
@@ -3155,182 +3293,182 @@ int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev) | |||
3155 | bdev->md.al_offset = be32_to_cpu(buffer->al_offset); | 3293 | bdev->md.al_offset = be32_to_cpu(buffer->al_offset); |
3156 | bdev->md.bm_offset = be32_to_cpu(buffer->bm_offset); | 3294 | bdev->md.bm_offset = be32_to_cpu(buffer->bm_offset); |
3157 | 3295 | ||
3158 | if (check_activity_log_stripe_size(mdev, buffer, &bdev->md)) | 3296 | if (check_activity_log_stripe_size(device, buffer, &bdev->md)) |
3159 | goto err; | 3297 | goto err; |
3160 | if (check_offsets_and_sizes(mdev, bdev)) | 3298 | if (check_offsets_and_sizes(device, bdev)) |
3161 | goto err; | 3299 | goto err; |
3162 | 3300 | ||
3163 | if (be32_to_cpu(buffer->bm_offset) != bdev->md.bm_offset) { | 3301 | if (be32_to_cpu(buffer->bm_offset) != bdev->md.bm_offset) { |
3164 | dev_err(DEV, "unexpected bm_offset: %d (expected %d)\n", | 3302 | drbd_err(device, "unexpected bm_offset: %d (expected %d)\n", |
3165 | be32_to_cpu(buffer->bm_offset), bdev->md.bm_offset); | 3303 | be32_to_cpu(buffer->bm_offset), bdev->md.bm_offset); |
3166 | goto err; | 3304 | goto err; |
3167 | } | 3305 | } |
3168 | if (be32_to_cpu(buffer->md_size_sect) != bdev->md.md_size_sect) { | 3306 | if (be32_to_cpu(buffer->md_size_sect) != bdev->md.md_size_sect) { |
3169 | dev_err(DEV, "unexpected md_size: %u (expected %u)\n", | 3307 | drbd_err(device, "unexpected md_size: %u (expected %u)\n", |
3170 | be32_to_cpu(buffer->md_size_sect), bdev->md.md_size_sect); | 3308 | be32_to_cpu(buffer->md_size_sect), bdev->md.md_size_sect); |
3171 | goto err; | 3309 | goto err; |
3172 | } | 3310 | } |
3173 | 3311 | ||
3174 | rv = NO_ERROR; | 3312 | rv = NO_ERROR; |
3175 | 3313 | ||
3176 | spin_lock_irq(&mdev->tconn->req_lock); | 3314 | spin_lock_irq(&device->resource->req_lock); |
3177 | if (mdev->state.conn < C_CONNECTED) { | 3315 | if (device->state.conn < C_CONNECTED) { |
3178 | unsigned int peer; | 3316 | unsigned int peer; |
3179 | peer = be32_to_cpu(buffer->la_peer_max_bio_size); | 3317 | peer = be32_to_cpu(buffer->la_peer_max_bio_size); |
3180 | peer = max(peer, DRBD_MAX_BIO_SIZE_SAFE); | 3318 | peer = max(peer, DRBD_MAX_BIO_SIZE_SAFE); |
3181 | mdev->peer_max_bio_size = peer; | 3319 | device->peer_max_bio_size = peer; |
3182 | } | 3320 | } |
3183 | spin_unlock_irq(&mdev->tconn->req_lock); | 3321 | spin_unlock_irq(&device->resource->req_lock); |
3184 | 3322 | ||
3185 | err: | 3323 | err: |
3186 | drbd_md_put_buffer(mdev); | 3324 | drbd_md_put_buffer(device); |
3187 | 3325 | ||
3188 | return rv; | 3326 | return rv; |
3189 | } | 3327 | } |
3190 | 3328 | ||
3191 | /** | 3329 | /** |
3192 | * drbd_md_mark_dirty() - Mark meta data super block as dirty | 3330 | * drbd_md_mark_dirty() - Mark meta data super block as dirty |
3193 | * @mdev: DRBD device. | 3331 | * @device: DRBD device. |
3194 | * | 3332 | * |
3195 | * Call this function if you change anything that should be written to | 3333 | * Call this function if you change anything that should be written to |
3196 | * the meta-data super block. This function sets MD_DIRTY, and starts a | 3334 | * the meta-data super block. This function sets MD_DIRTY, and starts a |
3197 | * timer that ensures that within five seconds you have to call drbd_md_sync(). | 3335 | * timer that ensures that within five seconds you have to call drbd_md_sync(). |
3198 | */ | 3336 | */ |
3199 | #ifdef DEBUG | 3337 | #ifdef DEBUG |
3200 | void drbd_md_mark_dirty_(struct drbd_conf *mdev, unsigned int line, const char *func) | 3338 | void drbd_md_mark_dirty_(struct drbd_device *device, unsigned int line, const char *func) |
3201 | { | 3339 | { |
3202 | if (!test_and_set_bit(MD_DIRTY, &mdev->flags)) { | 3340 | if (!test_and_set_bit(MD_DIRTY, &device->flags)) { |
3203 | mod_timer(&mdev->md_sync_timer, jiffies + HZ); | 3341 | mod_timer(&device->md_sync_timer, jiffies + HZ); |
3204 | mdev->last_md_mark_dirty.line = line; | 3342 | device->last_md_mark_dirty.line = line; |
3205 | mdev->last_md_mark_dirty.func = func; | 3343 | device->last_md_mark_dirty.func = func; |
3206 | } | 3344 | } |
3207 | } | 3345 | } |
3208 | #else | 3346 | #else |
3209 | void drbd_md_mark_dirty(struct drbd_conf *mdev) | 3347 | void drbd_md_mark_dirty(struct drbd_device *device) |
3210 | { | 3348 | { |
3211 | if (!test_and_set_bit(MD_DIRTY, &mdev->flags)) | 3349 | if (!test_and_set_bit(MD_DIRTY, &device->flags)) |
3212 | mod_timer(&mdev->md_sync_timer, jiffies + 5*HZ); | 3350 | mod_timer(&device->md_sync_timer, jiffies + 5*HZ); |
3213 | } | 3351 | } |
3214 | #endif | 3352 | #endif |
3215 | 3353 | ||
3216 | void drbd_uuid_move_history(struct drbd_conf *mdev) __must_hold(local) | 3354 | void drbd_uuid_move_history(struct drbd_device *device) __must_hold(local) |
3217 | { | 3355 | { |
3218 | int i; | 3356 | int i; |
3219 | 3357 | ||
3220 | for (i = UI_HISTORY_START; i < UI_HISTORY_END; i++) | 3358 | for (i = UI_HISTORY_START; i < UI_HISTORY_END; i++) |
3221 | mdev->ldev->md.uuid[i+1] = mdev->ldev->md.uuid[i]; | 3359 | device->ldev->md.uuid[i+1] = device->ldev->md.uuid[i]; |
3222 | } | 3360 | } |
3223 | 3361 | ||
3224 | void __drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local) | 3362 | void __drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local) |
3225 | { | 3363 | { |
3226 | if (idx == UI_CURRENT) { | 3364 | if (idx == UI_CURRENT) { |
3227 | if (mdev->state.role == R_PRIMARY) | 3365 | if (device->state.role == R_PRIMARY) |
3228 | val |= 1; | 3366 | val |= 1; |
3229 | else | 3367 | else |
3230 | val &= ~((u64)1); | 3368 | val &= ~((u64)1); |
3231 | 3369 | ||
3232 | drbd_set_ed_uuid(mdev, val); | 3370 | drbd_set_ed_uuid(device, val); |
3233 | } | 3371 | } |
3234 | 3372 | ||
3235 | mdev->ldev->md.uuid[idx] = val; | 3373 | device->ldev->md.uuid[idx] = val; |
3236 | drbd_md_mark_dirty(mdev); | 3374 | drbd_md_mark_dirty(device); |
3237 | } | 3375 | } |
3238 | 3376 | ||
3239 | void _drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local) | 3377 | void _drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local) |
3240 | { | 3378 | { |
3241 | unsigned long flags; | 3379 | unsigned long flags; |
3242 | spin_lock_irqsave(&mdev->ldev->md.uuid_lock, flags); | 3380 | spin_lock_irqsave(&device->ldev->md.uuid_lock, flags); |
3243 | __drbd_uuid_set(mdev, idx, val); | 3381 | __drbd_uuid_set(device, idx, val); |
3244 | spin_unlock_irqrestore(&mdev->ldev->md.uuid_lock, flags); | 3382 | spin_unlock_irqrestore(&device->ldev->md.uuid_lock, flags); |
3245 | } | 3383 | } |
3246 | 3384 | ||
3247 | void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local) | 3385 | void drbd_uuid_set(struct drbd_device *device, int idx, u64 val) __must_hold(local) |
3248 | { | 3386 | { |
3249 | unsigned long flags; | 3387 | unsigned long flags; |
3250 | spin_lock_irqsave(&mdev->ldev->md.uuid_lock, flags); | 3388 | spin_lock_irqsave(&device->ldev->md.uuid_lock, flags); |
3251 | if (mdev->ldev->md.uuid[idx]) { | 3389 | if (device->ldev->md.uuid[idx]) { |
3252 | drbd_uuid_move_history(mdev); | 3390 | drbd_uuid_move_history(device); |
3253 | mdev->ldev->md.uuid[UI_HISTORY_START] = mdev->ldev->md.uuid[idx]; | 3391 | device->ldev->md.uuid[UI_HISTORY_START] = device->ldev->md.uuid[idx]; |
3254 | } | 3392 | } |
3255 | __drbd_uuid_set(mdev, idx, val); | 3393 | __drbd_uuid_set(device, idx, val); |
3256 | spin_unlock_irqrestore(&mdev->ldev->md.uuid_lock, flags); | 3394 | spin_unlock_irqrestore(&device->ldev->md.uuid_lock, flags); |
3257 | } | 3395 | } |
3258 | 3396 | ||
3259 | /** | 3397 | /** |
3260 | * drbd_uuid_new_current() - Creates a new current UUID | 3398 | * drbd_uuid_new_current() - Creates a new current UUID |
3261 | * @mdev: DRBD device. | 3399 | * @device: DRBD device. |
3262 | * | 3400 | * |
3263 | * Creates a new current UUID, and rotates the old current UUID into | 3401 | * Creates a new current UUID, and rotates the old current UUID into |
3264 | * the bitmap slot. Causes an incremental resync upon next connect. | 3402 | * the bitmap slot. Causes an incremental resync upon next connect. |
3265 | */ | 3403 | */ |
3266 | void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local) | 3404 | void drbd_uuid_new_current(struct drbd_device *device) __must_hold(local) |
3267 | { | 3405 | { |
3268 | u64 val; | 3406 | u64 val; |
3269 | unsigned long long bm_uuid; | 3407 | unsigned long long bm_uuid; |
3270 | 3408 | ||
3271 | get_random_bytes(&val, sizeof(u64)); | 3409 | get_random_bytes(&val, sizeof(u64)); |
3272 | 3410 | ||
3273 | spin_lock_irq(&mdev->ldev->md.uuid_lock); | 3411 | spin_lock_irq(&device->ldev->md.uuid_lock); |
3274 | bm_uuid = mdev->ldev->md.uuid[UI_BITMAP]; | 3412 | bm_uuid = device->ldev->md.uuid[UI_BITMAP]; |
3275 | 3413 | ||
3276 | if (bm_uuid) | 3414 | if (bm_uuid) |
3277 | dev_warn(DEV, "bm UUID was already set: %llX\n", bm_uuid); | 3415 | drbd_warn(device, "bm UUID was already set: %llX\n", bm_uuid); |
3278 | 3416 | ||
3279 | mdev->ldev->md.uuid[UI_BITMAP] = mdev->ldev->md.uuid[UI_CURRENT]; | 3417 | device->ldev->md.uuid[UI_BITMAP] = device->ldev->md.uuid[UI_CURRENT]; |
3280 | __drbd_uuid_set(mdev, UI_CURRENT, val); | 3418 | __drbd_uuid_set(device, UI_CURRENT, val); |
3281 | spin_unlock_irq(&mdev->ldev->md.uuid_lock); | 3419 | spin_unlock_irq(&device->ldev->md.uuid_lock); |
3282 | 3420 | ||
3283 | drbd_print_uuids(mdev, "new current UUID"); | 3421 | drbd_print_uuids(device, "new current UUID"); |
3284 | /* get it to stable storage _now_ */ | 3422 | /* get it to stable storage _now_ */ |
3285 | drbd_md_sync(mdev); | 3423 | drbd_md_sync(device); |
3286 | } | 3424 | } |
3287 | 3425 | ||
3288 | void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local) | 3426 | void drbd_uuid_set_bm(struct drbd_device *device, u64 val) __must_hold(local) |
3289 | { | 3427 | { |
3290 | unsigned long flags; | 3428 | unsigned long flags; |
3291 | if (mdev->ldev->md.uuid[UI_BITMAP] == 0 && val == 0) | 3429 | if (device->ldev->md.uuid[UI_BITMAP] == 0 && val == 0) |
3292 | return; | 3430 | return; |
3293 | 3431 | ||
3294 | spin_lock_irqsave(&mdev->ldev->md.uuid_lock, flags); | 3432 | spin_lock_irqsave(&device->ldev->md.uuid_lock, flags); |
3295 | if (val == 0) { | 3433 | if (val == 0) { |
3296 | drbd_uuid_move_history(mdev); | 3434 | drbd_uuid_move_history(device); |
3297 | mdev->ldev->md.uuid[UI_HISTORY_START] = mdev->ldev->md.uuid[UI_BITMAP]; | 3435 | device->ldev->md.uuid[UI_HISTORY_START] = device->ldev->md.uuid[UI_BITMAP]; |
3298 | mdev->ldev->md.uuid[UI_BITMAP] = 0; | 3436 | device->ldev->md.uuid[UI_BITMAP] = 0; |
3299 | } else { | 3437 | } else { |
3300 | unsigned long long bm_uuid = mdev->ldev->md.uuid[UI_BITMAP]; | 3438 | unsigned long long bm_uuid = device->ldev->md.uuid[UI_BITMAP]; |
3301 | if (bm_uuid) | 3439 | if (bm_uuid) |
3302 | dev_warn(DEV, "bm UUID was already set: %llX\n", bm_uuid); | 3440 | drbd_warn(device, "bm UUID was already set: %llX\n", bm_uuid); |
3303 | 3441 | ||
3304 | mdev->ldev->md.uuid[UI_BITMAP] = val & ~((u64)1); | 3442 | device->ldev->md.uuid[UI_BITMAP] = val & ~((u64)1); |
3305 | } | 3443 | } |
3306 | spin_unlock_irqrestore(&mdev->ldev->md.uuid_lock, flags); | 3444 | spin_unlock_irqrestore(&device->ldev->md.uuid_lock, flags); |
3307 | 3445 | ||
3308 | drbd_md_mark_dirty(mdev); | 3446 | drbd_md_mark_dirty(device); |
3309 | } | 3447 | } |
3310 | 3448 | ||
3311 | /** | 3449 | /** |
3312 | * drbd_bmio_set_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io() | 3450 | * drbd_bmio_set_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io() |
3313 | * @mdev: DRBD device. | 3451 | * @device: DRBD device. |
3314 | * | 3452 | * |
3315 | * Sets all bits in the bitmap and writes the whole bitmap to stable storage. | 3453 | * Sets all bits in the bitmap and writes the whole bitmap to stable storage. |
3316 | */ | 3454 | */ |
3317 | int drbd_bmio_set_n_write(struct drbd_conf *mdev) | 3455 | int drbd_bmio_set_n_write(struct drbd_device *device) |
3318 | { | 3456 | { |
3319 | int rv = -EIO; | 3457 | int rv = -EIO; |
3320 | 3458 | ||
3321 | if (get_ldev_if_state(mdev, D_ATTACHING)) { | 3459 | if (get_ldev_if_state(device, D_ATTACHING)) { |
3322 | drbd_md_set_flag(mdev, MDF_FULL_SYNC); | 3460 | drbd_md_set_flag(device, MDF_FULL_SYNC); |
3323 | drbd_md_sync(mdev); | 3461 | drbd_md_sync(device); |
3324 | drbd_bm_set_all(mdev); | 3462 | drbd_bm_set_all(device); |
3325 | 3463 | ||
3326 | rv = drbd_bm_write(mdev); | 3464 | rv = drbd_bm_write(device); |
3327 | 3465 | ||
3328 | if (!rv) { | 3466 | if (!rv) { |
3329 | drbd_md_clear_flag(mdev, MDF_FULL_SYNC); | 3467 | drbd_md_clear_flag(device, MDF_FULL_SYNC); |
3330 | drbd_md_sync(mdev); | 3468 | drbd_md_sync(device); |
3331 | } | 3469 | } |
3332 | 3470 | ||
3333 | put_ldev(mdev); | 3471 | put_ldev(device); |
3334 | } | 3472 | } |
3335 | 3473 | ||
3336 | return rv; | 3474 | return rv; |
@@ -3338,19 +3476,19 @@ int drbd_bmio_set_n_write(struct drbd_conf *mdev) | |||
3338 | 3476 | ||
3339 | /** | 3477 | /** |
3340 | * drbd_bmio_clear_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io() | 3478 | * drbd_bmio_clear_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io() |
3341 | * @mdev: DRBD device. | 3479 | * @device: DRBD device. |
3342 | * | 3480 | * |
3343 | * Clears all bits in the bitmap and writes the whole bitmap to stable storage. | 3481 | * Clears all bits in the bitmap and writes the whole bitmap to stable storage. |
3344 | */ | 3482 | */ |
3345 | int drbd_bmio_clear_n_write(struct drbd_conf *mdev) | 3483 | int drbd_bmio_clear_n_write(struct drbd_device *device) |
3346 | { | 3484 | { |
3347 | int rv = -EIO; | 3485 | int rv = -EIO; |
3348 | 3486 | ||
3349 | drbd_resume_al(mdev); | 3487 | drbd_resume_al(device); |
3350 | if (get_ldev_if_state(mdev, D_ATTACHING)) { | 3488 | if (get_ldev_if_state(device, D_ATTACHING)) { |
3351 | drbd_bm_clear_all(mdev); | 3489 | drbd_bm_clear_all(device); |
3352 | rv = drbd_bm_write(mdev); | 3490 | rv = drbd_bm_write(device); |
3353 | put_ldev(mdev); | 3491 | put_ldev(device); |
3354 | } | 3492 | } |
3355 | 3493 | ||
3356 | return rv; | 3494 | return rv; |
@@ -3358,50 +3496,52 @@ int drbd_bmio_clear_n_write(struct drbd_conf *mdev) | |||
3358 | 3496 | ||
3359 | static int w_bitmap_io(struct drbd_work *w, int unused) | 3497 | static int w_bitmap_io(struct drbd_work *w, int unused) |
3360 | { | 3498 | { |
3361 | struct bm_io_work *work = container_of(w, struct bm_io_work, w); | 3499 | struct drbd_device *device = |
3362 | struct drbd_conf *mdev = w->mdev; | 3500 | container_of(w, struct drbd_device, bm_io_work.w); |
3501 | struct bm_io_work *work = &device->bm_io_work; | ||
3363 | int rv = -EIO; | 3502 | int rv = -EIO; |
3364 | 3503 | ||
3365 | D_ASSERT(atomic_read(&mdev->ap_bio_cnt) == 0); | 3504 | D_ASSERT(device, atomic_read(&device->ap_bio_cnt) == 0); |
3366 | 3505 | ||
3367 | if (get_ldev(mdev)) { | 3506 | if (get_ldev(device)) { |
3368 | drbd_bm_lock(mdev, work->why, work->flags); | 3507 | drbd_bm_lock(device, work->why, work->flags); |
3369 | rv = work->io_fn(mdev); | 3508 | rv = work->io_fn(device); |
3370 | drbd_bm_unlock(mdev); | 3509 | drbd_bm_unlock(device); |
3371 | put_ldev(mdev); | 3510 | put_ldev(device); |
3372 | } | 3511 | } |
3373 | 3512 | ||
3374 | clear_bit_unlock(BITMAP_IO, &mdev->flags); | 3513 | clear_bit_unlock(BITMAP_IO, &device->flags); |
3375 | wake_up(&mdev->misc_wait); | 3514 | wake_up(&device->misc_wait); |
3376 | 3515 | ||
3377 | if (work->done) | 3516 | if (work->done) |
3378 | work->done(mdev, rv); | 3517 | work->done(device, rv); |
3379 | 3518 | ||
3380 | clear_bit(BITMAP_IO_QUEUED, &mdev->flags); | 3519 | clear_bit(BITMAP_IO_QUEUED, &device->flags); |
3381 | work->why = NULL; | 3520 | work->why = NULL; |
3382 | work->flags = 0; | 3521 | work->flags = 0; |
3383 | 3522 | ||
3384 | return 0; | 3523 | return 0; |
3385 | } | 3524 | } |
3386 | 3525 | ||
3387 | void drbd_ldev_destroy(struct drbd_conf *mdev) | 3526 | void drbd_ldev_destroy(struct drbd_device *device) |
3388 | { | 3527 | { |
3389 | lc_destroy(mdev->resync); | 3528 | lc_destroy(device->resync); |
3390 | mdev->resync = NULL; | 3529 | device->resync = NULL; |
3391 | lc_destroy(mdev->act_log); | 3530 | lc_destroy(device->act_log); |
3392 | mdev->act_log = NULL; | 3531 | device->act_log = NULL; |
3393 | __no_warn(local, | 3532 | __no_warn(local, |
3394 | drbd_free_bc(mdev->ldev); | 3533 | drbd_free_bc(device->ldev); |
3395 | mdev->ldev = NULL;); | 3534 | device->ldev = NULL;); |
3396 | 3535 | ||
3397 | clear_bit(GO_DISKLESS, &mdev->flags); | 3536 | clear_bit(GO_DISKLESS, &device->flags); |
3398 | } | 3537 | } |
3399 | 3538 | ||
3400 | static int w_go_diskless(struct drbd_work *w, int unused) | 3539 | static int w_go_diskless(struct drbd_work *w, int unused) |
3401 | { | 3540 | { |
3402 | struct drbd_conf *mdev = w->mdev; | 3541 | struct drbd_device *device = |
3542 | container_of(w, struct drbd_device, go_diskless); | ||
3403 | 3543 | ||
3404 | D_ASSERT(mdev->state.disk == D_FAILED); | 3544 | D_ASSERT(device, device->state.disk == D_FAILED); |
3405 | /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will | 3545 | /* we cannot assert local_cnt == 0 here, as get_ldev_if_state will |
3406 | * inc/dec it frequently. Once we are D_DISKLESS, no one will touch | 3546 | * inc/dec it frequently. Once we are D_DISKLESS, no one will touch |
3407 | * the protected members anymore, though, so once put_ldev reaches zero | 3547 | * the protected members anymore, though, so once put_ldev reaches zero |
@@ -3420,27 +3560,27 @@ static int w_go_diskless(struct drbd_work *w, int unused) | |||
3420 | * We still need to check if both bitmap and ldev are present, we may | 3560 | * We still need to check if both bitmap and ldev are present, we may |
3421 | * end up here after a failed attach, before ldev was even assigned. | 3561 | * end up here after a failed attach, before ldev was even assigned. |
3422 | */ | 3562 | */ |
3423 | if (mdev->bitmap && mdev->ldev) { | 3563 | if (device->bitmap && device->ldev) { |
3424 | /* An interrupted resync or similar is allowed to recounts bits | 3564 | /* An interrupted resync or similar is allowed to recounts bits |
3425 | * while we detach. | 3565 | * while we detach. |
3426 | * Any modifications would not be expected anymore, though. | 3566 | * Any modifications would not be expected anymore, though. |
3427 | */ | 3567 | */ |
3428 | if (drbd_bitmap_io_from_worker(mdev, drbd_bm_write, | 3568 | if (drbd_bitmap_io_from_worker(device, drbd_bm_write, |
3429 | "detach", BM_LOCKED_TEST_ALLOWED)) { | 3569 | "detach", BM_LOCKED_TEST_ALLOWED)) { |
3430 | if (test_bit(WAS_READ_ERROR, &mdev->flags)) { | 3570 | if (test_bit(WAS_READ_ERROR, &device->flags)) { |
3431 | drbd_md_set_flag(mdev, MDF_FULL_SYNC); | 3571 | drbd_md_set_flag(device, MDF_FULL_SYNC); |
3432 | drbd_md_sync(mdev); | 3572 | drbd_md_sync(device); |
3433 | } | 3573 | } |
3434 | } | 3574 | } |
3435 | } | 3575 | } |
3436 | 3576 | ||
3437 | drbd_force_state(mdev, NS(disk, D_DISKLESS)); | 3577 | drbd_force_state(device, NS(disk, D_DISKLESS)); |
3438 | return 0; | 3578 | return 0; |
3439 | } | 3579 | } |
3440 | 3580 | ||
3441 | /** | 3581 | /** |
3442 | * drbd_queue_bitmap_io() - Queues an IO operation on the whole bitmap | 3582 | * drbd_queue_bitmap_io() - Queues an IO operation on the whole bitmap |
3443 | * @mdev: DRBD device. | 3583 | * @device: DRBD device. |
3444 | * @io_fn: IO callback to be called when bitmap IO is possible | 3584 | * @io_fn: IO callback to be called when bitmap IO is possible |
3445 | * @done: callback to be called after the bitmap IO was performed | 3585 | * @done: callback to be called after the bitmap IO was performed |
3446 | * @why: Descriptive text of the reason for doing the IO | 3586 | * @why: Descriptive text of the reason for doing the IO |
@@ -3450,76 +3590,77 @@ static int w_go_diskless(struct drbd_work *w, int unused) | |||
3450 | * called from worker context. It MUST NOT be used while a previous such | 3590 | * called from worker context. It MUST NOT be used while a previous such |
3451 | * work is still pending! | 3591 | * work is still pending! |
3452 | */ | 3592 | */ |
3453 | void drbd_queue_bitmap_io(struct drbd_conf *mdev, | 3593 | void drbd_queue_bitmap_io(struct drbd_device *device, |
3454 | int (*io_fn)(struct drbd_conf *), | 3594 | int (*io_fn)(struct drbd_device *), |
3455 | void (*done)(struct drbd_conf *, int), | 3595 | void (*done)(struct drbd_device *, int), |
3456 | char *why, enum bm_flag flags) | 3596 | char *why, enum bm_flag flags) |
3457 | { | 3597 | { |
3458 | D_ASSERT(current == mdev->tconn->worker.task); | 3598 | D_ASSERT(device, current == first_peer_device(device)->connection->worker.task); |
3459 | 3599 | ||
3460 | D_ASSERT(!test_bit(BITMAP_IO_QUEUED, &mdev->flags)); | 3600 | D_ASSERT(device, !test_bit(BITMAP_IO_QUEUED, &device->flags)); |
3461 | D_ASSERT(!test_bit(BITMAP_IO, &mdev->flags)); | 3601 | D_ASSERT(device, !test_bit(BITMAP_IO, &device->flags)); |
3462 | D_ASSERT(list_empty(&mdev->bm_io_work.w.list)); | 3602 | D_ASSERT(device, list_empty(&device->bm_io_work.w.list)); |
3463 | if (mdev->bm_io_work.why) | 3603 | if (device->bm_io_work.why) |
3464 | dev_err(DEV, "FIXME going to queue '%s' but '%s' still pending?\n", | 3604 | drbd_err(device, "FIXME going to queue '%s' but '%s' still pending?\n", |
3465 | why, mdev->bm_io_work.why); | 3605 | why, device->bm_io_work.why); |
3466 | 3606 | ||
3467 | mdev->bm_io_work.io_fn = io_fn; | 3607 | device->bm_io_work.io_fn = io_fn; |
3468 | mdev->bm_io_work.done = done; | 3608 | device->bm_io_work.done = done; |
3469 | mdev->bm_io_work.why = why; | 3609 | device->bm_io_work.why = why; |
3470 | mdev->bm_io_work.flags = flags; | 3610 | device->bm_io_work.flags = flags; |
3471 | 3611 | ||
3472 | spin_lock_irq(&mdev->tconn->req_lock); | 3612 | spin_lock_irq(&device->resource->req_lock); |
3473 | set_bit(BITMAP_IO, &mdev->flags); | 3613 | set_bit(BITMAP_IO, &device->flags); |
3474 | if (atomic_read(&mdev->ap_bio_cnt) == 0) { | 3614 | if (atomic_read(&device->ap_bio_cnt) == 0) { |
3475 | if (!test_and_set_bit(BITMAP_IO_QUEUED, &mdev->flags)) | 3615 | if (!test_and_set_bit(BITMAP_IO_QUEUED, &device->flags)) |
3476 | drbd_queue_work(&mdev->tconn->sender_work, &mdev->bm_io_work.w); | 3616 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
3617 | &device->bm_io_work.w); | ||
3477 | } | 3618 | } |
3478 | spin_unlock_irq(&mdev->tconn->req_lock); | 3619 | spin_unlock_irq(&device->resource->req_lock); |
3479 | } | 3620 | } |
3480 | 3621 | ||
3481 | /** | 3622 | /** |
3482 | * drbd_bitmap_io() - Does an IO operation on the whole bitmap | 3623 | * drbd_bitmap_io() - Does an IO operation on the whole bitmap |
3483 | * @mdev: DRBD device. | 3624 | * @device: DRBD device. |
3484 | * @io_fn: IO callback to be called when bitmap IO is possible | 3625 | * @io_fn: IO callback to be called when bitmap IO is possible |
3485 | * @why: Descriptive text of the reason for doing the IO | 3626 | * @why: Descriptive text of the reason for doing the IO |
3486 | * | 3627 | * |
3487 | * freezes application IO while that the actual IO operations runs. This | 3628 | * freezes application IO while that the actual IO operations runs. This |
3488 | * functions MAY NOT be called from worker context. | 3629 | * functions MAY NOT be called from worker context. |
3489 | */ | 3630 | */ |
3490 | int drbd_bitmap_io(struct drbd_conf *mdev, int (*io_fn)(struct drbd_conf *), | 3631 | int drbd_bitmap_io(struct drbd_device *device, int (*io_fn)(struct drbd_device *), |
3491 | char *why, enum bm_flag flags) | 3632 | char *why, enum bm_flag flags) |
3492 | { | 3633 | { |
3493 | int rv; | 3634 | int rv; |
3494 | 3635 | ||
3495 | D_ASSERT(current != mdev->tconn->worker.task); | 3636 | D_ASSERT(device, current != first_peer_device(device)->connection->worker.task); |
3496 | 3637 | ||
3497 | if ((flags & BM_LOCKED_SET_ALLOWED) == 0) | 3638 | if ((flags & BM_LOCKED_SET_ALLOWED) == 0) |
3498 | drbd_suspend_io(mdev); | 3639 | drbd_suspend_io(device); |
3499 | 3640 | ||
3500 | drbd_bm_lock(mdev, why, flags); | 3641 | drbd_bm_lock(device, why, flags); |
3501 | rv = io_fn(mdev); | 3642 | rv = io_fn(device); |
3502 | drbd_bm_unlock(mdev); | 3643 | drbd_bm_unlock(device); |
3503 | 3644 | ||
3504 | if ((flags & BM_LOCKED_SET_ALLOWED) == 0) | 3645 | if ((flags & BM_LOCKED_SET_ALLOWED) == 0) |
3505 | drbd_resume_io(mdev); | 3646 | drbd_resume_io(device); |
3506 | 3647 | ||
3507 | return rv; | 3648 | return rv; |
3508 | } | 3649 | } |
3509 | 3650 | ||
3510 | void drbd_md_set_flag(struct drbd_conf *mdev, int flag) __must_hold(local) | 3651 | void drbd_md_set_flag(struct drbd_device *device, int flag) __must_hold(local) |
3511 | { | 3652 | { |
3512 | if ((mdev->ldev->md.flags & flag) != flag) { | 3653 | if ((device->ldev->md.flags & flag) != flag) { |
3513 | drbd_md_mark_dirty(mdev); | 3654 | drbd_md_mark_dirty(device); |
3514 | mdev->ldev->md.flags |= flag; | 3655 | device->ldev->md.flags |= flag; |
3515 | } | 3656 | } |
3516 | } | 3657 | } |
3517 | 3658 | ||
3518 | void drbd_md_clear_flag(struct drbd_conf *mdev, int flag) __must_hold(local) | 3659 | void drbd_md_clear_flag(struct drbd_device *device, int flag) __must_hold(local) |
3519 | { | 3660 | { |
3520 | if ((mdev->ldev->md.flags & flag) != 0) { | 3661 | if ((device->ldev->md.flags & flag) != 0) { |
3521 | drbd_md_mark_dirty(mdev); | 3662 | drbd_md_mark_dirty(device); |
3522 | mdev->ldev->md.flags &= ~flag; | 3663 | device->ldev->md.flags &= ~flag; |
3523 | } | 3664 | } |
3524 | } | 3665 | } |
3525 | int drbd_md_test_flag(struct drbd_backing_dev *bdev, int flag) | 3666 | int drbd_md_test_flag(struct drbd_backing_dev *bdev, int flag) |
@@ -3529,23 +3670,25 @@ int drbd_md_test_flag(struct drbd_backing_dev *bdev, int flag) | |||
3529 | 3670 | ||
3530 | static void md_sync_timer_fn(unsigned long data) | 3671 | static void md_sync_timer_fn(unsigned long data) |
3531 | { | 3672 | { |
3532 | struct drbd_conf *mdev = (struct drbd_conf *) data; | 3673 | struct drbd_device *device = (struct drbd_device *) data; |
3533 | 3674 | ||
3534 | /* must not double-queue! */ | 3675 | /* must not double-queue! */ |
3535 | if (list_empty(&mdev->md_sync_work.list)) | 3676 | if (list_empty(&device->md_sync_work.list)) |
3536 | drbd_queue_work_front(&mdev->tconn->sender_work, &mdev->md_sync_work); | 3677 | drbd_queue_work_front(&first_peer_device(device)->connection->sender_work, |
3678 | &device->md_sync_work); | ||
3537 | } | 3679 | } |
3538 | 3680 | ||
3539 | static int w_md_sync(struct drbd_work *w, int unused) | 3681 | static int w_md_sync(struct drbd_work *w, int unused) |
3540 | { | 3682 | { |
3541 | struct drbd_conf *mdev = w->mdev; | 3683 | struct drbd_device *device = |
3684 | container_of(w, struct drbd_device, md_sync_work); | ||
3542 | 3685 | ||
3543 | dev_warn(DEV, "md_sync_timer expired! Worker calls drbd_md_sync().\n"); | 3686 | drbd_warn(device, "md_sync_timer expired! Worker calls drbd_md_sync().\n"); |
3544 | #ifdef DEBUG | 3687 | #ifdef DEBUG |
3545 | dev_warn(DEV, "last md_mark_dirty: %s:%u\n", | 3688 | drbd_warn(device, "last md_mark_dirty: %s:%u\n", |
3546 | mdev->last_md_mark_dirty.func, mdev->last_md_mark_dirty.line); | 3689 | device->last_md_mark_dirty.func, device->last_md_mark_dirty.line); |
3547 | #endif | 3690 | #endif |
3548 | drbd_md_sync(mdev); | 3691 | drbd_md_sync(device); |
3549 | return 0; | 3692 | return 0; |
3550 | } | 3693 | } |
3551 | 3694 | ||
@@ -3621,18 +3764,18 @@ const char *cmdname(enum drbd_packet cmd) | |||
3621 | 3764 | ||
3622 | /** | 3765 | /** |
3623 | * drbd_wait_misc - wait for a request to make progress | 3766 | * drbd_wait_misc - wait for a request to make progress |
3624 | * @mdev: device associated with the request | 3767 | * @device: device associated with the request |
3625 | * @i: the struct drbd_interval embedded in struct drbd_request or | 3768 | * @i: the struct drbd_interval embedded in struct drbd_request or |
3626 | * struct drbd_peer_request | 3769 | * struct drbd_peer_request |
3627 | */ | 3770 | */ |
3628 | int drbd_wait_misc(struct drbd_conf *mdev, struct drbd_interval *i) | 3771 | int drbd_wait_misc(struct drbd_device *device, struct drbd_interval *i) |
3629 | { | 3772 | { |
3630 | struct net_conf *nc; | 3773 | struct net_conf *nc; |
3631 | DEFINE_WAIT(wait); | 3774 | DEFINE_WAIT(wait); |
3632 | long timeout; | 3775 | long timeout; |
3633 | 3776 | ||
3634 | rcu_read_lock(); | 3777 | rcu_read_lock(); |
3635 | nc = rcu_dereference(mdev->tconn->net_conf); | 3778 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
3636 | if (!nc) { | 3779 | if (!nc) { |
3637 | rcu_read_unlock(); | 3780 | rcu_read_unlock(); |
3638 | return -ETIMEDOUT; | 3781 | return -ETIMEDOUT; |
@@ -3640,14 +3783,14 @@ int drbd_wait_misc(struct drbd_conf *mdev, struct drbd_interval *i) | |||
3640 | timeout = nc->ko_count ? nc->timeout * HZ / 10 * nc->ko_count : MAX_SCHEDULE_TIMEOUT; | 3783 | timeout = nc->ko_count ? nc->timeout * HZ / 10 * nc->ko_count : MAX_SCHEDULE_TIMEOUT; |
3641 | rcu_read_unlock(); | 3784 | rcu_read_unlock(); |
3642 | 3785 | ||
3643 | /* Indicate to wake up mdev->misc_wait on progress. */ | 3786 | /* Indicate to wake up device->misc_wait on progress. */ |
3644 | i->waiting = true; | 3787 | i->waiting = true; |
3645 | prepare_to_wait(&mdev->misc_wait, &wait, TASK_INTERRUPTIBLE); | 3788 | prepare_to_wait(&device->misc_wait, &wait, TASK_INTERRUPTIBLE); |
3646 | spin_unlock_irq(&mdev->tconn->req_lock); | 3789 | spin_unlock_irq(&device->resource->req_lock); |
3647 | timeout = schedule_timeout(timeout); | 3790 | timeout = schedule_timeout(timeout); |
3648 | finish_wait(&mdev->misc_wait, &wait); | 3791 | finish_wait(&device->misc_wait, &wait); |
3649 | spin_lock_irq(&mdev->tconn->req_lock); | 3792 | spin_lock_irq(&device->resource->req_lock); |
3650 | if (!timeout || mdev->state.conn < C_CONNECTED) | 3793 | if (!timeout || device->state.conn < C_CONNECTED) |
3651 | return -ETIMEDOUT; | 3794 | return -ETIMEDOUT; |
3652 | if (signal_pending(current)) | 3795 | if (signal_pending(current)) |
3653 | return -ERESTARTSYS; | 3796 | return -ERESTARTSYS; |
@@ -3703,20 +3846,20 @@ _drbd_fault_str(unsigned int type) { | |||
3703 | } | 3846 | } |
3704 | 3847 | ||
3705 | unsigned int | 3848 | unsigned int |
3706 | _drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) | 3849 | _drbd_insert_fault(struct drbd_device *device, unsigned int type) |
3707 | { | 3850 | { |
3708 | static struct fault_random_state rrs = {0, 0}; | 3851 | static struct fault_random_state rrs = {0, 0}; |
3709 | 3852 | ||
3710 | unsigned int ret = ( | 3853 | unsigned int ret = ( |
3711 | (fault_devs == 0 || | 3854 | (fault_devs == 0 || |
3712 | ((1 << mdev_to_minor(mdev)) & fault_devs) != 0) && | 3855 | ((1 << device_to_minor(device)) & fault_devs) != 0) && |
3713 | (((_drbd_fault_random(&rrs) % 100) + 1) <= fault_rate)); | 3856 | (((_drbd_fault_random(&rrs) % 100) + 1) <= fault_rate)); |
3714 | 3857 | ||
3715 | if (ret) { | 3858 | if (ret) { |
3716 | fault_count++; | 3859 | fault_count++; |
3717 | 3860 | ||
3718 | if (__ratelimit(&drbd_ratelimit_state)) | 3861 | if (__ratelimit(&drbd_ratelimit_state)) |
3719 | dev_warn(DEV, "***Simulating %s failure\n", | 3862 | drbd_warn(device, "***Simulating %s failure\n", |
3720 | _drbd_fault_str(type)); | 3863 | _drbd_fault_str(type)); |
3721 | } | 3864 | } |
3722 | 3865 | ||
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index c706d50a8b06..526414bc2cab 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/blkpg.h> | 32 | #include <linux/blkpg.h> |
33 | #include <linux/cpumask.h> | 33 | #include <linux/cpumask.h> |
34 | #include "drbd_int.h" | 34 | #include "drbd_int.h" |
35 | #include "drbd_protocol.h" | ||
35 | #include "drbd_req.h" | 36 | #include "drbd_req.h" |
36 | #include "drbd_wrappers.h" | 37 | #include "drbd_wrappers.h" |
37 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
@@ -44,8 +45,8 @@ | |||
44 | // int drbd_adm_create_resource(struct sk_buff *skb, struct genl_info *info); | 45 | // int drbd_adm_create_resource(struct sk_buff *skb, struct genl_info *info); |
45 | // int drbd_adm_delete_resource(struct sk_buff *skb, struct genl_info *info); | 46 | // int drbd_adm_delete_resource(struct sk_buff *skb, struct genl_info *info); |
46 | 47 | ||
47 | int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info); | 48 | int drbd_adm_new_minor(struct sk_buff *skb, struct genl_info *info); |
48 | int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info); | 49 | int drbd_adm_del_minor(struct sk_buff *skb, struct genl_info *info); |
49 | 50 | ||
50 | int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info); | 51 | int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info); |
51 | int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info); | 52 | int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info); |
@@ -102,8 +103,9 @@ static struct drbd_config_context { | |||
102 | /* pointer into reply buffer */ | 103 | /* pointer into reply buffer */ |
103 | struct drbd_genlmsghdr *reply_dh; | 104 | struct drbd_genlmsghdr *reply_dh; |
104 | /* resolved from attributes, if possible */ | 105 | /* resolved from attributes, if possible */ |
105 | struct drbd_conf *mdev; | 106 | struct drbd_device *device; |
106 | struct drbd_tconn *tconn; | 107 | struct drbd_resource *resource; |
108 | struct drbd_connection *connection; | ||
107 | } adm_ctx; | 109 | } adm_ctx; |
108 | 110 | ||
109 | static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info) | 111 | static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info) |
@@ -202,62 +204,67 @@ static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info, | |||
202 | adm_ctx.my_addr = nested_attr_tb[__nla_type(T_ctx_my_addr)]; | 204 | adm_ctx.my_addr = nested_attr_tb[__nla_type(T_ctx_my_addr)]; |
203 | adm_ctx.peer_addr = nested_attr_tb[__nla_type(T_ctx_peer_addr)]; | 205 | adm_ctx.peer_addr = nested_attr_tb[__nla_type(T_ctx_peer_addr)]; |
204 | if ((adm_ctx.my_addr && | 206 | if ((adm_ctx.my_addr && |
205 | nla_len(adm_ctx.my_addr) > sizeof(adm_ctx.tconn->my_addr)) || | 207 | nla_len(adm_ctx.my_addr) > sizeof(adm_ctx.connection->my_addr)) || |
206 | (adm_ctx.peer_addr && | 208 | (adm_ctx.peer_addr && |
207 | nla_len(adm_ctx.peer_addr) > sizeof(adm_ctx.tconn->peer_addr))) { | 209 | nla_len(adm_ctx.peer_addr) > sizeof(adm_ctx.connection->peer_addr))) { |
208 | err = -EINVAL; | 210 | err = -EINVAL; |
209 | goto fail; | 211 | goto fail; |
210 | } | 212 | } |
211 | } | 213 | } |
212 | 214 | ||
213 | adm_ctx.minor = d_in->minor; | 215 | adm_ctx.minor = d_in->minor; |
214 | adm_ctx.mdev = minor_to_mdev(d_in->minor); | 216 | adm_ctx.device = minor_to_device(d_in->minor); |
215 | adm_ctx.tconn = conn_get_by_name(adm_ctx.resource_name); | 217 | if (adm_ctx.resource_name) { |
218 | adm_ctx.resource = drbd_find_resource(adm_ctx.resource_name); | ||
219 | } | ||
216 | 220 | ||
217 | if (!adm_ctx.mdev && (flags & DRBD_ADM_NEED_MINOR)) { | 221 | if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) { |
218 | drbd_msg_put_info("unknown minor"); | 222 | drbd_msg_put_info("unknown minor"); |
219 | return ERR_MINOR_INVALID; | 223 | return ERR_MINOR_INVALID; |
220 | } | 224 | } |
221 | if (!adm_ctx.tconn && (flags & DRBD_ADM_NEED_RESOURCE)) { | 225 | if (!adm_ctx.resource && (flags & DRBD_ADM_NEED_RESOURCE)) { |
222 | drbd_msg_put_info("unknown resource"); | 226 | drbd_msg_put_info("unknown resource"); |
227 | if (adm_ctx.resource_name) | ||
228 | return ERR_RES_NOT_KNOWN; | ||
223 | return ERR_INVALID_REQUEST; | 229 | return ERR_INVALID_REQUEST; |
224 | } | 230 | } |
225 | 231 | ||
226 | if (flags & DRBD_ADM_NEED_CONNECTION) { | 232 | if (flags & DRBD_ADM_NEED_CONNECTION) { |
227 | if (adm_ctx.tconn && !(flags & DRBD_ADM_NEED_RESOURCE)) { | 233 | if (adm_ctx.resource) { |
228 | drbd_msg_put_info("no resource name expected"); | 234 | drbd_msg_put_info("no resource name expected"); |
229 | return ERR_INVALID_REQUEST; | 235 | return ERR_INVALID_REQUEST; |
230 | } | 236 | } |
231 | if (adm_ctx.mdev) { | 237 | if (adm_ctx.device) { |
232 | drbd_msg_put_info("no minor number expected"); | 238 | drbd_msg_put_info("no minor number expected"); |
233 | return ERR_INVALID_REQUEST; | 239 | return ERR_INVALID_REQUEST; |
234 | } | 240 | } |
235 | if (adm_ctx.my_addr && adm_ctx.peer_addr) | 241 | if (adm_ctx.my_addr && adm_ctx.peer_addr) |
236 | adm_ctx.tconn = conn_get_by_addrs(nla_data(adm_ctx.my_addr), | 242 | adm_ctx.connection = conn_get_by_addrs(nla_data(adm_ctx.my_addr), |
237 | nla_len(adm_ctx.my_addr), | 243 | nla_len(adm_ctx.my_addr), |
238 | nla_data(adm_ctx.peer_addr), | 244 | nla_data(adm_ctx.peer_addr), |
239 | nla_len(adm_ctx.peer_addr)); | 245 | nla_len(adm_ctx.peer_addr)); |
240 | if (!adm_ctx.tconn) { | 246 | if (!adm_ctx.connection) { |
241 | drbd_msg_put_info("unknown connection"); | 247 | drbd_msg_put_info("unknown connection"); |
242 | return ERR_INVALID_REQUEST; | 248 | return ERR_INVALID_REQUEST; |
243 | } | 249 | } |
244 | } | 250 | } |
245 | 251 | ||
246 | /* some more paranoia, if the request was over-determined */ | 252 | /* some more paranoia, if the request was over-determined */ |
247 | if (adm_ctx.mdev && adm_ctx.tconn && | 253 | if (adm_ctx.device && adm_ctx.resource && |
248 | adm_ctx.mdev->tconn != adm_ctx.tconn) { | 254 | adm_ctx.device->resource != adm_ctx.resource) { |
249 | pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n", | 255 | pr_warning("request: minor=%u, resource=%s; but that minor belongs to resource %s\n", |
250 | adm_ctx.minor, adm_ctx.resource_name, | 256 | adm_ctx.minor, adm_ctx.resource->name, |
251 | adm_ctx.mdev->tconn->name); | 257 | adm_ctx.device->resource->name); |
252 | drbd_msg_put_info("minor exists in different resource"); | 258 | drbd_msg_put_info("minor exists in different resource"); |
253 | return ERR_INVALID_REQUEST; | 259 | return ERR_INVALID_REQUEST; |
254 | } | 260 | } |
255 | if (adm_ctx.mdev && | 261 | if (adm_ctx.device && |
256 | adm_ctx.volume != VOLUME_UNSPECIFIED && | 262 | adm_ctx.volume != VOLUME_UNSPECIFIED && |
257 | adm_ctx.volume != adm_ctx.mdev->vnr) { | 263 | adm_ctx.volume != adm_ctx.device->vnr) { |
258 | pr_warning("request: minor=%u, volume=%u; but that minor is volume %u in %s\n", | 264 | pr_warning("request: minor=%u, volume=%u; but that minor is volume %u in %s\n", |
259 | adm_ctx.minor, adm_ctx.volume, | 265 | adm_ctx.minor, adm_ctx.volume, |
260 | adm_ctx.mdev->vnr, adm_ctx.mdev->tconn->name); | 266 | adm_ctx.device->vnr, |
267 | adm_ctx.device->resource->name); | ||
261 | drbd_msg_put_info("minor exists as different volume"); | 268 | drbd_msg_put_info("minor exists as different volume"); |
262 | return ERR_INVALID_REQUEST; | 269 | return ERR_INVALID_REQUEST; |
263 | } | 270 | } |
@@ -272,9 +279,13 @@ fail: | |||
272 | 279 | ||
273 | static int drbd_adm_finish(struct genl_info *info, int retcode) | 280 | static int drbd_adm_finish(struct genl_info *info, int retcode) |
274 | { | 281 | { |
275 | if (adm_ctx.tconn) { | 282 | if (adm_ctx.connection) { |
276 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); | 283 | kref_put(&adm_ctx.connection->kref, drbd_destroy_connection); |
277 | adm_ctx.tconn = NULL; | 284 | adm_ctx.connection = NULL; |
285 | } | ||
286 | if (adm_ctx.resource) { | ||
287 | kref_put(&adm_ctx.resource->kref, drbd_destroy_resource); | ||
288 | adm_ctx.resource = NULL; | ||
278 | } | 289 | } |
279 | 290 | ||
280 | if (!adm_ctx.reply_skb) | 291 | if (!adm_ctx.reply_skb) |
@@ -285,34 +296,34 @@ static int drbd_adm_finish(struct genl_info *info, int retcode) | |||
285 | return 0; | 296 | return 0; |
286 | } | 297 | } |
287 | 298 | ||
288 | static void setup_khelper_env(struct drbd_tconn *tconn, char **envp) | 299 | static void setup_khelper_env(struct drbd_connection *connection, char **envp) |
289 | { | 300 | { |
290 | char *afs; | 301 | char *afs; |
291 | 302 | ||
292 | /* FIXME: A future version will not allow this case. */ | 303 | /* FIXME: A future version will not allow this case. */ |
293 | if (tconn->my_addr_len == 0 || tconn->peer_addr_len == 0) | 304 | if (connection->my_addr_len == 0 || connection->peer_addr_len == 0) |
294 | return; | 305 | return; |
295 | 306 | ||
296 | switch (((struct sockaddr *)&tconn->peer_addr)->sa_family) { | 307 | switch (((struct sockaddr *)&connection->peer_addr)->sa_family) { |
297 | case AF_INET6: | 308 | case AF_INET6: |
298 | afs = "ipv6"; | 309 | afs = "ipv6"; |
299 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI6", | 310 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI6", |
300 | &((struct sockaddr_in6 *)&tconn->peer_addr)->sin6_addr); | 311 | &((struct sockaddr_in6 *)&connection->peer_addr)->sin6_addr); |
301 | break; | 312 | break; |
302 | case AF_INET: | 313 | case AF_INET: |
303 | afs = "ipv4"; | 314 | afs = "ipv4"; |
304 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", | 315 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", |
305 | &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr); | 316 | &((struct sockaddr_in *)&connection->peer_addr)->sin_addr); |
306 | break; | 317 | break; |
307 | default: | 318 | default: |
308 | afs = "ssocks"; | 319 | afs = "ssocks"; |
309 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", | 320 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", |
310 | &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr); | 321 | &((struct sockaddr_in *)&connection->peer_addr)->sin_addr); |
311 | } | 322 | } |
312 | snprintf(envp[3], 20, "DRBD_PEER_AF=%s", afs); | 323 | snprintf(envp[3], 20, "DRBD_PEER_AF=%s", afs); |
313 | } | 324 | } |
314 | 325 | ||
315 | int drbd_khelper(struct drbd_conf *mdev, char *cmd) | 326 | int drbd_khelper(struct drbd_device *device, char *cmd) |
316 | { | 327 | { |
317 | char *envp[] = { "HOME=/", | 328 | char *envp[] = { "HOME=/", |
318 | "TERM=linux", | 329 | "TERM=linux", |
@@ -322,39 +333,39 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd) | |||
322 | NULL }; | 333 | NULL }; |
323 | char mb[12]; | 334 | char mb[12]; |
324 | char *argv[] = {usermode_helper, cmd, mb, NULL }; | 335 | char *argv[] = {usermode_helper, cmd, mb, NULL }; |
325 | struct drbd_tconn *tconn = mdev->tconn; | 336 | struct drbd_connection *connection = first_peer_device(device)->connection; |
326 | struct sib_info sib; | 337 | struct sib_info sib; |
327 | int ret; | 338 | int ret; |
328 | 339 | ||
329 | if (current == tconn->worker.task) | 340 | if (current == connection->worker.task) |
330 | set_bit(CALLBACK_PENDING, &tconn->flags); | 341 | set_bit(CALLBACK_PENDING, &connection->flags); |
331 | 342 | ||
332 | snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev)); | 343 | snprintf(mb, 12, "minor-%d", device_to_minor(device)); |
333 | setup_khelper_env(tconn, envp); | 344 | setup_khelper_env(connection, envp); |
334 | 345 | ||
335 | /* The helper may take some time. | 346 | /* The helper may take some time. |
336 | * write out any unsynced meta data changes now */ | 347 | * write out any unsynced meta data changes now */ |
337 | drbd_md_sync(mdev); | 348 | drbd_md_sync(device); |
338 | 349 | ||
339 | dev_info(DEV, "helper command: %s %s %s\n", usermode_helper, cmd, mb); | 350 | drbd_info(device, "helper command: %s %s %s\n", usermode_helper, cmd, mb); |
340 | sib.sib_reason = SIB_HELPER_PRE; | 351 | sib.sib_reason = SIB_HELPER_PRE; |
341 | sib.helper_name = cmd; | 352 | sib.helper_name = cmd; |
342 | drbd_bcast_event(mdev, &sib); | 353 | drbd_bcast_event(device, &sib); |
343 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); | 354 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); |
344 | if (ret) | 355 | if (ret) |
345 | dev_warn(DEV, "helper command: %s %s %s exit code %u (0x%x)\n", | 356 | drbd_warn(device, "helper command: %s %s %s exit code %u (0x%x)\n", |
346 | usermode_helper, cmd, mb, | 357 | usermode_helper, cmd, mb, |
347 | (ret >> 8) & 0xff, ret); | 358 | (ret >> 8) & 0xff, ret); |
348 | else | 359 | else |
349 | dev_info(DEV, "helper command: %s %s %s exit code %u (0x%x)\n", | 360 | drbd_info(device, "helper command: %s %s %s exit code %u (0x%x)\n", |
350 | usermode_helper, cmd, mb, | 361 | usermode_helper, cmd, mb, |
351 | (ret >> 8) & 0xff, ret); | 362 | (ret >> 8) & 0xff, ret); |
352 | sib.sib_reason = SIB_HELPER_POST; | 363 | sib.sib_reason = SIB_HELPER_POST; |
353 | sib.helper_exit_code = ret; | 364 | sib.helper_exit_code = ret; |
354 | drbd_bcast_event(mdev, &sib); | 365 | drbd_bcast_event(device, &sib); |
355 | 366 | ||
356 | if (current == tconn->worker.task) | 367 | if (current == connection->worker.task) |
357 | clear_bit(CALLBACK_PENDING, &tconn->flags); | 368 | clear_bit(CALLBACK_PENDING, &connection->flags); |
358 | 369 | ||
359 | if (ret < 0) /* Ignore any ERRNOs we got. */ | 370 | if (ret < 0) /* Ignore any ERRNOs we got. */ |
360 | ret = 0; | 371 | ret = 0; |
@@ -362,7 +373,7 @@ int drbd_khelper(struct drbd_conf *mdev, char *cmd) | |||
362 | return ret; | 373 | return ret; |
363 | } | 374 | } |
364 | 375 | ||
365 | int conn_khelper(struct drbd_tconn *tconn, char *cmd) | 376 | static int conn_khelper(struct drbd_connection *connection, char *cmd) |
366 | { | 377 | { |
367 | char *envp[] = { "HOME=/", | 378 | char *envp[] = { "HOME=/", |
368 | "TERM=linux", | 379 | "TERM=linux", |
@@ -370,23 +381,24 @@ int conn_khelper(struct drbd_tconn *tconn, char *cmd) | |||
370 | (char[20]) { }, /* address family */ | 381 | (char[20]) { }, /* address family */ |
371 | (char[60]) { }, /* address */ | 382 | (char[60]) { }, /* address */ |
372 | NULL }; | 383 | NULL }; |
373 | char *argv[] = {usermode_helper, cmd, tconn->name, NULL }; | 384 | char *resource_name = connection->resource->name; |
385 | char *argv[] = {usermode_helper, cmd, resource_name, NULL }; | ||
374 | int ret; | 386 | int ret; |
375 | 387 | ||
376 | setup_khelper_env(tconn, envp); | 388 | setup_khelper_env(connection, envp); |
377 | conn_md_sync(tconn); | 389 | conn_md_sync(connection); |
378 | 390 | ||
379 | conn_info(tconn, "helper command: %s %s %s\n", usermode_helper, cmd, tconn->name); | 391 | drbd_info(connection, "helper command: %s %s %s\n", usermode_helper, cmd, resource_name); |
380 | /* TODO: conn_bcast_event() ?? */ | 392 | /* TODO: conn_bcast_event() ?? */ |
381 | 393 | ||
382 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); | 394 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); |
383 | if (ret) | 395 | if (ret) |
384 | conn_warn(tconn, "helper command: %s %s %s exit code %u (0x%x)\n", | 396 | drbd_warn(connection, "helper command: %s %s %s exit code %u (0x%x)\n", |
385 | usermode_helper, cmd, tconn->name, | 397 | usermode_helper, cmd, resource_name, |
386 | (ret >> 8) & 0xff, ret); | 398 | (ret >> 8) & 0xff, ret); |
387 | else | 399 | else |
388 | conn_info(tconn, "helper command: %s %s %s exit code %u (0x%x)\n", | 400 | drbd_info(connection, "helper command: %s %s %s exit code %u (0x%x)\n", |
389 | usermode_helper, cmd, tconn->name, | 401 | usermode_helper, cmd, resource_name, |
390 | (ret >> 8) & 0xff, ret); | 402 | (ret >> 8) & 0xff, ret); |
391 | /* TODO: conn_bcast_event() ?? */ | 403 | /* TODO: conn_bcast_event() ?? */ |
392 | 404 | ||
@@ -396,18 +408,20 @@ int conn_khelper(struct drbd_tconn *tconn, char *cmd) | |||
396 | return ret; | 408 | return ret; |
397 | } | 409 | } |
398 | 410 | ||
399 | static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn) | 411 | static enum drbd_fencing_p highest_fencing_policy(struct drbd_connection *connection) |
400 | { | 412 | { |
401 | enum drbd_fencing_p fp = FP_NOT_AVAIL; | 413 | enum drbd_fencing_p fp = FP_NOT_AVAIL; |
402 | struct drbd_conf *mdev; | 414 | struct drbd_peer_device *peer_device; |
403 | int vnr; | 415 | int vnr; |
404 | 416 | ||
405 | rcu_read_lock(); | 417 | rcu_read_lock(); |
406 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 418 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
407 | if (get_ldev_if_state(mdev, D_CONSISTENT)) { | 419 | struct drbd_device *device = peer_device->device; |
408 | fp = max_t(enum drbd_fencing_p, fp, | 420 | if (get_ldev_if_state(device, D_CONSISTENT)) { |
409 | rcu_dereference(mdev->ldev->disk_conf)->fencing); | 421 | struct disk_conf *disk_conf = |
410 | put_ldev(mdev); | 422 | rcu_dereference(peer_device->device->ldev->disk_conf); |
423 | fp = max_t(enum drbd_fencing_p, fp, disk_conf->fencing); | ||
424 | put_ldev(device); | ||
411 | } | 425 | } |
412 | } | 426 | } |
413 | rcu_read_unlock(); | 427 | rcu_read_unlock(); |
@@ -415,7 +429,7 @@ static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn) | |||
415 | return fp; | 429 | return fp; |
416 | } | 430 | } |
417 | 431 | ||
418 | bool conn_try_outdate_peer(struct drbd_tconn *tconn) | 432 | bool conn_try_outdate_peer(struct drbd_connection *connection) |
419 | { | 433 | { |
420 | unsigned int connect_cnt; | 434 | unsigned int connect_cnt; |
421 | union drbd_state mask = { }; | 435 | union drbd_state mask = { }; |
@@ -424,26 +438,26 @@ bool conn_try_outdate_peer(struct drbd_tconn *tconn) | |||
424 | char *ex_to_string; | 438 | char *ex_to_string; |
425 | int r; | 439 | int r; |
426 | 440 | ||
427 | if (tconn->cstate >= C_WF_REPORT_PARAMS) { | 441 | if (connection->cstate >= C_WF_REPORT_PARAMS) { |
428 | conn_err(tconn, "Expected cstate < C_WF_REPORT_PARAMS\n"); | 442 | drbd_err(connection, "Expected cstate < C_WF_REPORT_PARAMS\n"); |
429 | return false; | 443 | return false; |
430 | } | 444 | } |
431 | 445 | ||
432 | spin_lock_irq(&tconn->req_lock); | 446 | spin_lock_irq(&connection->resource->req_lock); |
433 | connect_cnt = tconn->connect_cnt; | 447 | connect_cnt = connection->connect_cnt; |
434 | spin_unlock_irq(&tconn->req_lock); | 448 | spin_unlock_irq(&connection->resource->req_lock); |
435 | 449 | ||
436 | fp = highest_fencing_policy(tconn); | 450 | fp = highest_fencing_policy(connection); |
437 | switch (fp) { | 451 | switch (fp) { |
438 | case FP_NOT_AVAIL: | 452 | case FP_NOT_AVAIL: |
439 | conn_warn(tconn, "Not fencing peer, I'm not even Consistent myself.\n"); | 453 | drbd_warn(connection, "Not fencing peer, I'm not even Consistent myself.\n"); |
440 | goto out; | 454 | goto out; |
441 | case FP_DONT_CARE: | 455 | case FP_DONT_CARE: |
442 | return true; | 456 | return true; |
443 | default: ; | 457 | default: ; |
444 | } | 458 | } |
445 | 459 | ||
446 | r = conn_khelper(tconn, "fence-peer"); | 460 | r = conn_khelper(connection, "fence-peer"); |
447 | 461 | ||
448 | switch ((r>>8) & 0xff) { | 462 | switch ((r>>8) & 0xff) { |
449 | case 3: /* peer is inconsistent */ | 463 | case 3: /* peer is inconsistent */ |
@@ -457,7 +471,7 @@ bool conn_try_outdate_peer(struct drbd_tconn *tconn) | |||
457 | val.pdsk = D_OUTDATED; | 471 | val.pdsk = D_OUTDATED; |
458 | break; | 472 | break; |
459 | case 5: /* peer was down */ | 473 | case 5: /* peer was down */ |
460 | if (conn_highest_disk(tconn) == D_UP_TO_DATE) { | 474 | if (conn_highest_disk(connection) == D_UP_TO_DATE) { |
461 | /* we will(have) create(d) a new UUID anyways... */ | 475 | /* we will(have) create(d) a new UUID anyways... */ |
462 | ex_to_string = "peer is unreachable, assumed to be dead"; | 476 | ex_to_string = "peer is unreachable, assumed to be dead"; |
463 | mask.pdsk = D_MASK; | 477 | mask.pdsk = D_MASK; |
@@ -470,70 +484,70 @@ bool conn_try_outdate_peer(struct drbd_tconn *tconn) | |||
470 | * This is useful when an unconnected R_SECONDARY is asked to | 484 | * This is useful when an unconnected R_SECONDARY is asked to |
471 | * become R_PRIMARY, but finds the other peer being active. */ | 485 | * become R_PRIMARY, but finds the other peer being active. */ |
472 | ex_to_string = "peer is active"; | 486 | ex_to_string = "peer is active"; |
473 | conn_warn(tconn, "Peer is primary, outdating myself.\n"); | 487 | drbd_warn(connection, "Peer is primary, outdating myself.\n"); |
474 | mask.disk = D_MASK; | 488 | mask.disk = D_MASK; |
475 | val.disk = D_OUTDATED; | 489 | val.disk = D_OUTDATED; |
476 | break; | 490 | break; |
477 | case 7: | 491 | case 7: |
478 | if (fp != FP_STONITH) | 492 | if (fp != FP_STONITH) |
479 | conn_err(tconn, "fence-peer() = 7 && fencing != Stonith !!!\n"); | 493 | drbd_err(connection, "fence-peer() = 7 && fencing != Stonith !!!\n"); |
480 | ex_to_string = "peer was stonithed"; | 494 | ex_to_string = "peer was stonithed"; |
481 | mask.pdsk = D_MASK; | 495 | mask.pdsk = D_MASK; |
482 | val.pdsk = D_OUTDATED; | 496 | val.pdsk = D_OUTDATED; |
483 | break; | 497 | break; |
484 | default: | 498 | default: |
485 | /* The script is broken ... */ | 499 | /* The script is broken ... */ |
486 | conn_err(tconn, "fence-peer helper broken, returned %d\n", (r>>8)&0xff); | 500 | drbd_err(connection, "fence-peer helper broken, returned %d\n", (r>>8)&0xff); |
487 | return false; /* Eventually leave IO frozen */ | 501 | return false; /* Eventually leave IO frozen */ |
488 | } | 502 | } |
489 | 503 | ||
490 | conn_info(tconn, "fence-peer helper returned %d (%s)\n", | 504 | drbd_info(connection, "fence-peer helper returned %d (%s)\n", |
491 | (r>>8) & 0xff, ex_to_string); | 505 | (r>>8) & 0xff, ex_to_string); |
492 | 506 | ||
493 | out: | 507 | out: |
494 | 508 | ||
495 | /* Not using | 509 | /* Not using |
496 | conn_request_state(tconn, mask, val, CS_VERBOSE); | 510 | conn_request_state(connection, mask, val, CS_VERBOSE); |
497 | here, because we might were able to re-establish the connection in the | 511 | here, because we might were able to re-establish the connection in the |
498 | meantime. */ | 512 | meantime. */ |
499 | spin_lock_irq(&tconn->req_lock); | 513 | spin_lock_irq(&connection->resource->req_lock); |
500 | if (tconn->cstate < C_WF_REPORT_PARAMS && !test_bit(STATE_SENT, &tconn->flags)) { | 514 | if (connection->cstate < C_WF_REPORT_PARAMS && !test_bit(STATE_SENT, &connection->flags)) { |
501 | if (tconn->connect_cnt != connect_cnt) | 515 | if (connection->connect_cnt != connect_cnt) |
502 | /* In case the connection was established and droped | 516 | /* In case the connection was established and droped |
503 | while the fence-peer handler was running, ignore it */ | 517 | while the fence-peer handler was running, ignore it */ |
504 | conn_info(tconn, "Ignoring fence-peer exit code\n"); | 518 | drbd_info(connection, "Ignoring fence-peer exit code\n"); |
505 | else | 519 | else |
506 | _conn_request_state(tconn, mask, val, CS_VERBOSE); | 520 | _conn_request_state(connection, mask, val, CS_VERBOSE); |
507 | } | 521 | } |
508 | spin_unlock_irq(&tconn->req_lock); | 522 | spin_unlock_irq(&connection->resource->req_lock); |
509 | 523 | ||
510 | return conn_highest_pdsk(tconn) <= D_OUTDATED; | 524 | return conn_highest_pdsk(connection) <= D_OUTDATED; |
511 | } | 525 | } |
512 | 526 | ||
513 | static int _try_outdate_peer_async(void *data) | 527 | static int _try_outdate_peer_async(void *data) |
514 | { | 528 | { |
515 | struct drbd_tconn *tconn = (struct drbd_tconn *)data; | 529 | struct drbd_connection *connection = (struct drbd_connection *)data; |
516 | 530 | ||
517 | conn_try_outdate_peer(tconn); | 531 | conn_try_outdate_peer(connection); |
518 | 532 | ||
519 | kref_put(&tconn->kref, &conn_destroy); | 533 | kref_put(&connection->kref, drbd_destroy_connection); |
520 | return 0; | 534 | return 0; |
521 | } | 535 | } |
522 | 536 | ||
523 | void conn_try_outdate_peer_async(struct drbd_tconn *tconn) | 537 | void conn_try_outdate_peer_async(struct drbd_connection *connection) |
524 | { | 538 | { |
525 | struct task_struct *opa; | 539 | struct task_struct *opa; |
526 | 540 | ||
527 | kref_get(&tconn->kref); | 541 | kref_get(&connection->kref); |
528 | opa = kthread_run(_try_outdate_peer_async, tconn, "drbd_async_h"); | 542 | opa = kthread_run(_try_outdate_peer_async, connection, "drbd_async_h"); |
529 | if (IS_ERR(opa)) { | 543 | if (IS_ERR(opa)) { |
530 | conn_err(tconn, "out of mem, failed to invoke fence-peer helper\n"); | 544 | drbd_err(connection, "out of mem, failed to invoke fence-peer helper\n"); |
531 | kref_put(&tconn->kref, &conn_destroy); | 545 | kref_put(&connection->kref, drbd_destroy_connection); |
532 | } | 546 | } |
533 | } | 547 | } |
534 | 548 | ||
535 | enum drbd_state_rv | 549 | enum drbd_state_rv |
536 | drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | 550 | drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force) |
537 | { | 551 | { |
538 | const int max_tries = 4; | 552 | const int max_tries = 4; |
539 | enum drbd_state_rv rv = SS_UNKNOWN_ERROR; | 553 | enum drbd_state_rv rv = SS_UNKNOWN_ERROR; |
@@ -542,16 +556,24 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
542 | int forced = 0; | 556 | int forced = 0; |
543 | union drbd_state mask, val; | 557 | union drbd_state mask, val; |
544 | 558 | ||
545 | if (new_role == R_PRIMARY) | 559 | if (new_role == R_PRIMARY) { |
546 | request_ping(mdev->tconn); /* Detect a dead peer ASAP */ | 560 | struct drbd_connection *connection; |
547 | 561 | ||
548 | mutex_lock(mdev->state_mutex); | 562 | /* Detect dead peers as soon as possible. */ |
563 | |||
564 | rcu_read_lock(); | ||
565 | for_each_connection(connection, device->resource) | ||
566 | request_ping(connection); | ||
567 | rcu_read_unlock(); | ||
568 | } | ||
569 | |||
570 | mutex_lock(device->state_mutex); | ||
549 | 571 | ||
550 | mask.i = 0; mask.role = R_MASK; | 572 | mask.i = 0; mask.role = R_MASK; |
551 | val.i = 0; val.role = new_role; | 573 | val.i = 0; val.role = new_role; |
552 | 574 | ||
553 | while (try++ < max_tries) { | 575 | while (try++ < max_tries) { |
554 | rv = _drbd_request_state(mdev, mask, val, CS_WAIT_COMPLETE); | 576 | rv = _drbd_request_state(device, mask, val, CS_WAIT_COMPLETE); |
555 | 577 | ||
556 | /* in case we first succeeded to outdate, | 578 | /* in case we first succeeded to outdate, |
557 | * but now suddenly could establish a connection */ | 579 | * but now suddenly could establish a connection */ |
@@ -562,8 +584,8 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
562 | } | 584 | } |
563 | 585 | ||
564 | if (rv == SS_NO_UP_TO_DATE_DISK && force && | 586 | if (rv == SS_NO_UP_TO_DATE_DISK && force && |
565 | (mdev->state.disk < D_UP_TO_DATE && | 587 | (device->state.disk < D_UP_TO_DATE && |
566 | mdev->state.disk >= D_INCONSISTENT)) { | 588 | device->state.disk >= D_INCONSISTENT)) { |
567 | mask.disk = D_MASK; | 589 | mask.disk = D_MASK; |
568 | val.disk = D_UP_TO_DATE; | 590 | val.disk = D_UP_TO_DATE; |
569 | forced = 1; | 591 | forced = 1; |
@@ -571,10 +593,10 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
571 | } | 593 | } |
572 | 594 | ||
573 | if (rv == SS_NO_UP_TO_DATE_DISK && | 595 | if (rv == SS_NO_UP_TO_DATE_DISK && |
574 | mdev->state.disk == D_CONSISTENT && mask.pdsk == 0) { | 596 | device->state.disk == D_CONSISTENT && mask.pdsk == 0) { |
575 | D_ASSERT(mdev->state.pdsk == D_UNKNOWN); | 597 | D_ASSERT(device, device->state.pdsk == D_UNKNOWN); |
576 | 598 | ||
577 | if (conn_try_outdate_peer(mdev->tconn)) { | 599 | if (conn_try_outdate_peer(first_peer_device(device)->connection)) { |
578 | val.disk = D_UP_TO_DATE; | 600 | val.disk = D_UP_TO_DATE; |
579 | mask.disk = D_MASK; | 601 | mask.disk = D_MASK; |
580 | } | 602 | } |
@@ -584,8 +606,8 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
584 | if (rv == SS_NOTHING_TO_DO) | 606 | if (rv == SS_NOTHING_TO_DO) |
585 | goto out; | 607 | goto out; |
586 | if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) { | 608 | if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) { |
587 | if (!conn_try_outdate_peer(mdev->tconn) && force) { | 609 | if (!conn_try_outdate_peer(first_peer_device(device)->connection) && force) { |
588 | dev_warn(DEV, "Forced into split brain situation!\n"); | 610 | drbd_warn(device, "Forced into split brain situation!\n"); |
589 | mask.pdsk = D_MASK; | 611 | mask.pdsk = D_MASK; |
590 | val.pdsk = D_OUTDATED; | 612 | val.pdsk = D_OUTDATED; |
591 | 613 | ||
@@ -597,7 +619,7 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
597 | retry at most once more in this case. */ | 619 | retry at most once more in this case. */ |
598 | int timeo; | 620 | int timeo; |
599 | rcu_read_lock(); | 621 | rcu_read_lock(); |
600 | nc = rcu_dereference(mdev->tconn->net_conf); | 622 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
601 | timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1; | 623 | timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1; |
602 | rcu_read_unlock(); | 624 | rcu_read_unlock(); |
603 | schedule_timeout_interruptible(timeo); | 625 | schedule_timeout_interruptible(timeo); |
@@ -606,7 +628,7 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
606 | continue; | 628 | continue; |
607 | } | 629 | } |
608 | if (rv < SS_SUCCESS) { | 630 | if (rv < SS_SUCCESS) { |
609 | rv = _drbd_request_state(mdev, mask, val, | 631 | rv = _drbd_request_state(device, mask, val, |
610 | CS_VERBOSE + CS_WAIT_COMPLETE); | 632 | CS_VERBOSE + CS_WAIT_COMPLETE); |
611 | if (rv < SS_SUCCESS) | 633 | if (rv < SS_SUCCESS) |
612 | goto out; | 634 | goto out; |
@@ -618,53 +640,53 @@ drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) | |||
618 | goto out; | 640 | goto out; |
619 | 641 | ||
620 | if (forced) | 642 | if (forced) |
621 | dev_warn(DEV, "Forced to consider local data as UpToDate!\n"); | 643 | drbd_warn(device, "Forced to consider local data as UpToDate!\n"); |
622 | 644 | ||
623 | /* Wait until nothing is on the fly :) */ | 645 | /* Wait until nothing is on the fly :) */ |
624 | wait_event(mdev->misc_wait, atomic_read(&mdev->ap_pending_cnt) == 0); | 646 | wait_event(device->misc_wait, atomic_read(&device->ap_pending_cnt) == 0); |
625 | 647 | ||
626 | /* FIXME also wait for all pending P_BARRIER_ACK? */ | 648 | /* FIXME also wait for all pending P_BARRIER_ACK? */ |
627 | 649 | ||
628 | if (new_role == R_SECONDARY) { | 650 | if (new_role == R_SECONDARY) { |
629 | set_disk_ro(mdev->vdisk, true); | 651 | set_disk_ro(device->vdisk, true); |
630 | if (get_ldev(mdev)) { | 652 | if (get_ldev(device)) { |
631 | mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; | 653 | device->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; |
632 | put_ldev(mdev); | 654 | put_ldev(device); |
633 | } | 655 | } |
634 | } else { | 656 | } else { |
635 | mutex_lock(&mdev->tconn->conf_update); | 657 | mutex_lock(&device->resource->conf_update); |
636 | nc = mdev->tconn->net_conf; | 658 | nc = first_peer_device(device)->connection->net_conf; |
637 | if (nc) | 659 | if (nc) |
638 | nc->discard_my_data = 0; /* without copy; single bit op is atomic */ | 660 | nc->discard_my_data = 0; /* without copy; single bit op is atomic */ |
639 | mutex_unlock(&mdev->tconn->conf_update); | 661 | mutex_unlock(&device->resource->conf_update); |
640 | 662 | ||
641 | set_disk_ro(mdev->vdisk, false); | 663 | set_disk_ro(device->vdisk, false); |
642 | if (get_ldev(mdev)) { | 664 | if (get_ldev(device)) { |
643 | if (((mdev->state.conn < C_CONNECTED || | 665 | if (((device->state.conn < C_CONNECTED || |
644 | mdev->state.pdsk <= D_FAILED) | 666 | device->state.pdsk <= D_FAILED) |
645 | && mdev->ldev->md.uuid[UI_BITMAP] == 0) || forced) | 667 | && device->ldev->md.uuid[UI_BITMAP] == 0) || forced) |
646 | drbd_uuid_new_current(mdev); | 668 | drbd_uuid_new_current(device); |
647 | 669 | ||
648 | mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1; | 670 | device->ldev->md.uuid[UI_CURRENT] |= (u64)1; |
649 | put_ldev(mdev); | 671 | put_ldev(device); |
650 | } | 672 | } |
651 | } | 673 | } |
652 | 674 | ||
653 | /* writeout of activity log covered areas of the bitmap | 675 | /* writeout of activity log covered areas of the bitmap |
654 | * to stable storage done in after state change already */ | 676 | * to stable storage done in after state change already */ |
655 | 677 | ||
656 | if (mdev->state.conn >= C_WF_REPORT_PARAMS) { | 678 | if (device->state.conn >= C_WF_REPORT_PARAMS) { |
657 | /* if this was forced, we should consider sync */ | 679 | /* if this was forced, we should consider sync */ |
658 | if (forced) | 680 | if (forced) |
659 | drbd_send_uuids(mdev); | 681 | drbd_send_uuids(first_peer_device(device)); |
660 | drbd_send_current_state(mdev); | 682 | drbd_send_current_state(first_peer_device(device)); |
661 | } | 683 | } |
662 | 684 | ||
663 | drbd_md_sync(mdev); | 685 | drbd_md_sync(device); |
664 | 686 | ||
665 | kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE); | 687 | kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE); |
666 | out: | 688 | out: |
667 | mutex_unlock(mdev->state_mutex); | 689 | mutex_unlock(device->state_mutex); |
668 | return rv; | 690 | return rv; |
669 | } | 691 | } |
670 | 692 | ||
@@ -699,9 +721,9 @@ int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info) | |||
699 | } | 721 | } |
700 | 722 | ||
701 | if (info->genlhdr->cmd == DRBD_ADM_PRIMARY) | 723 | if (info->genlhdr->cmd == DRBD_ADM_PRIMARY) |
702 | retcode = drbd_set_role(adm_ctx.mdev, R_PRIMARY, parms.assume_uptodate); | 724 | retcode = drbd_set_role(adm_ctx.device, R_PRIMARY, parms.assume_uptodate); |
703 | else | 725 | else |
704 | retcode = drbd_set_role(adm_ctx.mdev, R_SECONDARY, 0); | 726 | retcode = drbd_set_role(adm_ctx.device, R_SECONDARY, 0); |
705 | out: | 727 | out: |
706 | drbd_adm_finish(info, retcode); | 728 | drbd_adm_finish(info, retcode); |
707 | return 0; | 729 | return 0; |
@@ -728,7 +750,7 @@ out: | |||
728 | * Activity log size used to be fixed 32kB, | 750 | * Activity log size used to be fixed 32kB, |
729 | * but is about to become configurable. | 751 | * but is about to become configurable. |
730 | */ | 752 | */ |
731 | static void drbd_md_set_sector_offsets(struct drbd_conf *mdev, | 753 | static void drbd_md_set_sector_offsets(struct drbd_device *device, |
732 | struct drbd_backing_dev *bdev) | 754 | struct drbd_backing_dev *bdev) |
733 | { | 755 | { |
734 | sector_t md_size_sect = 0; | 756 | sector_t md_size_sect = 0; |
@@ -804,35 +826,35 @@ char *ppsize(char *buf, unsigned long long size) | |||
804 | * drbd_adm_suspend_io/drbd_adm_resume_io, | 826 | * drbd_adm_suspend_io/drbd_adm_resume_io, |
805 | * which are (sub) state changes triggered by admin (drbdsetup), | 827 | * which are (sub) state changes triggered by admin (drbdsetup), |
806 | * and can be long lived. | 828 | * and can be long lived. |
807 | * This changes an mdev->flag, is triggered by drbd internals, | 829 | * This changes an device->flag, is triggered by drbd internals, |
808 | * and should be short-lived. */ | 830 | * and should be short-lived. */ |
809 | void drbd_suspend_io(struct drbd_conf *mdev) | 831 | void drbd_suspend_io(struct drbd_device *device) |
810 | { | 832 | { |
811 | set_bit(SUSPEND_IO, &mdev->flags); | 833 | set_bit(SUSPEND_IO, &device->flags); |
812 | if (drbd_suspended(mdev)) | 834 | if (drbd_suspended(device)) |
813 | return; | 835 | return; |
814 | wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_bio_cnt)); | 836 | wait_event(device->misc_wait, !atomic_read(&device->ap_bio_cnt)); |
815 | } | 837 | } |
816 | 838 | ||
817 | void drbd_resume_io(struct drbd_conf *mdev) | 839 | void drbd_resume_io(struct drbd_device *device) |
818 | { | 840 | { |
819 | clear_bit(SUSPEND_IO, &mdev->flags); | 841 | clear_bit(SUSPEND_IO, &device->flags); |
820 | wake_up(&mdev->misc_wait); | 842 | wake_up(&device->misc_wait); |
821 | } | 843 | } |
822 | 844 | ||
823 | /** | 845 | /** |
824 | * drbd_determine_dev_size() - Sets the right device size obeying all constraints | 846 | * drbd_determine_dev_size() - Sets the right device size obeying all constraints |
825 | * @mdev: DRBD device. | 847 | * @device: DRBD device. |
826 | * | 848 | * |
827 | * Returns 0 on success, negative return values indicate errors. | 849 | * Returns 0 on success, negative return values indicate errors. |
828 | * You should call drbd_md_sync() after calling this function. | 850 | * You should call drbd_md_sync() after calling this function. |
829 | */ | 851 | */ |
830 | enum determine_dev_size | 852 | enum determine_dev_size |
831 | drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct resize_parms *rs) __must_hold(local) | 853 | drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct resize_parms *rs) __must_hold(local) |
832 | { | 854 | { |
833 | sector_t prev_first_sect, prev_size; /* previous meta location */ | 855 | sector_t prev_first_sect, prev_size; /* previous meta location */ |
834 | sector_t la_size_sect, u_size; | 856 | sector_t la_size_sect, u_size; |
835 | struct drbd_md *md = &mdev->ldev->md; | 857 | struct drbd_md *md = &device->ldev->md; |
836 | u32 prev_al_stripe_size_4k; | 858 | u32 prev_al_stripe_size_4k; |
837 | u32 prev_al_stripes; | 859 | u32 prev_al_stripes; |
838 | sector_t size; | 860 | sector_t size; |
@@ -851,19 +873,19 @@ drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct res | |||
851 | * Suspend IO right here. | 873 | * Suspend IO right here. |
852 | * still lock the act_log to not trigger ASSERTs there. | 874 | * still lock the act_log to not trigger ASSERTs there. |
853 | */ | 875 | */ |
854 | drbd_suspend_io(mdev); | 876 | drbd_suspend_io(device); |
855 | buffer = drbd_md_get_buffer(mdev); /* Lock meta-data IO */ | 877 | buffer = drbd_md_get_buffer(device); /* Lock meta-data IO */ |
856 | if (!buffer) { | 878 | if (!buffer) { |
857 | drbd_resume_io(mdev); | 879 | drbd_resume_io(device); |
858 | return DS_ERROR; | 880 | return DS_ERROR; |
859 | } | 881 | } |
860 | 882 | ||
861 | /* no wait necessary anymore, actually we could assert that */ | 883 | /* no wait necessary anymore, actually we could assert that */ |
862 | wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); | 884 | wait_event(device->al_wait, lc_try_lock(device->act_log)); |
863 | 885 | ||
864 | prev_first_sect = drbd_md_first_sector(mdev->ldev); | 886 | prev_first_sect = drbd_md_first_sector(device->ldev); |
865 | prev_size = mdev->ldev->md.md_size_sect; | 887 | prev_size = device->ldev->md.md_size_sect; |
866 | la_size_sect = mdev->ldev->md.la_size_sect; | 888 | la_size_sect = device->ldev->md.la_size_sect; |
867 | 889 | ||
868 | if (rs) { | 890 | if (rs) { |
869 | /* rs is non NULL if we should change the AL layout only */ | 891 | /* rs is non NULL if we should change the AL layout only */ |
@@ -876,18 +898,18 @@ drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct res | |||
876 | md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4; | 898 | md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4; |
877 | } | 899 | } |
878 | 900 | ||
879 | drbd_md_set_sector_offsets(mdev, mdev->ldev); | 901 | drbd_md_set_sector_offsets(device, device->ldev); |
880 | 902 | ||
881 | rcu_read_lock(); | 903 | rcu_read_lock(); |
882 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; | 904 | u_size = rcu_dereference(device->ldev->disk_conf)->disk_size; |
883 | rcu_read_unlock(); | 905 | rcu_read_unlock(); |
884 | size = drbd_new_dev_size(mdev, mdev->ldev, u_size, flags & DDSF_FORCED); | 906 | size = drbd_new_dev_size(device, device->ldev, u_size, flags & DDSF_FORCED); |
885 | 907 | ||
886 | if (size < la_size_sect) { | 908 | if (size < la_size_sect) { |
887 | if (rs && u_size == 0) { | 909 | if (rs && u_size == 0) { |
888 | /* Remove "rs &&" later. This check should always be active, but | 910 | /* Remove "rs &&" later. This check should always be active, but |
889 | right now the receiver expects the permissive behavior */ | 911 | right now the receiver expects the permissive behavior */ |
890 | dev_warn(DEV, "Implicit shrink not allowed. " | 912 | drbd_warn(device, "Implicit shrink not allowed. " |
891 | "Use --size=%llus for explicit shrink.\n", | 913 | "Use --size=%llus for explicit shrink.\n", |
892 | (unsigned long long)size); | 914 | (unsigned long long)size); |
893 | rv = DS_ERROR_SHRINK; | 915 | rv = DS_ERROR_SHRINK; |
@@ -898,60 +920,60 @@ drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct res | |||
898 | goto err_out; | 920 | goto err_out; |
899 | } | 921 | } |
900 | 922 | ||
901 | if (drbd_get_capacity(mdev->this_bdev) != size || | 923 | if (drbd_get_capacity(device->this_bdev) != size || |
902 | drbd_bm_capacity(mdev) != size) { | 924 | drbd_bm_capacity(device) != size) { |
903 | int err; | 925 | int err; |
904 | err = drbd_bm_resize(mdev, size, !(flags & DDSF_NO_RESYNC)); | 926 | err = drbd_bm_resize(device, size, !(flags & DDSF_NO_RESYNC)); |
905 | if (unlikely(err)) { | 927 | if (unlikely(err)) { |
906 | /* currently there is only one error: ENOMEM! */ | 928 | /* currently there is only one error: ENOMEM! */ |
907 | size = drbd_bm_capacity(mdev)>>1; | 929 | size = drbd_bm_capacity(device)>>1; |
908 | if (size == 0) { | 930 | if (size == 0) { |
909 | dev_err(DEV, "OUT OF MEMORY! " | 931 | drbd_err(device, "OUT OF MEMORY! " |
910 | "Could not allocate bitmap!\n"); | 932 | "Could not allocate bitmap!\n"); |
911 | } else { | 933 | } else { |
912 | dev_err(DEV, "BM resizing failed. " | 934 | drbd_err(device, "BM resizing failed. " |
913 | "Leaving size unchanged at size = %lu KB\n", | 935 | "Leaving size unchanged at size = %lu KB\n", |
914 | (unsigned long)size); | 936 | (unsigned long)size); |
915 | } | 937 | } |
916 | rv = DS_ERROR; | 938 | rv = DS_ERROR; |
917 | } | 939 | } |
918 | /* racy, see comments above. */ | 940 | /* racy, see comments above. */ |
919 | drbd_set_my_capacity(mdev, size); | 941 | drbd_set_my_capacity(device, size); |
920 | mdev->ldev->md.la_size_sect = size; | 942 | device->ldev->md.la_size_sect = size; |
921 | dev_info(DEV, "size = %s (%llu KB)\n", ppsize(ppb, size>>1), | 943 | drbd_info(device, "size = %s (%llu KB)\n", ppsize(ppb, size>>1), |
922 | (unsigned long long)size>>1); | 944 | (unsigned long long)size>>1); |
923 | } | 945 | } |
924 | if (rv <= DS_ERROR) | 946 | if (rv <= DS_ERROR) |
925 | goto err_out; | 947 | goto err_out; |
926 | 948 | ||
927 | la_size_changed = (la_size_sect != mdev->ldev->md.la_size_sect); | 949 | la_size_changed = (la_size_sect != device->ldev->md.la_size_sect); |
928 | 950 | ||
929 | md_moved = prev_first_sect != drbd_md_first_sector(mdev->ldev) | 951 | md_moved = prev_first_sect != drbd_md_first_sector(device->ldev) |
930 | || prev_size != mdev->ldev->md.md_size_sect; | 952 | || prev_size != device->ldev->md.md_size_sect; |
931 | 953 | ||
932 | if (la_size_changed || md_moved || rs) { | 954 | if (la_size_changed || md_moved || rs) { |
933 | u32 prev_flags; | 955 | u32 prev_flags; |
934 | 956 | ||
935 | drbd_al_shrink(mdev); /* All extents inactive. */ | 957 | drbd_al_shrink(device); /* All extents inactive. */ |
936 | 958 | ||
937 | prev_flags = md->flags; | 959 | prev_flags = md->flags; |
938 | md->flags &= ~MDF_PRIMARY_IND; | 960 | md->flags &= ~MDF_PRIMARY_IND; |
939 | drbd_md_write(mdev, buffer); | 961 | drbd_md_write(device, buffer); |
940 | 962 | ||
941 | dev_info(DEV, "Writing the whole bitmap, %s\n", | 963 | drbd_info(device, "Writing the whole bitmap, %s\n", |
942 | la_size_changed && md_moved ? "size changed and md moved" : | 964 | la_size_changed && md_moved ? "size changed and md moved" : |
943 | la_size_changed ? "size changed" : "md moved"); | 965 | la_size_changed ? "size changed" : "md moved"); |
944 | /* next line implicitly does drbd_suspend_io()+drbd_resume_io() */ | 966 | /* next line implicitly does drbd_suspend_io()+drbd_resume_io() */ |
945 | drbd_bitmap_io(mdev, md_moved ? &drbd_bm_write_all : &drbd_bm_write, | 967 | drbd_bitmap_io(device, md_moved ? &drbd_bm_write_all : &drbd_bm_write, |
946 | "size changed", BM_LOCKED_MASK); | 968 | "size changed", BM_LOCKED_MASK); |
947 | drbd_initialize_al(mdev, buffer); | 969 | drbd_initialize_al(device, buffer); |
948 | 970 | ||
949 | md->flags = prev_flags; | 971 | md->flags = prev_flags; |
950 | drbd_md_write(mdev, buffer); | 972 | drbd_md_write(device, buffer); |
951 | 973 | ||
952 | if (rs) | 974 | if (rs) |
953 | dev_info(DEV, "Changed AL layout to al-stripes = %d, al-stripe-size-kB = %d\n", | 975 | drbd_info(device, "Changed AL layout to al-stripes = %d, al-stripe-size-kB = %d\n", |
954 | md->al_stripes, md->al_stripe_size_4k * 4); | 976 | md->al_stripes, md->al_stripe_size_4k * 4); |
955 | } | 977 | } |
956 | 978 | ||
957 | if (size > la_size_sect) | 979 | if (size > la_size_sect) |
@@ -966,30 +988,30 @@ drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct res | |||
966 | md->al_stripe_size_4k = prev_al_stripe_size_4k; | 988 | md->al_stripe_size_4k = prev_al_stripe_size_4k; |
967 | md->al_size_4k = (u64)prev_al_stripes * prev_al_stripe_size_4k; | 989 | md->al_size_4k = (u64)prev_al_stripes * prev_al_stripe_size_4k; |
968 | 990 | ||
969 | drbd_md_set_sector_offsets(mdev, mdev->ldev); | 991 | drbd_md_set_sector_offsets(device, device->ldev); |
970 | } | 992 | } |
971 | } | 993 | } |
972 | lc_unlock(mdev->act_log); | 994 | lc_unlock(device->act_log); |
973 | wake_up(&mdev->al_wait); | 995 | wake_up(&device->al_wait); |
974 | drbd_md_put_buffer(mdev); | 996 | drbd_md_put_buffer(device); |
975 | drbd_resume_io(mdev); | 997 | drbd_resume_io(device); |
976 | 998 | ||
977 | return rv; | 999 | return rv; |
978 | } | 1000 | } |
979 | 1001 | ||
980 | sector_t | 1002 | sector_t |
981 | drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, | 1003 | drbd_new_dev_size(struct drbd_device *device, struct drbd_backing_dev *bdev, |
982 | sector_t u_size, int assume_peer_has_space) | 1004 | sector_t u_size, int assume_peer_has_space) |
983 | { | 1005 | { |
984 | sector_t p_size = mdev->p_size; /* partner's disk size. */ | 1006 | sector_t p_size = device->p_size; /* partner's disk size. */ |
985 | sector_t la_size_sect = bdev->md.la_size_sect; /* last agreed size. */ | 1007 | sector_t la_size_sect = bdev->md.la_size_sect; /* last agreed size. */ |
986 | sector_t m_size; /* my size */ | 1008 | sector_t m_size; /* my size */ |
987 | sector_t size = 0; | 1009 | sector_t size = 0; |
988 | 1010 | ||
989 | m_size = drbd_get_max_capacity(bdev); | 1011 | m_size = drbd_get_max_capacity(bdev); |
990 | 1012 | ||
991 | if (mdev->state.conn < C_CONNECTED && assume_peer_has_space) { | 1013 | if (device->state.conn < C_CONNECTED && assume_peer_has_space) { |
992 | dev_warn(DEV, "Resize while not connected was forced by the user!\n"); | 1014 | drbd_warn(device, "Resize while not connected was forced by the user!\n"); |
993 | p_size = m_size; | 1015 | p_size = m_size; |
994 | } | 1016 | } |
995 | 1017 | ||
@@ -1011,11 +1033,11 @@ drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, | |||
1011 | } | 1033 | } |
1012 | 1034 | ||
1013 | if (size == 0) | 1035 | if (size == 0) |
1014 | dev_err(DEV, "Both nodes diskless!\n"); | 1036 | drbd_err(device, "Both nodes diskless!\n"); |
1015 | 1037 | ||
1016 | if (u_size) { | 1038 | if (u_size) { |
1017 | if (u_size > size) | 1039 | if (u_size > size) |
1018 | dev_err(DEV, "Requested disk size is too big (%lu > %lu)\n", | 1040 | drbd_err(device, "Requested disk size is too big (%lu > %lu)\n", |
1019 | (unsigned long)u_size>>1, (unsigned long)size>>1); | 1041 | (unsigned long)u_size>>1, (unsigned long)size>>1); |
1020 | else | 1042 | else |
1021 | size = u_size; | 1043 | size = u_size; |
@@ -1026,71 +1048,71 @@ drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, | |||
1026 | 1048 | ||
1027 | /** | 1049 | /** |
1028 | * drbd_check_al_size() - Ensures that the AL is of the right size | 1050 | * drbd_check_al_size() - Ensures that the AL is of the right size |
1029 | * @mdev: DRBD device. | 1051 | * @device: DRBD device. |
1030 | * | 1052 | * |
1031 | * Returns -EBUSY if current al lru is still used, -ENOMEM when allocation | 1053 | * Returns -EBUSY if current al lru is still used, -ENOMEM when allocation |
1032 | * failed, and 0 on success. You should call drbd_md_sync() after you called | 1054 | * failed, and 0 on success. You should call drbd_md_sync() after you called |
1033 | * this function. | 1055 | * this function. |
1034 | */ | 1056 | */ |
1035 | static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc) | 1057 | static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc) |
1036 | { | 1058 | { |
1037 | struct lru_cache *n, *t; | 1059 | struct lru_cache *n, *t; |
1038 | struct lc_element *e; | 1060 | struct lc_element *e; |
1039 | unsigned int in_use; | 1061 | unsigned int in_use; |
1040 | int i; | 1062 | int i; |
1041 | 1063 | ||
1042 | if (mdev->act_log && | 1064 | if (device->act_log && |
1043 | mdev->act_log->nr_elements == dc->al_extents) | 1065 | device->act_log->nr_elements == dc->al_extents) |
1044 | return 0; | 1066 | return 0; |
1045 | 1067 | ||
1046 | in_use = 0; | 1068 | in_use = 0; |
1047 | t = mdev->act_log; | 1069 | t = device->act_log; |
1048 | n = lc_create("act_log", drbd_al_ext_cache, AL_UPDATES_PER_TRANSACTION, | 1070 | n = lc_create("act_log", drbd_al_ext_cache, AL_UPDATES_PER_TRANSACTION, |
1049 | dc->al_extents, sizeof(struct lc_element), 0); | 1071 | dc->al_extents, sizeof(struct lc_element), 0); |
1050 | 1072 | ||
1051 | if (n == NULL) { | 1073 | if (n == NULL) { |
1052 | dev_err(DEV, "Cannot allocate act_log lru!\n"); | 1074 | drbd_err(device, "Cannot allocate act_log lru!\n"); |
1053 | return -ENOMEM; | 1075 | return -ENOMEM; |
1054 | } | 1076 | } |
1055 | spin_lock_irq(&mdev->al_lock); | 1077 | spin_lock_irq(&device->al_lock); |
1056 | if (t) { | 1078 | if (t) { |
1057 | for (i = 0; i < t->nr_elements; i++) { | 1079 | for (i = 0; i < t->nr_elements; i++) { |
1058 | e = lc_element_by_index(t, i); | 1080 | e = lc_element_by_index(t, i); |
1059 | if (e->refcnt) | 1081 | if (e->refcnt) |
1060 | dev_err(DEV, "refcnt(%d)==%d\n", | 1082 | drbd_err(device, "refcnt(%d)==%d\n", |
1061 | e->lc_number, e->refcnt); | 1083 | e->lc_number, e->refcnt); |
1062 | in_use += e->refcnt; | 1084 | in_use += e->refcnt; |
1063 | } | 1085 | } |
1064 | } | 1086 | } |
1065 | if (!in_use) | 1087 | if (!in_use) |
1066 | mdev->act_log = n; | 1088 | device->act_log = n; |
1067 | spin_unlock_irq(&mdev->al_lock); | 1089 | spin_unlock_irq(&device->al_lock); |
1068 | if (in_use) { | 1090 | if (in_use) { |
1069 | dev_err(DEV, "Activity log still in use!\n"); | 1091 | drbd_err(device, "Activity log still in use!\n"); |
1070 | lc_destroy(n); | 1092 | lc_destroy(n); |
1071 | return -EBUSY; | 1093 | return -EBUSY; |
1072 | } else { | 1094 | } else { |
1073 | if (t) | 1095 | if (t) |
1074 | lc_destroy(t); | 1096 | lc_destroy(t); |
1075 | } | 1097 | } |
1076 | drbd_md_mark_dirty(mdev); /* we changed mdev->act_log->nr_elemens */ | 1098 | drbd_md_mark_dirty(device); /* we changed device->act_log->nr_elemens */ |
1077 | return 0; | 1099 | return 0; |
1078 | } | 1100 | } |
1079 | 1101 | ||
1080 | static void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int max_bio_size) | 1102 | static void drbd_setup_queue_param(struct drbd_device *device, unsigned int max_bio_size) |
1081 | { | 1103 | { |
1082 | struct request_queue * const q = mdev->rq_queue; | 1104 | struct request_queue * const q = device->rq_queue; |
1083 | unsigned int max_hw_sectors = max_bio_size >> 9; | 1105 | unsigned int max_hw_sectors = max_bio_size >> 9; |
1084 | unsigned int max_segments = 0; | 1106 | unsigned int max_segments = 0; |
1085 | 1107 | ||
1086 | if (get_ldev_if_state(mdev, D_ATTACHING)) { | 1108 | if (get_ldev_if_state(device, D_ATTACHING)) { |
1087 | struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue; | 1109 | struct request_queue * const b = device->ldev->backing_bdev->bd_disk->queue; |
1088 | 1110 | ||
1089 | max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9); | 1111 | max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9); |
1090 | rcu_read_lock(); | 1112 | rcu_read_lock(); |
1091 | max_segments = rcu_dereference(mdev->ldev->disk_conf)->max_bio_bvecs; | 1113 | max_segments = rcu_dereference(device->ldev->disk_conf)->max_bio_bvecs; |
1092 | rcu_read_unlock(); | 1114 | rcu_read_unlock(); |
1093 | put_ldev(mdev); | 1115 | put_ldev(device); |
1094 | } | 1116 | } |
1095 | 1117 | ||
1096 | blk_queue_logical_block_size(q, 512); | 1118 | blk_queue_logical_block_size(q, 512); |
@@ -1099,46 +1121,46 @@ static void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int max_bio_ | |||
1099 | blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS); | 1121 | blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS); |
1100 | blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1); | 1122 | blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1); |
1101 | 1123 | ||
1102 | if (get_ldev_if_state(mdev, D_ATTACHING)) { | 1124 | if (get_ldev_if_state(device, D_ATTACHING)) { |
1103 | struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue; | 1125 | struct request_queue * const b = device->ldev->backing_bdev->bd_disk->queue; |
1104 | 1126 | ||
1105 | blk_queue_stack_limits(q, b); | 1127 | blk_queue_stack_limits(q, b); |
1106 | 1128 | ||
1107 | if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) { | 1129 | if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) { |
1108 | dev_info(DEV, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n", | 1130 | drbd_info(device, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n", |
1109 | q->backing_dev_info.ra_pages, | 1131 | q->backing_dev_info.ra_pages, |
1110 | b->backing_dev_info.ra_pages); | 1132 | b->backing_dev_info.ra_pages); |
1111 | q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages; | 1133 | q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages; |
1112 | } | 1134 | } |
1113 | put_ldev(mdev); | 1135 | put_ldev(device); |
1114 | } | 1136 | } |
1115 | } | 1137 | } |
1116 | 1138 | ||
1117 | void drbd_reconsider_max_bio_size(struct drbd_conf *mdev) | 1139 | void drbd_reconsider_max_bio_size(struct drbd_device *device) |
1118 | { | 1140 | { |
1119 | unsigned int now, new, local, peer; | 1141 | unsigned int now, new, local, peer; |
1120 | 1142 | ||
1121 | now = queue_max_hw_sectors(mdev->rq_queue) << 9; | 1143 | now = queue_max_hw_sectors(device->rq_queue) << 9; |
1122 | local = mdev->local_max_bio_size; /* Eventually last known value, from volatile memory */ | 1144 | local = device->local_max_bio_size; /* Eventually last known value, from volatile memory */ |
1123 | peer = mdev->peer_max_bio_size; /* Eventually last known value, from meta data */ | 1145 | peer = device->peer_max_bio_size; /* Eventually last known value, from meta data */ |
1124 | 1146 | ||
1125 | if (get_ldev_if_state(mdev, D_ATTACHING)) { | 1147 | if (get_ldev_if_state(device, D_ATTACHING)) { |
1126 | local = queue_max_hw_sectors(mdev->ldev->backing_bdev->bd_disk->queue) << 9; | 1148 | local = queue_max_hw_sectors(device->ldev->backing_bdev->bd_disk->queue) << 9; |
1127 | mdev->local_max_bio_size = local; | 1149 | device->local_max_bio_size = local; |
1128 | put_ldev(mdev); | 1150 | put_ldev(device); |
1129 | } | 1151 | } |
1130 | local = min(local, DRBD_MAX_BIO_SIZE); | 1152 | local = min(local, DRBD_MAX_BIO_SIZE); |
1131 | 1153 | ||
1132 | /* We may ignore peer limits if the peer is modern enough. | 1154 | /* We may ignore peer limits if the peer is modern enough. |
1133 | Because new from 8.3.8 onwards the peer can use multiple | 1155 | Because new from 8.3.8 onwards the peer can use multiple |
1134 | BIOs for a single peer_request */ | 1156 | BIOs for a single peer_request */ |
1135 | if (mdev->state.conn >= C_WF_REPORT_PARAMS) { | 1157 | if (device->state.conn >= C_WF_REPORT_PARAMS) { |
1136 | if (mdev->tconn->agreed_pro_version < 94) | 1158 | if (first_peer_device(device)->connection->agreed_pro_version < 94) |
1137 | peer = min(mdev->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET); | 1159 | peer = min(device->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET); |
1138 | /* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */ | 1160 | /* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */ |
1139 | else if (mdev->tconn->agreed_pro_version == 94) | 1161 | else if (first_peer_device(device)->connection->agreed_pro_version == 94) |
1140 | peer = DRBD_MAX_SIZE_H80_PACKET; | 1162 | peer = DRBD_MAX_SIZE_H80_PACKET; |
1141 | else if (mdev->tconn->agreed_pro_version < 100) | 1163 | else if (first_peer_device(device)->connection->agreed_pro_version < 100) |
1142 | peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */ | 1164 | peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */ |
1143 | else | 1165 | else |
1144 | peer = DRBD_MAX_BIO_SIZE; | 1166 | peer = DRBD_MAX_BIO_SIZE; |
@@ -1146,57 +1168,57 @@ void drbd_reconsider_max_bio_size(struct drbd_conf *mdev) | |||
1146 | 1168 | ||
1147 | new = min(local, peer); | 1169 | new = min(local, peer); |
1148 | 1170 | ||
1149 | if (mdev->state.role == R_PRIMARY && new < now) | 1171 | if (device->state.role == R_PRIMARY && new < now) |
1150 | dev_err(DEV, "ASSERT FAILED new < now; (%u < %u)\n", new, now); | 1172 | drbd_err(device, "ASSERT FAILED new < now; (%u < %u)\n", new, now); |
1151 | 1173 | ||
1152 | if (new != now) | 1174 | if (new != now) |
1153 | dev_info(DEV, "max BIO size = %u\n", new); | 1175 | drbd_info(device, "max BIO size = %u\n", new); |
1154 | 1176 | ||
1155 | drbd_setup_queue_param(mdev, new); | 1177 | drbd_setup_queue_param(device, new); |
1156 | } | 1178 | } |
1157 | 1179 | ||
1158 | /* Starts the worker thread */ | 1180 | /* Starts the worker thread */ |
1159 | static void conn_reconfig_start(struct drbd_tconn *tconn) | 1181 | static void conn_reconfig_start(struct drbd_connection *connection) |
1160 | { | 1182 | { |
1161 | drbd_thread_start(&tconn->worker); | 1183 | drbd_thread_start(&connection->worker); |
1162 | conn_flush_workqueue(tconn); | 1184 | drbd_flush_workqueue(&connection->sender_work); |
1163 | } | 1185 | } |
1164 | 1186 | ||
1165 | /* if still unconfigured, stops worker again. */ | 1187 | /* if still unconfigured, stops worker again. */ |
1166 | static void conn_reconfig_done(struct drbd_tconn *tconn) | 1188 | static void conn_reconfig_done(struct drbd_connection *connection) |
1167 | { | 1189 | { |
1168 | bool stop_threads; | 1190 | bool stop_threads; |
1169 | spin_lock_irq(&tconn->req_lock); | 1191 | spin_lock_irq(&connection->resource->req_lock); |
1170 | stop_threads = conn_all_vols_unconf(tconn) && | 1192 | stop_threads = conn_all_vols_unconf(connection) && |
1171 | tconn->cstate == C_STANDALONE; | 1193 | connection->cstate == C_STANDALONE; |
1172 | spin_unlock_irq(&tconn->req_lock); | 1194 | spin_unlock_irq(&connection->resource->req_lock); |
1173 | if (stop_threads) { | 1195 | if (stop_threads) { |
1174 | /* asender is implicitly stopped by receiver | 1196 | /* asender is implicitly stopped by receiver |
1175 | * in conn_disconnect() */ | 1197 | * in conn_disconnect() */ |
1176 | drbd_thread_stop(&tconn->receiver); | 1198 | drbd_thread_stop(&connection->receiver); |
1177 | drbd_thread_stop(&tconn->worker); | 1199 | drbd_thread_stop(&connection->worker); |
1178 | } | 1200 | } |
1179 | } | 1201 | } |
1180 | 1202 | ||
1181 | /* Make sure IO is suspended before calling this function(). */ | 1203 | /* Make sure IO is suspended before calling this function(). */ |
1182 | static void drbd_suspend_al(struct drbd_conf *mdev) | 1204 | static void drbd_suspend_al(struct drbd_device *device) |
1183 | { | 1205 | { |
1184 | int s = 0; | 1206 | int s = 0; |
1185 | 1207 | ||
1186 | if (!lc_try_lock(mdev->act_log)) { | 1208 | if (!lc_try_lock(device->act_log)) { |
1187 | dev_warn(DEV, "Failed to lock al in drbd_suspend_al()\n"); | 1209 | drbd_warn(device, "Failed to lock al in drbd_suspend_al()\n"); |
1188 | return; | 1210 | return; |
1189 | } | 1211 | } |
1190 | 1212 | ||
1191 | drbd_al_shrink(mdev); | 1213 | drbd_al_shrink(device); |
1192 | spin_lock_irq(&mdev->tconn->req_lock); | 1214 | spin_lock_irq(&device->resource->req_lock); |
1193 | if (mdev->state.conn < C_CONNECTED) | 1215 | if (device->state.conn < C_CONNECTED) |
1194 | s = !test_and_set_bit(AL_SUSPENDED, &mdev->flags); | 1216 | s = !test_and_set_bit(AL_SUSPENDED, &device->flags); |
1195 | spin_unlock_irq(&mdev->tconn->req_lock); | 1217 | spin_unlock_irq(&device->resource->req_lock); |
1196 | lc_unlock(mdev->act_log); | 1218 | lc_unlock(device->act_log); |
1197 | 1219 | ||
1198 | if (s) | 1220 | if (s) |
1199 | dev_info(DEV, "Suspended AL updates\n"); | 1221 | drbd_info(device, "Suspended AL updates\n"); |
1200 | } | 1222 | } |
1201 | 1223 | ||
1202 | 1224 | ||
@@ -1237,7 +1259,7 @@ static unsigned int drbd_al_extents_max(struct drbd_backing_dev *bdev) | |||
1237 | int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | 1259 | int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) |
1238 | { | 1260 | { |
1239 | enum drbd_ret_code retcode; | 1261 | enum drbd_ret_code retcode; |
1240 | struct drbd_conf *mdev; | 1262 | struct drbd_device *device; |
1241 | struct disk_conf *new_disk_conf, *old_disk_conf; | 1263 | struct disk_conf *new_disk_conf, *old_disk_conf; |
1242 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; | 1264 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; |
1243 | int err, fifo_size; | 1265 | int err, fifo_size; |
@@ -1248,11 +1270,11 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1248 | if (retcode != NO_ERROR) | 1270 | if (retcode != NO_ERROR) |
1249 | goto out; | 1271 | goto out; |
1250 | 1272 | ||
1251 | mdev = adm_ctx.mdev; | 1273 | device = adm_ctx.device; |
1252 | 1274 | ||
1253 | /* we also need a disk | 1275 | /* we also need a disk |
1254 | * to change the options on */ | 1276 | * to change the options on */ |
1255 | if (!get_ldev(mdev)) { | 1277 | if (!get_ldev(device)) { |
1256 | retcode = ERR_NO_DISK; | 1278 | retcode = ERR_NO_DISK; |
1257 | goto out; | 1279 | goto out; |
1258 | } | 1280 | } |
@@ -1263,8 +1285,8 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1263 | goto fail; | 1285 | goto fail; |
1264 | } | 1286 | } |
1265 | 1287 | ||
1266 | mutex_lock(&mdev->tconn->conf_update); | 1288 | mutex_lock(&device->resource->conf_update); |
1267 | old_disk_conf = mdev->ldev->disk_conf; | 1289 | old_disk_conf = device->ldev->disk_conf; |
1268 | *new_disk_conf = *old_disk_conf; | 1290 | *new_disk_conf = *old_disk_conf; |
1269 | if (should_set_defaults(info)) | 1291 | if (should_set_defaults(info)) |
1270 | set_disk_conf_defaults(new_disk_conf); | 1292 | set_disk_conf_defaults(new_disk_conf); |
@@ -1273,6 +1295,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1273 | if (err && err != -ENOMSG) { | 1295 | if (err && err != -ENOMSG) { |
1274 | retcode = ERR_MANDATORY_TAG; | 1296 | retcode = ERR_MANDATORY_TAG; |
1275 | drbd_msg_put_info(from_attrs_err_to_txt(err)); | 1297 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
1298 | goto fail_unlock; | ||
1276 | } | 1299 | } |
1277 | 1300 | ||
1278 | if (!expect(new_disk_conf->resync_rate >= 1)) | 1301 | if (!expect(new_disk_conf->resync_rate >= 1)) |
@@ -1280,29 +1303,29 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1280 | 1303 | ||
1281 | if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN) | 1304 | if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN) |
1282 | new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN; | 1305 | new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN; |
1283 | if (new_disk_conf->al_extents > drbd_al_extents_max(mdev->ldev)) | 1306 | if (new_disk_conf->al_extents > drbd_al_extents_max(device->ldev)) |
1284 | new_disk_conf->al_extents = drbd_al_extents_max(mdev->ldev); | 1307 | new_disk_conf->al_extents = drbd_al_extents_max(device->ldev); |
1285 | 1308 | ||
1286 | if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX) | 1309 | if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX) |
1287 | new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX; | 1310 | new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX; |
1288 | 1311 | ||
1289 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; | 1312 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
1290 | if (fifo_size != mdev->rs_plan_s->size) { | 1313 | if (fifo_size != device->rs_plan_s->size) { |
1291 | new_plan = fifo_alloc(fifo_size); | 1314 | new_plan = fifo_alloc(fifo_size); |
1292 | if (!new_plan) { | 1315 | if (!new_plan) { |
1293 | dev_err(DEV, "kmalloc of fifo_buffer failed"); | 1316 | drbd_err(device, "kmalloc of fifo_buffer failed"); |
1294 | retcode = ERR_NOMEM; | 1317 | retcode = ERR_NOMEM; |
1295 | goto fail_unlock; | 1318 | goto fail_unlock; |
1296 | } | 1319 | } |
1297 | } | 1320 | } |
1298 | 1321 | ||
1299 | drbd_suspend_io(mdev); | 1322 | drbd_suspend_io(device); |
1300 | wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); | 1323 | wait_event(device->al_wait, lc_try_lock(device->act_log)); |
1301 | drbd_al_shrink(mdev); | 1324 | drbd_al_shrink(device); |
1302 | err = drbd_check_al_size(mdev, new_disk_conf); | 1325 | err = drbd_check_al_size(device, new_disk_conf); |
1303 | lc_unlock(mdev->act_log); | 1326 | lc_unlock(device->act_log); |
1304 | wake_up(&mdev->al_wait); | 1327 | wake_up(&device->al_wait); |
1305 | drbd_resume_io(mdev); | 1328 | drbd_resume_io(device); |
1306 | 1329 | ||
1307 | if (err) { | 1330 | if (err) { |
1308 | retcode = ERR_NOMEM; | 1331 | retcode = ERR_NOMEM; |
@@ -1310,10 +1333,10 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1310 | } | 1333 | } |
1311 | 1334 | ||
1312 | write_lock_irq(&global_state_lock); | 1335 | write_lock_irq(&global_state_lock); |
1313 | retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after); | 1336 | retcode = drbd_resync_after_valid(device, new_disk_conf->resync_after); |
1314 | if (retcode == NO_ERROR) { | 1337 | if (retcode == NO_ERROR) { |
1315 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); | 1338 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
1316 | drbd_resync_after_changed(mdev); | 1339 | drbd_resync_after_changed(device); |
1317 | } | 1340 | } |
1318 | write_unlock_irq(&global_state_lock); | 1341 | write_unlock_irq(&global_state_lock); |
1319 | 1342 | ||
@@ -1321,42 +1344,46 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) | |||
1321 | goto fail_unlock; | 1344 | goto fail_unlock; |
1322 | 1345 | ||
1323 | if (new_plan) { | 1346 | if (new_plan) { |
1324 | old_plan = mdev->rs_plan_s; | 1347 | old_plan = device->rs_plan_s; |
1325 | rcu_assign_pointer(mdev->rs_plan_s, new_plan); | 1348 | rcu_assign_pointer(device->rs_plan_s, new_plan); |
1326 | } | 1349 | } |
1327 | 1350 | ||
1328 | mutex_unlock(&mdev->tconn->conf_update); | 1351 | mutex_unlock(&device->resource->conf_update); |
1329 | 1352 | ||
1330 | if (new_disk_conf->al_updates) | 1353 | if (new_disk_conf->al_updates) |
1331 | mdev->ldev->md.flags &= ~MDF_AL_DISABLED; | 1354 | device->ldev->md.flags &= ~MDF_AL_DISABLED; |
1332 | else | 1355 | else |
1333 | mdev->ldev->md.flags |= MDF_AL_DISABLED; | 1356 | device->ldev->md.flags |= MDF_AL_DISABLED; |
1334 | 1357 | ||
1335 | if (new_disk_conf->md_flushes) | 1358 | if (new_disk_conf->md_flushes) |
1336 | clear_bit(MD_NO_FUA, &mdev->flags); | 1359 | clear_bit(MD_NO_FUA, &device->flags); |
1337 | else | 1360 | else |
1338 | set_bit(MD_NO_FUA, &mdev->flags); | 1361 | set_bit(MD_NO_FUA, &device->flags); |
1339 | 1362 | ||
1340 | drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush); | 1363 | drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush); |
1341 | 1364 | ||
1342 | drbd_md_sync(mdev); | 1365 | drbd_md_sync(device); |
1343 | 1366 | ||
1344 | if (mdev->state.conn >= C_CONNECTED) | 1367 | if (device->state.conn >= C_CONNECTED) { |
1345 | drbd_send_sync_param(mdev); | 1368 | struct drbd_peer_device *peer_device; |
1369 | |||
1370 | for_each_peer_device(peer_device, device) | ||
1371 | drbd_send_sync_param(peer_device); | ||
1372 | } | ||
1346 | 1373 | ||
1347 | synchronize_rcu(); | 1374 | synchronize_rcu(); |
1348 | kfree(old_disk_conf); | 1375 | kfree(old_disk_conf); |
1349 | kfree(old_plan); | 1376 | kfree(old_plan); |
1350 | mod_timer(&mdev->request_timer, jiffies + HZ); | 1377 | mod_timer(&device->request_timer, jiffies + HZ); |
1351 | goto success; | 1378 | goto success; |
1352 | 1379 | ||
1353 | fail_unlock: | 1380 | fail_unlock: |
1354 | mutex_unlock(&mdev->tconn->conf_update); | 1381 | mutex_unlock(&device->resource->conf_update); |
1355 | fail: | 1382 | fail: |
1356 | kfree(new_disk_conf); | 1383 | kfree(new_disk_conf); |
1357 | kfree(new_plan); | 1384 | kfree(new_plan); |
1358 | success: | 1385 | success: |
1359 | put_ldev(mdev); | 1386 | put_ldev(device); |
1360 | out: | 1387 | out: |
1361 | drbd_adm_finish(info, retcode); | 1388 | drbd_adm_finish(info, retcode); |
1362 | return 0; | 1389 | return 0; |
@@ -1364,7 +1391,7 @@ success: | |||
1364 | 1391 | ||
1365 | int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | 1392 | int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) |
1366 | { | 1393 | { |
1367 | struct drbd_conf *mdev; | 1394 | struct drbd_device *device; |
1368 | int err; | 1395 | int err; |
1369 | enum drbd_ret_code retcode; | 1396 | enum drbd_ret_code retcode; |
1370 | enum determine_dev_size dd; | 1397 | enum determine_dev_size dd; |
@@ -1385,11 +1412,11 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1385 | if (retcode != NO_ERROR) | 1412 | if (retcode != NO_ERROR) |
1386 | goto finish; | 1413 | goto finish; |
1387 | 1414 | ||
1388 | mdev = adm_ctx.mdev; | 1415 | device = adm_ctx.device; |
1389 | conn_reconfig_start(mdev->tconn); | 1416 | conn_reconfig_start(first_peer_device(device)->connection); |
1390 | 1417 | ||
1391 | /* if you want to reconfigure, please tear down first */ | 1418 | /* if you want to reconfigure, please tear down first */ |
1392 | if (mdev->state.disk > D_DISKLESS) { | 1419 | if (device->state.disk > D_DISKLESS) { |
1393 | retcode = ERR_DISK_CONFIGURED; | 1420 | retcode = ERR_DISK_CONFIGURED; |
1394 | goto fail; | 1421 | goto fail; |
1395 | } | 1422 | } |
@@ -1397,17 +1424,17 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1397 | * drbd_ldev_destroy is done already, we may end up here very fast, | 1424 | * drbd_ldev_destroy is done already, we may end up here very fast, |
1398 | * e.g. if someone calls attach from the on-io-error handler, | 1425 | * e.g. if someone calls attach from the on-io-error handler, |
1399 | * to realize a "hot spare" feature (not that I'd recommend that) */ | 1426 | * to realize a "hot spare" feature (not that I'd recommend that) */ |
1400 | wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt)); | 1427 | wait_event(device->misc_wait, !atomic_read(&device->local_cnt)); |
1401 | 1428 | ||
1402 | /* make sure there is no leftover from previous force-detach attempts */ | 1429 | /* make sure there is no leftover from previous force-detach attempts */ |
1403 | clear_bit(FORCE_DETACH, &mdev->flags); | 1430 | clear_bit(FORCE_DETACH, &device->flags); |
1404 | clear_bit(WAS_IO_ERROR, &mdev->flags); | 1431 | clear_bit(WAS_IO_ERROR, &device->flags); |
1405 | clear_bit(WAS_READ_ERROR, &mdev->flags); | 1432 | clear_bit(WAS_READ_ERROR, &device->flags); |
1406 | 1433 | ||
1407 | /* and no leftover from previously aborted resync or verify, either */ | 1434 | /* and no leftover from previously aborted resync or verify, either */ |
1408 | mdev->rs_total = 0; | 1435 | device->rs_total = 0; |
1409 | mdev->rs_failed = 0; | 1436 | device->rs_failed = 0; |
1410 | atomic_set(&mdev->rs_pending_cnt, 0); | 1437 | atomic_set(&device->rs_pending_cnt, 0); |
1411 | 1438 | ||
1412 | /* allocation not in the IO path, drbdsetup context */ | 1439 | /* allocation not in the IO path, drbdsetup context */ |
1413 | nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL); | 1440 | nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL); |
@@ -1447,13 +1474,13 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1447 | } | 1474 | } |
1448 | 1475 | ||
1449 | write_lock_irq(&global_state_lock); | 1476 | write_lock_irq(&global_state_lock); |
1450 | retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after); | 1477 | retcode = drbd_resync_after_valid(device, new_disk_conf->resync_after); |
1451 | write_unlock_irq(&global_state_lock); | 1478 | write_unlock_irq(&global_state_lock); |
1452 | if (retcode != NO_ERROR) | 1479 | if (retcode != NO_ERROR) |
1453 | goto fail; | 1480 | goto fail; |
1454 | 1481 | ||
1455 | rcu_read_lock(); | 1482 | rcu_read_lock(); |
1456 | nc = rcu_dereference(mdev->tconn->net_conf); | 1483 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
1457 | if (nc) { | 1484 | if (nc) { |
1458 | if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) { | 1485 | if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) { |
1459 | rcu_read_unlock(); | 1486 | rcu_read_unlock(); |
@@ -1464,9 +1491,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1464 | rcu_read_unlock(); | 1491 | rcu_read_unlock(); |
1465 | 1492 | ||
1466 | bdev = blkdev_get_by_path(new_disk_conf->backing_dev, | 1493 | bdev = blkdev_get_by_path(new_disk_conf->backing_dev, |
1467 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev); | 1494 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, device); |
1468 | if (IS_ERR(bdev)) { | 1495 | if (IS_ERR(bdev)) { |
1469 | dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->backing_dev, | 1496 | drbd_err(device, "open(\"%s\") failed with %ld\n", new_disk_conf->backing_dev, |
1470 | PTR_ERR(bdev)); | 1497 | PTR_ERR(bdev)); |
1471 | retcode = ERR_OPEN_DISK; | 1498 | retcode = ERR_OPEN_DISK; |
1472 | goto fail; | 1499 | goto fail; |
@@ -1484,9 +1511,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1484 | bdev = blkdev_get_by_path(new_disk_conf->meta_dev, | 1511 | bdev = blkdev_get_by_path(new_disk_conf->meta_dev, |
1485 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, | 1512 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, |
1486 | (new_disk_conf->meta_dev_idx < 0) ? | 1513 | (new_disk_conf->meta_dev_idx < 0) ? |
1487 | (void *)mdev : (void *)drbd_m_holder); | 1514 | (void *)device : (void *)drbd_m_holder); |
1488 | if (IS_ERR(bdev)) { | 1515 | if (IS_ERR(bdev)) { |
1489 | dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->meta_dev, | 1516 | drbd_err(device, "open(\"%s\") failed with %ld\n", new_disk_conf->meta_dev, |
1490 | PTR_ERR(bdev)); | 1517 | PTR_ERR(bdev)); |
1491 | retcode = ERR_OPEN_MD_DISK; | 1518 | retcode = ERR_OPEN_MD_DISK; |
1492 | goto fail; | 1519 | goto fail; |
@@ -1510,7 +1537,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1510 | 1537 | ||
1511 | /* Read our meta data super block early. | 1538 | /* Read our meta data super block early. |
1512 | * This also sets other on-disk offsets. */ | 1539 | * This also sets other on-disk offsets. */ |
1513 | retcode = drbd_md_read(mdev, nbc); | 1540 | retcode = drbd_md_read(device, nbc); |
1514 | if (retcode != NO_ERROR) | 1541 | if (retcode != NO_ERROR) |
1515 | goto fail; | 1542 | goto fail; |
1516 | 1543 | ||
@@ -1520,7 +1547,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1520 | new_disk_conf->al_extents = drbd_al_extents_max(nbc); | 1547 | new_disk_conf->al_extents = drbd_al_extents_max(nbc); |
1521 | 1548 | ||
1522 | if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) { | 1549 | if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) { |
1523 | dev_err(DEV, "max capacity %llu smaller than disk size %llu\n", | 1550 | drbd_err(device, "max capacity %llu smaller than disk size %llu\n", |
1524 | (unsigned long long) drbd_get_max_capacity(nbc), | 1551 | (unsigned long long) drbd_get_max_capacity(nbc), |
1525 | (unsigned long long) new_disk_conf->disk_size); | 1552 | (unsigned long long) new_disk_conf->disk_size); |
1526 | retcode = ERR_DISK_TOO_SMALL; | 1553 | retcode = ERR_DISK_TOO_SMALL; |
@@ -1538,7 +1565,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1538 | 1565 | ||
1539 | if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) { | 1566 | if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) { |
1540 | retcode = ERR_MD_DISK_TOO_SMALL; | 1567 | retcode = ERR_MD_DISK_TOO_SMALL; |
1541 | dev_warn(DEV, "refusing attach: md-device too small, " | 1568 | drbd_warn(device, "refusing attach: md-device too small, " |
1542 | "at least %llu sectors needed for this meta-disk type\n", | 1569 | "at least %llu sectors needed for this meta-disk type\n", |
1543 | (unsigned long long) min_md_device_sectors); | 1570 | (unsigned long long) min_md_device_sectors); |
1544 | goto fail; | 1571 | goto fail; |
@@ -1547,7 +1574,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1547 | /* Make sure the new disk is big enough | 1574 | /* Make sure the new disk is big enough |
1548 | * (we may currently be R_PRIMARY with no local disk...) */ | 1575 | * (we may currently be R_PRIMARY with no local disk...) */ |
1549 | if (drbd_get_max_capacity(nbc) < | 1576 | if (drbd_get_max_capacity(nbc) < |
1550 | drbd_get_capacity(mdev->this_bdev)) { | 1577 | drbd_get_capacity(device->this_bdev)) { |
1551 | retcode = ERR_DISK_TOO_SMALL; | 1578 | retcode = ERR_DISK_TOO_SMALL; |
1552 | goto fail; | 1579 | goto fail; |
1553 | } | 1580 | } |
@@ -1555,15 +1582,15 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1555 | nbc->known_size = drbd_get_capacity(nbc->backing_bdev); | 1582 | nbc->known_size = drbd_get_capacity(nbc->backing_bdev); |
1556 | 1583 | ||
1557 | if (nbc->known_size > max_possible_sectors) { | 1584 | if (nbc->known_size > max_possible_sectors) { |
1558 | dev_warn(DEV, "==> truncating very big lower level device " | 1585 | drbd_warn(device, "==> truncating very big lower level device " |
1559 | "to currently maximum possible %llu sectors <==\n", | 1586 | "to currently maximum possible %llu sectors <==\n", |
1560 | (unsigned long long) max_possible_sectors); | 1587 | (unsigned long long) max_possible_sectors); |
1561 | if (new_disk_conf->meta_dev_idx >= 0) | 1588 | if (new_disk_conf->meta_dev_idx >= 0) |
1562 | dev_warn(DEV, "==>> using internal or flexible " | 1589 | drbd_warn(device, "==>> using internal or flexible " |
1563 | "meta data may help <<==\n"); | 1590 | "meta data may help <<==\n"); |
1564 | } | 1591 | } |
1565 | 1592 | ||
1566 | drbd_suspend_io(mdev); | 1593 | drbd_suspend_io(device); |
1567 | /* also wait for the last barrier ack. */ | 1594 | /* also wait for the last barrier ack. */ |
1568 | /* FIXME see also https://daiquiri.linbit/cgi-bin/bugzilla/show_bug.cgi?id=171 | 1595 | /* FIXME see also https://daiquiri.linbit/cgi-bin/bugzilla/show_bug.cgi?id=171 |
1569 | * We need a way to either ignore barrier acks for barriers sent before a device | 1596 | * We need a way to either ignore barrier acks for barriers sent before a device |
@@ -1571,45 +1598,45 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1571 | * As barriers are counted per resource, | 1598 | * As barriers are counted per resource, |
1572 | * we'd need to suspend io on all devices of a resource. | 1599 | * we'd need to suspend io on all devices of a resource. |
1573 | */ | 1600 | */ |
1574 | wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_pending_cnt) || drbd_suspended(mdev)); | 1601 | wait_event(device->misc_wait, !atomic_read(&device->ap_pending_cnt) || drbd_suspended(device)); |
1575 | /* and for any other previously queued work */ | 1602 | /* and for any other previously queued work */ |
1576 | drbd_flush_workqueue(mdev); | 1603 | drbd_flush_workqueue(&first_peer_device(device)->connection->sender_work); |
1577 | 1604 | ||
1578 | rv = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE); | 1605 | rv = _drbd_request_state(device, NS(disk, D_ATTACHING), CS_VERBOSE); |
1579 | retcode = rv; /* FIXME: Type mismatch. */ | 1606 | retcode = rv; /* FIXME: Type mismatch. */ |
1580 | drbd_resume_io(mdev); | 1607 | drbd_resume_io(device); |
1581 | if (rv < SS_SUCCESS) | 1608 | if (rv < SS_SUCCESS) |
1582 | goto fail; | 1609 | goto fail; |
1583 | 1610 | ||
1584 | if (!get_ldev_if_state(mdev, D_ATTACHING)) | 1611 | if (!get_ldev_if_state(device, D_ATTACHING)) |
1585 | goto force_diskless; | 1612 | goto force_diskless; |
1586 | 1613 | ||
1587 | if (!mdev->bitmap) { | 1614 | if (!device->bitmap) { |
1588 | if (drbd_bm_init(mdev)) { | 1615 | if (drbd_bm_init(device)) { |
1589 | retcode = ERR_NOMEM; | 1616 | retcode = ERR_NOMEM; |
1590 | goto force_diskless_dec; | 1617 | goto force_diskless_dec; |
1591 | } | 1618 | } |
1592 | } | 1619 | } |
1593 | 1620 | ||
1594 | if (mdev->state.conn < C_CONNECTED && | 1621 | if (device->state.conn < C_CONNECTED && |
1595 | mdev->state.role == R_PRIMARY && | 1622 | device->state.role == R_PRIMARY && |
1596 | (mdev->ed_uuid & ~((u64)1)) != (nbc->md.uuid[UI_CURRENT] & ~((u64)1))) { | 1623 | (device->ed_uuid & ~((u64)1)) != (nbc->md.uuid[UI_CURRENT] & ~((u64)1))) { |
1597 | dev_err(DEV, "Can only attach to data with current UUID=%016llX\n", | 1624 | drbd_err(device, "Can only attach to data with current UUID=%016llX\n", |
1598 | (unsigned long long)mdev->ed_uuid); | 1625 | (unsigned long long)device->ed_uuid); |
1599 | retcode = ERR_DATA_NOT_CURRENT; | 1626 | retcode = ERR_DATA_NOT_CURRENT; |
1600 | goto force_diskless_dec; | 1627 | goto force_diskless_dec; |
1601 | } | 1628 | } |
1602 | 1629 | ||
1603 | /* Since we are diskless, fix the activity log first... */ | 1630 | /* Since we are diskless, fix the activity log first... */ |
1604 | if (drbd_check_al_size(mdev, new_disk_conf)) { | 1631 | if (drbd_check_al_size(device, new_disk_conf)) { |
1605 | retcode = ERR_NOMEM; | 1632 | retcode = ERR_NOMEM; |
1606 | goto force_diskless_dec; | 1633 | goto force_diskless_dec; |
1607 | } | 1634 | } |
1608 | 1635 | ||
1609 | /* Prevent shrinking of consistent devices ! */ | 1636 | /* Prevent shrinking of consistent devices ! */ |
1610 | if (drbd_md_test_flag(nbc, MDF_CONSISTENT) && | 1637 | if (drbd_md_test_flag(nbc, MDF_CONSISTENT) && |
1611 | drbd_new_dev_size(mdev, nbc, nbc->disk_conf->disk_size, 0) < nbc->md.la_size_sect) { | 1638 | drbd_new_dev_size(device, nbc, nbc->disk_conf->disk_size, 0) < nbc->md.la_size_sect) { |
1612 | dev_warn(DEV, "refusing to truncate a consistent device\n"); | 1639 | drbd_warn(device, "refusing to truncate a consistent device\n"); |
1613 | retcode = ERR_DISK_TOO_SMALL; | 1640 | retcode = ERR_DISK_TOO_SMALL; |
1614 | goto force_diskless_dec; | 1641 | goto force_diskless_dec; |
1615 | } | 1642 | } |
@@ -1617,40 +1644,40 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1617 | /* Reset the "barriers don't work" bits here, then force meta data to | 1644 | /* Reset the "barriers don't work" bits here, then force meta data to |
1618 | * be written, to ensure we determine if barriers are supported. */ | 1645 | * be written, to ensure we determine if barriers are supported. */ |
1619 | if (new_disk_conf->md_flushes) | 1646 | if (new_disk_conf->md_flushes) |
1620 | clear_bit(MD_NO_FUA, &mdev->flags); | 1647 | clear_bit(MD_NO_FUA, &device->flags); |
1621 | else | 1648 | else |
1622 | set_bit(MD_NO_FUA, &mdev->flags); | 1649 | set_bit(MD_NO_FUA, &device->flags); |
1623 | 1650 | ||
1624 | /* Point of no return reached. | 1651 | /* Point of no return reached. |
1625 | * Devices and memory are no longer released by error cleanup below. | 1652 | * Devices and memory are no longer released by error cleanup below. |
1626 | * now mdev takes over responsibility, and the state engine should | 1653 | * now device takes over responsibility, and the state engine should |
1627 | * clean it up somewhere. */ | 1654 | * clean it up somewhere. */ |
1628 | D_ASSERT(mdev->ldev == NULL); | 1655 | D_ASSERT(device, device->ldev == NULL); |
1629 | mdev->ldev = nbc; | 1656 | device->ldev = nbc; |
1630 | mdev->resync = resync_lru; | 1657 | device->resync = resync_lru; |
1631 | mdev->rs_plan_s = new_plan; | 1658 | device->rs_plan_s = new_plan; |
1632 | nbc = NULL; | 1659 | nbc = NULL; |
1633 | resync_lru = NULL; | 1660 | resync_lru = NULL; |
1634 | new_disk_conf = NULL; | 1661 | new_disk_conf = NULL; |
1635 | new_plan = NULL; | 1662 | new_plan = NULL; |
1636 | 1663 | ||
1637 | drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush); | 1664 | drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush); |
1638 | 1665 | ||
1639 | if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY)) | 1666 | if (drbd_md_test_flag(device->ldev, MDF_CRASHED_PRIMARY)) |
1640 | set_bit(CRASHED_PRIMARY, &mdev->flags); | 1667 | set_bit(CRASHED_PRIMARY, &device->flags); |
1641 | else | 1668 | else |
1642 | clear_bit(CRASHED_PRIMARY, &mdev->flags); | 1669 | clear_bit(CRASHED_PRIMARY, &device->flags); |
1643 | 1670 | ||
1644 | if (drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) && | 1671 | if (drbd_md_test_flag(device->ldev, MDF_PRIMARY_IND) && |
1645 | !(mdev->state.role == R_PRIMARY && mdev->tconn->susp_nod)) | 1672 | !(device->state.role == R_PRIMARY && device->resource->susp_nod)) |
1646 | set_bit(CRASHED_PRIMARY, &mdev->flags); | 1673 | set_bit(CRASHED_PRIMARY, &device->flags); |
1647 | 1674 | ||
1648 | mdev->send_cnt = 0; | 1675 | device->send_cnt = 0; |
1649 | mdev->recv_cnt = 0; | 1676 | device->recv_cnt = 0; |
1650 | mdev->read_cnt = 0; | 1677 | device->read_cnt = 0; |
1651 | mdev->writ_cnt = 0; | 1678 | device->writ_cnt = 0; |
1652 | 1679 | ||
1653 | drbd_reconsider_max_bio_size(mdev); | 1680 | drbd_reconsider_max_bio_size(device); |
1654 | 1681 | ||
1655 | /* If I am currently not R_PRIMARY, | 1682 | /* If I am currently not R_PRIMARY, |
1656 | * but meta data primary indicator is set, | 1683 | * but meta data primary indicator is set, |
@@ -1666,50 +1693,50 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1666 | * so we can automatically recover from a crash of a | 1693 | * so we can automatically recover from a crash of a |
1667 | * degraded but active "cluster" after a certain timeout. | 1694 | * degraded but active "cluster" after a certain timeout. |
1668 | */ | 1695 | */ |
1669 | clear_bit(USE_DEGR_WFC_T, &mdev->flags); | 1696 | clear_bit(USE_DEGR_WFC_T, &device->flags); |
1670 | if (mdev->state.role != R_PRIMARY && | 1697 | if (device->state.role != R_PRIMARY && |
1671 | drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) && | 1698 | drbd_md_test_flag(device->ldev, MDF_PRIMARY_IND) && |
1672 | !drbd_md_test_flag(mdev->ldev, MDF_CONNECTED_IND)) | 1699 | !drbd_md_test_flag(device->ldev, MDF_CONNECTED_IND)) |
1673 | set_bit(USE_DEGR_WFC_T, &mdev->flags); | 1700 | set_bit(USE_DEGR_WFC_T, &device->flags); |
1674 | 1701 | ||
1675 | dd = drbd_determine_dev_size(mdev, 0, NULL); | 1702 | dd = drbd_determine_dev_size(device, 0, NULL); |
1676 | if (dd <= DS_ERROR) { | 1703 | if (dd <= DS_ERROR) { |
1677 | retcode = ERR_NOMEM_BITMAP; | 1704 | retcode = ERR_NOMEM_BITMAP; |
1678 | goto force_diskless_dec; | 1705 | goto force_diskless_dec; |
1679 | } else if (dd == DS_GREW) | 1706 | } else if (dd == DS_GREW) |
1680 | set_bit(RESYNC_AFTER_NEG, &mdev->flags); | 1707 | set_bit(RESYNC_AFTER_NEG, &device->flags); |
1681 | 1708 | ||
1682 | if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC) || | 1709 | if (drbd_md_test_flag(device->ldev, MDF_FULL_SYNC) || |
1683 | (test_bit(CRASHED_PRIMARY, &mdev->flags) && | 1710 | (test_bit(CRASHED_PRIMARY, &device->flags) && |
1684 | drbd_md_test_flag(mdev->ldev, MDF_AL_DISABLED))) { | 1711 | drbd_md_test_flag(device->ldev, MDF_AL_DISABLED))) { |
1685 | dev_info(DEV, "Assuming that all blocks are out of sync " | 1712 | drbd_info(device, "Assuming that all blocks are out of sync " |
1686 | "(aka FullSync)\n"); | 1713 | "(aka FullSync)\n"); |
1687 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, | 1714 | if (drbd_bitmap_io(device, &drbd_bmio_set_n_write, |
1688 | "set_n_write from attaching", BM_LOCKED_MASK)) { | 1715 | "set_n_write from attaching", BM_LOCKED_MASK)) { |
1689 | retcode = ERR_IO_MD_DISK; | 1716 | retcode = ERR_IO_MD_DISK; |
1690 | goto force_diskless_dec; | 1717 | goto force_diskless_dec; |
1691 | } | 1718 | } |
1692 | } else { | 1719 | } else { |
1693 | if (drbd_bitmap_io(mdev, &drbd_bm_read, | 1720 | if (drbd_bitmap_io(device, &drbd_bm_read, |
1694 | "read from attaching", BM_LOCKED_MASK)) { | 1721 | "read from attaching", BM_LOCKED_MASK)) { |
1695 | retcode = ERR_IO_MD_DISK; | 1722 | retcode = ERR_IO_MD_DISK; |
1696 | goto force_diskless_dec; | 1723 | goto force_diskless_dec; |
1697 | } | 1724 | } |
1698 | } | 1725 | } |
1699 | 1726 | ||
1700 | if (_drbd_bm_total_weight(mdev) == drbd_bm_bits(mdev)) | 1727 | if (_drbd_bm_total_weight(device) == drbd_bm_bits(device)) |
1701 | drbd_suspend_al(mdev); /* IO is still suspended here... */ | 1728 | drbd_suspend_al(device); /* IO is still suspended here... */ |
1702 | 1729 | ||
1703 | spin_lock_irq(&mdev->tconn->req_lock); | 1730 | spin_lock_irq(&device->resource->req_lock); |
1704 | os = drbd_read_state(mdev); | 1731 | os = drbd_read_state(device); |
1705 | ns = os; | 1732 | ns = os; |
1706 | /* If MDF_CONSISTENT is not set go into inconsistent state, | 1733 | /* If MDF_CONSISTENT is not set go into inconsistent state, |
1707 | otherwise investigate MDF_WasUpToDate... | 1734 | otherwise investigate MDF_WasUpToDate... |
1708 | If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state, | 1735 | If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state, |
1709 | otherwise into D_CONSISTENT state. | 1736 | otherwise into D_CONSISTENT state. |
1710 | */ | 1737 | */ |
1711 | if (drbd_md_test_flag(mdev->ldev, MDF_CONSISTENT)) { | 1738 | if (drbd_md_test_flag(device->ldev, MDF_CONSISTENT)) { |
1712 | if (drbd_md_test_flag(mdev->ldev, MDF_WAS_UP_TO_DATE)) | 1739 | if (drbd_md_test_flag(device->ldev, MDF_WAS_UP_TO_DATE)) |
1713 | ns.disk = D_CONSISTENT; | 1740 | ns.disk = D_CONSISTENT; |
1714 | else | 1741 | else |
1715 | ns.disk = D_OUTDATED; | 1742 | ns.disk = D_OUTDATED; |
@@ -1717,12 +1744,12 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1717 | ns.disk = D_INCONSISTENT; | 1744 | ns.disk = D_INCONSISTENT; |
1718 | } | 1745 | } |
1719 | 1746 | ||
1720 | if (drbd_md_test_flag(mdev->ldev, MDF_PEER_OUT_DATED)) | 1747 | if (drbd_md_test_flag(device->ldev, MDF_PEER_OUT_DATED)) |
1721 | ns.pdsk = D_OUTDATED; | 1748 | ns.pdsk = D_OUTDATED; |
1722 | 1749 | ||
1723 | rcu_read_lock(); | 1750 | rcu_read_lock(); |
1724 | if (ns.disk == D_CONSISTENT && | 1751 | if (ns.disk == D_CONSISTENT && |
1725 | (ns.pdsk == D_OUTDATED || rcu_dereference(mdev->ldev->disk_conf)->fencing == FP_DONT_CARE)) | 1752 | (ns.pdsk == D_OUTDATED || rcu_dereference(device->ldev->disk_conf)->fencing == FP_DONT_CARE)) |
1726 | ns.disk = D_UP_TO_DATE; | 1753 | ns.disk = D_UP_TO_DATE; |
1727 | 1754 | ||
1728 | /* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND, | 1755 | /* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND, |
@@ -1730,56 +1757,56 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1730 | this point, because drbd_request_state() modifies these | 1757 | this point, because drbd_request_state() modifies these |
1731 | flags. */ | 1758 | flags. */ |
1732 | 1759 | ||
1733 | if (rcu_dereference(mdev->ldev->disk_conf)->al_updates) | 1760 | if (rcu_dereference(device->ldev->disk_conf)->al_updates) |
1734 | mdev->ldev->md.flags &= ~MDF_AL_DISABLED; | 1761 | device->ldev->md.flags &= ~MDF_AL_DISABLED; |
1735 | else | 1762 | else |
1736 | mdev->ldev->md.flags |= MDF_AL_DISABLED; | 1763 | device->ldev->md.flags |= MDF_AL_DISABLED; |
1737 | 1764 | ||
1738 | rcu_read_unlock(); | 1765 | rcu_read_unlock(); |
1739 | 1766 | ||
1740 | /* In case we are C_CONNECTED postpone any decision on the new disk | 1767 | /* In case we are C_CONNECTED postpone any decision on the new disk |
1741 | state after the negotiation phase. */ | 1768 | state after the negotiation phase. */ |
1742 | if (mdev->state.conn == C_CONNECTED) { | 1769 | if (device->state.conn == C_CONNECTED) { |
1743 | mdev->new_state_tmp.i = ns.i; | 1770 | device->new_state_tmp.i = ns.i; |
1744 | ns.i = os.i; | 1771 | ns.i = os.i; |
1745 | ns.disk = D_NEGOTIATING; | 1772 | ns.disk = D_NEGOTIATING; |
1746 | 1773 | ||
1747 | /* We expect to receive up-to-date UUIDs soon. | 1774 | /* We expect to receive up-to-date UUIDs soon. |
1748 | To avoid a race in receive_state, free p_uuid while | 1775 | To avoid a race in receive_state, free p_uuid while |
1749 | holding req_lock. I.e. atomic with the state change */ | 1776 | holding req_lock. I.e. atomic with the state change */ |
1750 | kfree(mdev->p_uuid); | 1777 | kfree(device->p_uuid); |
1751 | mdev->p_uuid = NULL; | 1778 | device->p_uuid = NULL; |
1752 | } | 1779 | } |
1753 | 1780 | ||
1754 | rv = _drbd_set_state(mdev, ns, CS_VERBOSE, NULL); | 1781 | rv = _drbd_set_state(device, ns, CS_VERBOSE, NULL); |
1755 | spin_unlock_irq(&mdev->tconn->req_lock); | 1782 | spin_unlock_irq(&device->resource->req_lock); |
1756 | 1783 | ||
1757 | if (rv < SS_SUCCESS) | 1784 | if (rv < SS_SUCCESS) |
1758 | goto force_diskless_dec; | 1785 | goto force_diskless_dec; |
1759 | 1786 | ||
1760 | mod_timer(&mdev->request_timer, jiffies + HZ); | 1787 | mod_timer(&device->request_timer, jiffies + HZ); |
1761 | 1788 | ||
1762 | if (mdev->state.role == R_PRIMARY) | 1789 | if (device->state.role == R_PRIMARY) |
1763 | mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1; | 1790 | device->ldev->md.uuid[UI_CURRENT] |= (u64)1; |
1764 | else | 1791 | else |
1765 | mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; | 1792 | device->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; |
1766 | 1793 | ||
1767 | drbd_md_mark_dirty(mdev); | 1794 | drbd_md_mark_dirty(device); |
1768 | drbd_md_sync(mdev); | 1795 | drbd_md_sync(device); |
1769 | 1796 | ||
1770 | kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE); | 1797 | kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE); |
1771 | put_ldev(mdev); | 1798 | put_ldev(device); |
1772 | conn_reconfig_done(mdev->tconn); | 1799 | conn_reconfig_done(first_peer_device(device)->connection); |
1773 | drbd_adm_finish(info, retcode); | 1800 | drbd_adm_finish(info, retcode); |
1774 | return 0; | 1801 | return 0; |
1775 | 1802 | ||
1776 | force_diskless_dec: | 1803 | force_diskless_dec: |
1777 | put_ldev(mdev); | 1804 | put_ldev(device); |
1778 | force_diskless: | 1805 | force_diskless: |
1779 | drbd_force_state(mdev, NS(disk, D_DISKLESS)); | 1806 | drbd_force_state(device, NS(disk, D_DISKLESS)); |
1780 | drbd_md_sync(mdev); | 1807 | drbd_md_sync(device); |
1781 | fail: | 1808 | fail: |
1782 | conn_reconfig_done(mdev->tconn); | 1809 | conn_reconfig_done(first_peer_device(device)->connection); |
1783 | if (nbc) { | 1810 | if (nbc) { |
1784 | if (nbc->backing_bdev) | 1811 | if (nbc->backing_bdev) |
1785 | blkdev_put(nbc->backing_bdev, | 1812 | blkdev_put(nbc->backing_bdev, |
@@ -1798,26 +1825,26 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) | |||
1798 | return 0; | 1825 | return 0; |
1799 | } | 1826 | } |
1800 | 1827 | ||
1801 | static int adm_detach(struct drbd_conf *mdev, int force) | 1828 | static int adm_detach(struct drbd_device *device, int force) |
1802 | { | 1829 | { |
1803 | enum drbd_state_rv retcode; | 1830 | enum drbd_state_rv retcode; |
1804 | int ret; | 1831 | int ret; |
1805 | 1832 | ||
1806 | if (force) { | 1833 | if (force) { |
1807 | set_bit(FORCE_DETACH, &mdev->flags); | 1834 | set_bit(FORCE_DETACH, &device->flags); |
1808 | drbd_force_state(mdev, NS(disk, D_FAILED)); | 1835 | drbd_force_state(device, NS(disk, D_FAILED)); |
1809 | retcode = SS_SUCCESS; | 1836 | retcode = SS_SUCCESS; |
1810 | goto out; | 1837 | goto out; |
1811 | } | 1838 | } |
1812 | 1839 | ||
1813 | drbd_suspend_io(mdev); /* so no-one is stuck in drbd_al_begin_io */ | 1840 | drbd_suspend_io(device); /* so no-one is stuck in drbd_al_begin_io */ |
1814 | drbd_md_get_buffer(mdev); /* make sure there is no in-flight meta-data IO */ | 1841 | drbd_md_get_buffer(device); /* make sure there is no in-flight meta-data IO */ |
1815 | retcode = drbd_request_state(mdev, NS(disk, D_FAILED)); | 1842 | retcode = drbd_request_state(device, NS(disk, D_FAILED)); |
1816 | drbd_md_put_buffer(mdev); | 1843 | drbd_md_put_buffer(device); |
1817 | /* D_FAILED will transition to DISKLESS. */ | 1844 | /* D_FAILED will transition to DISKLESS. */ |
1818 | ret = wait_event_interruptible(mdev->misc_wait, | 1845 | ret = wait_event_interruptible(device->misc_wait, |
1819 | mdev->state.disk != D_FAILED); | 1846 | device->state.disk != D_FAILED); |
1820 | drbd_resume_io(mdev); | 1847 | drbd_resume_io(device); |
1821 | if ((int)retcode == (int)SS_IS_DISKLESS) | 1848 | if ((int)retcode == (int)SS_IS_DISKLESS) |
1822 | retcode = SS_NOTHING_TO_DO; | 1849 | retcode = SS_NOTHING_TO_DO; |
1823 | if (ret) | 1850 | if (ret) |
@@ -1852,24 +1879,25 @@ int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info) | |||
1852 | } | 1879 | } |
1853 | } | 1880 | } |
1854 | 1881 | ||
1855 | retcode = adm_detach(adm_ctx.mdev, parms.force_detach); | 1882 | retcode = adm_detach(adm_ctx.device, parms.force_detach); |
1856 | out: | 1883 | out: |
1857 | drbd_adm_finish(info, retcode); | 1884 | drbd_adm_finish(info, retcode); |
1858 | return 0; | 1885 | return 0; |
1859 | } | 1886 | } |
1860 | 1887 | ||
1861 | static bool conn_resync_running(struct drbd_tconn *tconn) | 1888 | static bool conn_resync_running(struct drbd_connection *connection) |
1862 | { | 1889 | { |
1863 | struct drbd_conf *mdev; | 1890 | struct drbd_peer_device *peer_device; |
1864 | bool rv = false; | 1891 | bool rv = false; |
1865 | int vnr; | 1892 | int vnr; |
1866 | 1893 | ||
1867 | rcu_read_lock(); | 1894 | rcu_read_lock(); |
1868 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1895 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1869 | if (mdev->state.conn == C_SYNC_SOURCE || | 1896 | struct drbd_device *device = peer_device->device; |
1870 | mdev->state.conn == C_SYNC_TARGET || | 1897 | if (device->state.conn == C_SYNC_SOURCE || |
1871 | mdev->state.conn == C_PAUSED_SYNC_S || | 1898 | device->state.conn == C_SYNC_TARGET || |
1872 | mdev->state.conn == C_PAUSED_SYNC_T) { | 1899 | device->state.conn == C_PAUSED_SYNC_S || |
1900 | device->state.conn == C_PAUSED_SYNC_T) { | ||
1873 | rv = true; | 1901 | rv = true; |
1874 | break; | 1902 | break; |
1875 | } | 1903 | } |
@@ -1879,16 +1907,17 @@ static bool conn_resync_running(struct drbd_tconn *tconn) | |||
1879 | return rv; | 1907 | return rv; |
1880 | } | 1908 | } |
1881 | 1909 | ||
1882 | static bool conn_ov_running(struct drbd_tconn *tconn) | 1910 | static bool conn_ov_running(struct drbd_connection *connection) |
1883 | { | 1911 | { |
1884 | struct drbd_conf *mdev; | 1912 | struct drbd_peer_device *peer_device; |
1885 | bool rv = false; | 1913 | bool rv = false; |
1886 | int vnr; | 1914 | int vnr; |
1887 | 1915 | ||
1888 | rcu_read_lock(); | 1916 | rcu_read_lock(); |
1889 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1917 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1890 | if (mdev->state.conn == C_VERIFY_S || | 1918 | struct drbd_device *device = peer_device->device; |
1891 | mdev->state.conn == C_VERIFY_T) { | 1919 | if (device->state.conn == C_VERIFY_S || |
1920 | device->state.conn == C_VERIFY_T) { | ||
1892 | rv = true; | 1921 | rv = true; |
1893 | break; | 1922 | break; |
1894 | } | 1923 | } |
@@ -1899,63 +1928,65 @@ static bool conn_ov_running(struct drbd_tconn *tconn) | |||
1899 | } | 1928 | } |
1900 | 1929 | ||
1901 | static enum drbd_ret_code | 1930 | static enum drbd_ret_code |
1902 | _check_net_options(struct drbd_tconn *tconn, struct net_conf *old_conf, struct net_conf *new_conf) | 1931 | _check_net_options(struct drbd_connection *connection, struct net_conf *old_net_conf, struct net_conf *new_net_conf) |
1903 | { | 1932 | { |
1904 | struct drbd_conf *mdev; | 1933 | struct drbd_peer_device *peer_device; |
1905 | int i; | 1934 | int i; |
1906 | 1935 | ||
1907 | if (old_conf && tconn->cstate == C_WF_REPORT_PARAMS && tconn->agreed_pro_version < 100) { | 1936 | if (old_net_conf && connection->cstate == C_WF_REPORT_PARAMS && connection->agreed_pro_version < 100) { |
1908 | if (new_conf->wire_protocol != old_conf->wire_protocol) | 1937 | if (new_net_conf->wire_protocol != old_net_conf->wire_protocol) |
1909 | return ERR_NEED_APV_100; | 1938 | return ERR_NEED_APV_100; |
1910 | 1939 | ||
1911 | if (new_conf->two_primaries != old_conf->two_primaries) | 1940 | if (new_net_conf->two_primaries != old_net_conf->two_primaries) |
1912 | return ERR_NEED_APV_100; | 1941 | return ERR_NEED_APV_100; |
1913 | 1942 | ||
1914 | if (strcmp(new_conf->integrity_alg, old_conf->integrity_alg)) | 1943 | if (strcmp(new_net_conf->integrity_alg, old_net_conf->integrity_alg)) |
1915 | return ERR_NEED_APV_100; | 1944 | return ERR_NEED_APV_100; |
1916 | } | 1945 | } |
1917 | 1946 | ||
1918 | if (!new_conf->two_primaries && | 1947 | if (!new_net_conf->two_primaries && |
1919 | conn_highest_role(tconn) == R_PRIMARY && | 1948 | conn_highest_role(connection) == R_PRIMARY && |
1920 | conn_highest_peer(tconn) == R_PRIMARY) | 1949 | conn_highest_peer(connection) == R_PRIMARY) |
1921 | return ERR_NEED_ALLOW_TWO_PRI; | 1950 | return ERR_NEED_ALLOW_TWO_PRI; |
1922 | 1951 | ||
1923 | if (new_conf->two_primaries && | 1952 | if (new_net_conf->two_primaries && |
1924 | (new_conf->wire_protocol != DRBD_PROT_C)) | 1953 | (new_net_conf->wire_protocol != DRBD_PROT_C)) |
1925 | return ERR_NOT_PROTO_C; | 1954 | return ERR_NOT_PROTO_C; |
1926 | 1955 | ||
1927 | idr_for_each_entry(&tconn->volumes, mdev, i) { | 1956 | idr_for_each_entry(&connection->peer_devices, peer_device, i) { |
1928 | if (get_ldev(mdev)) { | 1957 | struct drbd_device *device = peer_device->device; |
1929 | enum drbd_fencing_p fp = rcu_dereference(mdev->ldev->disk_conf)->fencing; | 1958 | if (get_ldev(device)) { |
1930 | put_ldev(mdev); | 1959 | enum drbd_fencing_p fp = rcu_dereference(device->ldev->disk_conf)->fencing; |
1931 | if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) | 1960 | put_ldev(device); |
1961 | if (new_net_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) | ||
1932 | return ERR_STONITH_AND_PROT_A; | 1962 | return ERR_STONITH_AND_PROT_A; |
1933 | } | 1963 | } |
1934 | if (mdev->state.role == R_PRIMARY && new_conf->discard_my_data) | 1964 | if (device->state.role == R_PRIMARY && new_net_conf->discard_my_data) |
1935 | return ERR_DISCARD_IMPOSSIBLE; | 1965 | return ERR_DISCARD_IMPOSSIBLE; |
1936 | } | 1966 | } |
1937 | 1967 | ||
1938 | if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) | 1968 | if (new_net_conf->on_congestion != OC_BLOCK && new_net_conf->wire_protocol != DRBD_PROT_A) |
1939 | return ERR_CONG_NOT_PROTO_A; | 1969 | return ERR_CONG_NOT_PROTO_A; |
1940 | 1970 | ||
1941 | return NO_ERROR; | 1971 | return NO_ERROR; |
1942 | } | 1972 | } |
1943 | 1973 | ||
1944 | static enum drbd_ret_code | 1974 | static enum drbd_ret_code |
1945 | check_net_options(struct drbd_tconn *tconn, struct net_conf *new_conf) | 1975 | check_net_options(struct drbd_connection *connection, struct net_conf *new_net_conf) |
1946 | { | 1976 | { |
1947 | static enum drbd_ret_code rv; | 1977 | static enum drbd_ret_code rv; |
1948 | struct drbd_conf *mdev; | 1978 | struct drbd_peer_device *peer_device; |
1949 | int i; | 1979 | int i; |
1950 | 1980 | ||
1951 | rcu_read_lock(); | 1981 | rcu_read_lock(); |
1952 | rv = _check_net_options(tconn, rcu_dereference(tconn->net_conf), new_conf); | 1982 | rv = _check_net_options(connection, rcu_dereference(connection->net_conf), new_net_conf); |
1953 | rcu_read_unlock(); | 1983 | rcu_read_unlock(); |
1954 | 1984 | ||
1955 | /* tconn->volumes protected by genl_lock() here */ | 1985 | /* connection->volumes protected by genl_lock() here */ |
1956 | idr_for_each_entry(&tconn->volumes, mdev, i) { | 1986 | idr_for_each_entry(&connection->peer_devices, peer_device, i) { |
1957 | if (!mdev->bitmap) { | 1987 | struct drbd_device *device = peer_device->device; |
1958 | if(drbd_bm_init(mdev)) | 1988 | if (!device->bitmap) { |
1989 | if (drbd_bm_init(device)) | ||
1959 | return ERR_NOMEM; | 1990 | return ERR_NOMEM; |
1960 | } | 1991 | } |
1961 | } | 1992 | } |
@@ -1986,26 +2017,26 @@ alloc_hash(struct crypto_hash **tfm, char *tfm_name, int err_alg) | |||
1986 | } | 2017 | } |
1987 | 2018 | ||
1988 | static enum drbd_ret_code | 2019 | static enum drbd_ret_code |
1989 | alloc_crypto(struct crypto *crypto, struct net_conf *new_conf) | 2020 | alloc_crypto(struct crypto *crypto, struct net_conf *new_net_conf) |
1990 | { | 2021 | { |
1991 | char hmac_name[CRYPTO_MAX_ALG_NAME]; | 2022 | char hmac_name[CRYPTO_MAX_ALG_NAME]; |
1992 | enum drbd_ret_code rv; | 2023 | enum drbd_ret_code rv; |
1993 | 2024 | ||
1994 | rv = alloc_hash(&crypto->csums_tfm, new_conf->csums_alg, | 2025 | rv = alloc_hash(&crypto->csums_tfm, new_net_conf->csums_alg, |
1995 | ERR_CSUMS_ALG); | 2026 | ERR_CSUMS_ALG); |
1996 | if (rv != NO_ERROR) | 2027 | if (rv != NO_ERROR) |
1997 | return rv; | 2028 | return rv; |
1998 | rv = alloc_hash(&crypto->verify_tfm, new_conf->verify_alg, | 2029 | rv = alloc_hash(&crypto->verify_tfm, new_net_conf->verify_alg, |
1999 | ERR_VERIFY_ALG); | 2030 | ERR_VERIFY_ALG); |
2000 | if (rv != NO_ERROR) | 2031 | if (rv != NO_ERROR) |
2001 | return rv; | 2032 | return rv; |
2002 | rv = alloc_hash(&crypto->integrity_tfm, new_conf->integrity_alg, | 2033 | rv = alloc_hash(&crypto->integrity_tfm, new_net_conf->integrity_alg, |
2003 | ERR_INTEGRITY_ALG); | 2034 | ERR_INTEGRITY_ALG); |
2004 | if (rv != NO_ERROR) | 2035 | if (rv != NO_ERROR) |
2005 | return rv; | 2036 | return rv; |
2006 | if (new_conf->cram_hmac_alg[0] != 0) { | 2037 | if (new_net_conf->cram_hmac_alg[0] != 0) { |
2007 | snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", | 2038 | snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", |
2008 | new_conf->cram_hmac_alg); | 2039 | new_net_conf->cram_hmac_alg); |
2009 | 2040 | ||
2010 | rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name, | 2041 | rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name, |
2011 | ERR_AUTH_ALG); | 2042 | ERR_AUTH_ALG); |
@@ -2025,8 +2056,8 @@ static void free_crypto(struct crypto *crypto) | |||
2025 | int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) | 2056 | int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) |
2026 | { | 2057 | { |
2027 | enum drbd_ret_code retcode; | 2058 | enum drbd_ret_code retcode; |
2028 | struct drbd_tconn *tconn; | 2059 | struct drbd_connection *connection; |
2029 | struct net_conf *old_conf, *new_conf = NULL; | 2060 | struct net_conf *old_net_conf, *new_net_conf = NULL; |
2030 | int err; | 2061 | int err; |
2031 | int ovr; /* online verify running */ | 2062 | int ovr; /* online verify running */ |
2032 | int rsr; /* re-sync running */ | 2063 | int rsr; /* re-sync running */ |
@@ -2038,98 +2069,103 @@ int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) | |||
2038 | if (retcode != NO_ERROR) | 2069 | if (retcode != NO_ERROR) |
2039 | goto out; | 2070 | goto out; |
2040 | 2071 | ||
2041 | tconn = adm_ctx.tconn; | 2072 | connection = adm_ctx.connection; |
2042 | 2073 | ||
2043 | new_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); | 2074 | new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
2044 | if (!new_conf) { | 2075 | if (!new_net_conf) { |
2045 | retcode = ERR_NOMEM; | 2076 | retcode = ERR_NOMEM; |
2046 | goto out; | 2077 | goto out; |
2047 | } | 2078 | } |
2048 | 2079 | ||
2049 | conn_reconfig_start(tconn); | 2080 | conn_reconfig_start(connection); |
2050 | 2081 | ||
2051 | mutex_lock(&tconn->data.mutex); | 2082 | mutex_lock(&connection->data.mutex); |
2052 | mutex_lock(&tconn->conf_update); | 2083 | mutex_lock(&connection->resource->conf_update); |
2053 | old_conf = tconn->net_conf; | 2084 | old_net_conf = connection->net_conf; |
2054 | 2085 | ||
2055 | if (!old_conf) { | 2086 | if (!old_net_conf) { |
2056 | drbd_msg_put_info("net conf missing, try connect"); | 2087 | drbd_msg_put_info("net conf missing, try connect"); |
2057 | retcode = ERR_INVALID_REQUEST; | 2088 | retcode = ERR_INVALID_REQUEST; |
2058 | goto fail; | 2089 | goto fail; |
2059 | } | 2090 | } |
2060 | 2091 | ||
2061 | *new_conf = *old_conf; | 2092 | *new_net_conf = *old_net_conf; |
2062 | if (should_set_defaults(info)) | 2093 | if (should_set_defaults(info)) |
2063 | set_net_conf_defaults(new_conf); | 2094 | set_net_conf_defaults(new_net_conf); |
2064 | 2095 | ||
2065 | err = net_conf_from_attrs_for_change(new_conf, info); | 2096 | err = net_conf_from_attrs_for_change(new_net_conf, info); |
2066 | if (err && err != -ENOMSG) { | 2097 | if (err && err != -ENOMSG) { |
2067 | retcode = ERR_MANDATORY_TAG; | 2098 | retcode = ERR_MANDATORY_TAG; |
2068 | drbd_msg_put_info(from_attrs_err_to_txt(err)); | 2099 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
2069 | goto fail; | 2100 | goto fail; |
2070 | } | 2101 | } |
2071 | 2102 | ||
2072 | retcode = check_net_options(tconn, new_conf); | 2103 | retcode = check_net_options(connection, new_net_conf); |
2073 | if (retcode != NO_ERROR) | 2104 | if (retcode != NO_ERROR) |
2074 | goto fail; | 2105 | goto fail; |
2075 | 2106 | ||
2076 | /* re-sync running */ | 2107 | /* re-sync running */ |
2077 | rsr = conn_resync_running(tconn); | 2108 | rsr = conn_resync_running(connection); |
2078 | if (rsr && strcmp(new_conf->csums_alg, old_conf->csums_alg)) { | 2109 | if (rsr && strcmp(new_net_conf->csums_alg, old_net_conf->csums_alg)) { |
2079 | retcode = ERR_CSUMS_RESYNC_RUNNING; | 2110 | retcode = ERR_CSUMS_RESYNC_RUNNING; |
2080 | goto fail; | 2111 | goto fail; |
2081 | } | 2112 | } |
2082 | 2113 | ||
2083 | /* online verify running */ | 2114 | /* online verify running */ |
2084 | ovr = conn_ov_running(tconn); | 2115 | ovr = conn_ov_running(connection); |
2085 | if (ovr && strcmp(new_conf->verify_alg, old_conf->verify_alg)) { | 2116 | if (ovr && strcmp(new_net_conf->verify_alg, old_net_conf->verify_alg)) { |
2086 | retcode = ERR_VERIFY_RUNNING; | 2117 | retcode = ERR_VERIFY_RUNNING; |
2087 | goto fail; | 2118 | goto fail; |
2088 | } | 2119 | } |
2089 | 2120 | ||
2090 | retcode = alloc_crypto(&crypto, new_conf); | 2121 | retcode = alloc_crypto(&crypto, new_net_conf); |
2091 | if (retcode != NO_ERROR) | 2122 | if (retcode != NO_ERROR) |
2092 | goto fail; | 2123 | goto fail; |
2093 | 2124 | ||
2094 | rcu_assign_pointer(tconn->net_conf, new_conf); | 2125 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
2095 | 2126 | ||
2096 | if (!rsr) { | 2127 | if (!rsr) { |
2097 | crypto_free_hash(tconn->csums_tfm); | 2128 | crypto_free_hash(connection->csums_tfm); |
2098 | tconn->csums_tfm = crypto.csums_tfm; | 2129 | connection->csums_tfm = crypto.csums_tfm; |
2099 | crypto.csums_tfm = NULL; | 2130 | crypto.csums_tfm = NULL; |
2100 | } | 2131 | } |
2101 | if (!ovr) { | 2132 | if (!ovr) { |
2102 | crypto_free_hash(tconn->verify_tfm); | 2133 | crypto_free_hash(connection->verify_tfm); |
2103 | tconn->verify_tfm = crypto.verify_tfm; | 2134 | connection->verify_tfm = crypto.verify_tfm; |
2104 | crypto.verify_tfm = NULL; | 2135 | crypto.verify_tfm = NULL; |
2105 | } | 2136 | } |
2106 | 2137 | ||
2107 | crypto_free_hash(tconn->integrity_tfm); | 2138 | crypto_free_hash(connection->integrity_tfm); |
2108 | tconn->integrity_tfm = crypto.integrity_tfm; | 2139 | connection->integrity_tfm = crypto.integrity_tfm; |
2109 | if (tconn->cstate >= C_WF_REPORT_PARAMS && tconn->agreed_pro_version >= 100) | 2140 | if (connection->cstate >= C_WF_REPORT_PARAMS && connection->agreed_pro_version >= 100) |
2110 | /* Do this without trying to take tconn->data.mutex again. */ | 2141 | /* Do this without trying to take connection->data.mutex again. */ |
2111 | __drbd_send_protocol(tconn, P_PROTOCOL_UPDATE); | 2142 | __drbd_send_protocol(connection, P_PROTOCOL_UPDATE); |
2112 | 2143 | ||
2113 | crypto_free_hash(tconn->cram_hmac_tfm); | 2144 | crypto_free_hash(connection->cram_hmac_tfm); |
2114 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; | 2145 | connection->cram_hmac_tfm = crypto.cram_hmac_tfm; |
2115 | 2146 | ||
2116 | mutex_unlock(&tconn->conf_update); | 2147 | mutex_unlock(&connection->resource->conf_update); |
2117 | mutex_unlock(&tconn->data.mutex); | 2148 | mutex_unlock(&connection->data.mutex); |
2118 | synchronize_rcu(); | 2149 | synchronize_rcu(); |
2119 | kfree(old_conf); | 2150 | kfree(old_net_conf); |
2151 | |||
2152 | if (connection->cstate >= C_WF_REPORT_PARAMS) { | ||
2153 | struct drbd_peer_device *peer_device; | ||
2154 | int vnr; | ||
2120 | 2155 | ||
2121 | if (tconn->cstate >= C_WF_REPORT_PARAMS) | 2156 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
2122 | drbd_send_sync_param(minor_to_mdev(conn_lowest_minor(tconn))); | 2157 | drbd_send_sync_param(peer_device); |
2158 | } | ||
2123 | 2159 | ||
2124 | goto done; | 2160 | goto done; |
2125 | 2161 | ||
2126 | fail: | 2162 | fail: |
2127 | mutex_unlock(&tconn->conf_update); | 2163 | mutex_unlock(&connection->resource->conf_update); |
2128 | mutex_unlock(&tconn->data.mutex); | 2164 | mutex_unlock(&connection->data.mutex); |
2129 | free_crypto(&crypto); | 2165 | free_crypto(&crypto); |
2130 | kfree(new_conf); | 2166 | kfree(new_net_conf); |
2131 | done: | 2167 | done: |
2132 | conn_reconfig_done(tconn); | 2168 | conn_reconfig_done(connection); |
2133 | out: | 2169 | out: |
2134 | drbd_adm_finish(info, retcode); | 2170 | drbd_adm_finish(info, retcode); |
2135 | return 0; | 2171 | return 0; |
@@ -2137,10 +2173,11 @@ int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) | |||
2137 | 2173 | ||
2138 | int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info) | 2174 | int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info) |
2139 | { | 2175 | { |
2140 | struct drbd_conf *mdev; | 2176 | struct drbd_peer_device *peer_device; |
2141 | struct net_conf *old_conf, *new_conf = NULL; | 2177 | struct net_conf *old_net_conf, *new_net_conf = NULL; |
2142 | struct crypto crypto = { }; | 2178 | struct crypto crypto = { }; |
2143 | struct drbd_tconn *tconn; | 2179 | struct drbd_resource *resource; |
2180 | struct drbd_connection *connection; | ||
2144 | enum drbd_ret_code retcode; | 2181 | enum drbd_ret_code retcode; |
2145 | int i; | 2182 | int i; |
2146 | int err; | 2183 | int err; |
@@ -2160,106 +2197,111 @@ int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info) | |||
2160 | /* No need for _rcu here. All reconfiguration is | 2197 | /* No need for _rcu here. All reconfiguration is |
2161 | * strictly serialized on genl_lock(). We are protected against | 2198 | * strictly serialized on genl_lock(). We are protected against |
2162 | * concurrent reconfiguration/addition/deletion */ | 2199 | * concurrent reconfiguration/addition/deletion */ |
2163 | list_for_each_entry(tconn, &drbd_tconns, all_tconn) { | 2200 | for_each_resource(resource, &drbd_resources) { |
2164 | if (nla_len(adm_ctx.my_addr) == tconn->my_addr_len && | 2201 | for_each_connection(connection, resource) { |
2165 | !memcmp(nla_data(adm_ctx.my_addr), &tconn->my_addr, tconn->my_addr_len)) { | 2202 | if (nla_len(adm_ctx.my_addr) == connection->my_addr_len && |
2166 | retcode = ERR_LOCAL_ADDR; | 2203 | !memcmp(nla_data(adm_ctx.my_addr), &connection->my_addr, |
2167 | goto out; | 2204 | connection->my_addr_len)) { |
2168 | } | 2205 | retcode = ERR_LOCAL_ADDR; |
2206 | goto out; | ||
2207 | } | ||
2169 | 2208 | ||
2170 | if (nla_len(adm_ctx.peer_addr) == tconn->peer_addr_len && | 2209 | if (nla_len(adm_ctx.peer_addr) == connection->peer_addr_len && |
2171 | !memcmp(nla_data(adm_ctx.peer_addr), &tconn->peer_addr, tconn->peer_addr_len)) { | 2210 | !memcmp(nla_data(adm_ctx.peer_addr), &connection->peer_addr, |
2172 | retcode = ERR_PEER_ADDR; | 2211 | connection->peer_addr_len)) { |
2173 | goto out; | 2212 | retcode = ERR_PEER_ADDR; |
2213 | goto out; | ||
2214 | } | ||
2174 | } | 2215 | } |
2175 | } | 2216 | } |
2176 | 2217 | ||
2177 | tconn = adm_ctx.tconn; | 2218 | connection = first_connection(adm_ctx.resource); |
2178 | conn_reconfig_start(tconn); | 2219 | conn_reconfig_start(connection); |
2179 | 2220 | ||
2180 | if (tconn->cstate > C_STANDALONE) { | 2221 | if (connection->cstate > C_STANDALONE) { |
2181 | retcode = ERR_NET_CONFIGURED; | 2222 | retcode = ERR_NET_CONFIGURED; |
2182 | goto fail; | 2223 | goto fail; |
2183 | } | 2224 | } |
2184 | 2225 | ||
2185 | /* allocation not in the IO path, drbdsetup / netlink process context */ | 2226 | /* allocation not in the IO path, drbdsetup / netlink process context */ |
2186 | new_conf = kzalloc(sizeof(*new_conf), GFP_KERNEL); | 2227 | new_net_conf = kzalloc(sizeof(*new_net_conf), GFP_KERNEL); |
2187 | if (!new_conf) { | 2228 | if (!new_net_conf) { |
2188 | retcode = ERR_NOMEM; | 2229 | retcode = ERR_NOMEM; |
2189 | goto fail; | 2230 | goto fail; |
2190 | } | 2231 | } |
2191 | 2232 | ||
2192 | set_net_conf_defaults(new_conf); | 2233 | set_net_conf_defaults(new_net_conf); |
2193 | 2234 | ||
2194 | err = net_conf_from_attrs(new_conf, info); | 2235 | err = net_conf_from_attrs(new_net_conf, info); |
2195 | if (err && err != -ENOMSG) { | 2236 | if (err && err != -ENOMSG) { |
2196 | retcode = ERR_MANDATORY_TAG; | 2237 | retcode = ERR_MANDATORY_TAG; |
2197 | drbd_msg_put_info(from_attrs_err_to_txt(err)); | 2238 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
2198 | goto fail; | 2239 | goto fail; |
2199 | } | 2240 | } |
2200 | 2241 | ||
2201 | retcode = check_net_options(tconn, new_conf); | 2242 | retcode = check_net_options(connection, new_net_conf); |
2202 | if (retcode != NO_ERROR) | 2243 | if (retcode != NO_ERROR) |
2203 | goto fail; | 2244 | goto fail; |
2204 | 2245 | ||
2205 | retcode = alloc_crypto(&crypto, new_conf); | 2246 | retcode = alloc_crypto(&crypto, new_net_conf); |
2206 | if (retcode != NO_ERROR) | 2247 | if (retcode != NO_ERROR) |
2207 | goto fail; | 2248 | goto fail; |
2208 | 2249 | ||
2209 | ((char *)new_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0; | 2250 | ((char *)new_net_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0; |
2210 | 2251 | ||
2211 | conn_flush_workqueue(tconn); | 2252 | drbd_flush_workqueue(&connection->sender_work); |
2212 | 2253 | ||
2213 | mutex_lock(&tconn->conf_update); | 2254 | mutex_lock(&adm_ctx.resource->conf_update); |
2214 | old_conf = tconn->net_conf; | 2255 | old_net_conf = connection->net_conf; |
2215 | if (old_conf) { | 2256 | if (old_net_conf) { |
2216 | retcode = ERR_NET_CONFIGURED; | 2257 | retcode = ERR_NET_CONFIGURED; |
2217 | mutex_unlock(&tconn->conf_update); | 2258 | mutex_unlock(&adm_ctx.resource->conf_update); |
2218 | goto fail; | 2259 | goto fail; |
2219 | } | 2260 | } |
2220 | rcu_assign_pointer(tconn->net_conf, new_conf); | 2261 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
2221 | 2262 | ||
2222 | conn_free_crypto(tconn); | 2263 | conn_free_crypto(connection); |
2223 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; | 2264 | connection->cram_hmac_tfm = crypto.cram_hmac_tfm; |
2224 | tconn->integrity_tfm = crypto.integrity_tfm; | 2265 | connection->integrity_tfm = crypto.integrity_tfm; |
2225 | tconn->csums_tfm = crypto.csums_tfm; | 2266 | connection->csums_tfm = crypto.csums_tfm; |
2226 | tconn->verify_tfm = crypto.verify_tfm; | 2267 | connection->verify_tfm = crypto.verify_tfm; |
2227 | 2268 | ||
2228 | tconn->my_addr_len = nla_len(adm_ctx.my_addr); | 2269 | connection->my_addr_len = nla_len(adm_ctx.my_addr); |
2229 | memcpy(&tconn->my_addr, nla_data(adm_ctx.my_addr), tconn->my_addr_len); | 2270 | memcpy(&connection->my_addr, nla_data(adm_ctx.my_addr), connection->my_addr_len); |
2230 | tconn->peer_addr_len = nla_len(adm_ctx.peer_addr); | 2271 | connection->peer_addr_len = nla_len(adm_ctx.peer_addr); |
2231 | memcpy(&tconn->peer_addr, nla_data(adm_ctx.peer_addr), tconn->peer_addr_len); | 2272 | memcpy(&connection->peer_addr, nla_data(adm_ctx.peer_addr), connection->peer_addr_len); |
2232 | 2273 | ||
2233 | mutex_unlock(&tconn->conf_update); | 2274 | mutex_unlock(&adm_ctx.resource->conf_update); |
2234 | 2275 | ||
2235 | rcu_read_lock(); | 2276 | rcu_read_lock(); |
2236 | idr_for_each_entry(&tconn->volumes, mdev, i) { | 2277 | idr_for_each_entry(&connection->peer_devices, peer_device, i) { |
2237 | mdev->send_cnt = 0; | 2278 | struct drbd_device *device = peer_device->device; |
2238 | mdev->recv_cnt = 0; | 2279 | device->send_cnt = 0; |
2280 | device->recv_cnt = 0; | ||
2239 | } | 2281 | } |
2240 | rcu_read_unlock(); | 2282 | rcu_read_unlock(); |
2241 | 2283 | ||
2242 | retcode = conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); | 2284 | retcode = conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
2243 | 2285 | ||
2244 | conn_reconfig_done(tconn); | 2286 | conn_reconfig_done(connection); |
2245 | drbd_adm_finish(info, retcode); | 2287 | drbd_adm_finish(info, retcode); |
2246 | return 0; | 2288 | return 0; |
2247 | 2289 | ||
2248 | fail: | 2290 | fail: |
2249 | free_crypto(&crypto); | 2291 | free_crypto(&crypto); |
2250 | kfree(new_conf); | 2292 | kfree(new_net_conf); |
2251 | 2293 | ||
2252 | conn_reconfig_done(tconn); | 2294 | conn_reconfig_done(connection); |
2253 | out: | 2295 | out: |
2254 | drbd_adm_finish(info, retcode); | 2296 | drbd_adm_finish(info, retcode); |
2255 | return 0; | 2297 | return 0; |
2256 | } | 2298 | } |
2257 | 2299 | ||
2258 | static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool force) | 2300 | static enum drbd_state_rv conn_try_disconnect(struct drbd_connection *connection, bool force) |
2259 | { | 2301 | { |
2260 | enum drbd_state_rv rv; | 2302 | enum drbd_state_rv rv; |
2261 | 2303 | ||
2262 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), | 2304 | rv = conn_request_state(connection, NS(conn, C_DISCONNECTING), |
2263 | force ? CS_HARD : 0); | 2305 | force ? CS_HARD : 0); |
2264 | 2306 | ||
2265 | switch (rv) { | 2307 | switch (rv) { |
@@ -2269,18 +2311,18 @@ static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool for | |||
2269 | return SS_SUCCESS; | 2311 | return SS_SUCCESS; |
2270 | case SS_PRIMARY_NOP: | 2312 | case SS_PRIMARY_NOP: |
2271 | /* Our state checking code wants to see the peer outdated. */ | 2313 | /* Our state checking code wants to see the peer outdated. */ |
2272 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, pdsk, D_OUTDATED), 0); | 2314 | rv = conn_request_state(connection, NS2(conn, C_DISCONNECTING, pdsk, D_OUTDATED), 0); |
2273 | 2315 | ||
2274 | if (rv == SS_OUTDATE_WO_CONN) /* lost connection before graceful disconnect succeeded */ | 2316 | if (rv == SS_OUTDATE_WO_CONN) /* lost connection before graceful disconnect succeeded */ |
2275 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_VERBOSE); | 2317 | rv = conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_VERBOSE); |
2276 | 2318 | ||
2277 | break; | 2319 | break; |
2278 | case SS_CW_FAILED_BY_PEER: | 2320 | case SS_CW_FAILED_BY_PEER: |
2279 | /* The peer probably wants to see us outdated. */ | 2321 | /* The peer probably wants to see us outdated. */ |
2280 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, | 2322 | rv = conn_request_state(connection, NS2(conn, C_DISCONNECTING, |
2281 | disk, D_OUTDATED), 0); | 2323 | disk, D_OUTDATED), 0); |
2282 | if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) { | 2324 | if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) { |
2283 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), | 2325 | rv = conn_request_state(connection, NS(conn, C_DISCONNECTING), |
2284 | CS_HARD); | 2326 | CS_HARD); |
2285 | } | 2327 | } |
2286 | break; | 2328 | break; |
@@ -2294,18 +2336,18 @@ static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool for | |||
2294 | * The state handling only uses drbd_thread_stop_nowait(), | 2336 | * The state handling only uses drbd_thread_stop_nowait(), |
2295 | * we want to really wait here until the receiver is no more. | 2337 | * we want to really wait here until the receiver is no more. |
2296 | */ | 2338 | */ |
2297 | drbd_thread_stop(&adm_ctx.tconn->receiver); | 2339 | drbd_thread_stop(&connection->receiver); |
2298 | 2340 | ||
2299 | /* Race breaker. This additional state change request may be | 2341 | /* Race breaker. This additional state change request may be |
2300 | * necessary, if this was a forced disconnect during a receiver | 2342 | * necessary, if this was a forced disconnect during a receiver |
2301 | * restart. We may have "killed" the receiver thread just | 2343 | * restart. We may have "killed" the receiver thread just |
2302 | * after drbdd_init() returned. Typically, we should be | 2344 | * after drbd_receiver() returned. Typically, we should be |
2303 | * C_STANDALONE already, now, and this becomes a no-op. | 2345 | * C_STANDALONE already, now, and this becomes a no-op. |
2304 | */ | 2346 | */ |
2305 | rv2 = conn_request_state(tconn, NS(conn, C_STANDALONE), | 2347 | rv2 = conn_request_state(connection, NS(conn, C_STANDALONE), |
2306 | CS_VERBOSE | CS_HARD); | 2348 | CS_VERBOSE | CS_HARD); |
2307 | if (rv2 < SS_SUCCESS) | 2349 | if (rv2 < SS_SUCCESS) |
2308 | conn_err(tconn, | 2350 | drbd_err(connection, |
2309 | "unexpected rv2=%d in conn_try_disconnect()\n", | 2351 | "unexpected rv2=%d in conn_try_disconnect()\n", |
2310 | rv2); | 2352 | rv2); |
2311 | } | 2353 | } |
@@ -2315,7 +2357,7 @@ static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool for | |||
2315 | int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) | 2357 | int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) |
2316 | { | 2358 | { |
2317 | struct disconnect_parms parms; | 2359 | struct disconnect_parms parms; |
2318 | struct drbd_tconn *tconn; | 2360 | struct drbd_connection *connection; |
2319 | enum drbd_state_rv rv; | 2361 | enum drbd_state_rv rv; |
2320 | enum drbd_ret_code retcode; | 2362 | enum drbd_ret_code retcode; |
2321 | int err; | 2363 | int err; |
@@ -2326,7 +2368,7 @@ int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) | |||
2326 | if (retcode != NO_ERROR) | 2368 | if (retcode != NO_ERROR) |
2327 | goto fail; | 2369 | goto fail; |
2328 | 2370 | ||
2329 | tconn = adm_ctx.tconn; | 2371 | connection = adm_ctx.connection; |
2330 | memset(&parms, 0, sizeof(parms)); | 2372 | memset(&parms, 0, sizeof(parms)); |
2331 | if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) { | 2373 | if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) { |
2332 | err = disconnect_parms_from_attrs(&parms, info); | 2374 | err = disconnect_parms_from_attrs(&parms, info); |
@@ -2337,7 +2379,7 @@ int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) | |||
2337 | } | 2379 | } |
2338 | } | 2380 | } |
2339 | 2381 | ||
2340 | rv = conn_try_disconnect(tconn, parms.force_disconnect); | 2382 | rv = conn_try_disconnect(connection, parms.force_disconnect); |
2341 | if (rv < SS_SUCCESS) | 2383 | if (rv < SS_SUCCESS) |
2342 | retcode = rv; /* FIXME: Type mismatch. */ | 2384 | retcode = rv; /* FIXME: Type mismatch. */ |
2343 | else | 2385 | else |
@@ -2347,27 +2389,27 @@ int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) | |||
2347 | return 0; | 2389 | return 0; |
2348 | } | 2390 | } |
2349 | 2391 | ||
2350 | void resync_after_online_grow(struct drbd_conf *mdev) | 2392 | void resync_after_online_grow(struct drbd_device *device) |
2351 | { | 2393 | { |
2352 | int iass; /* I am sync source */ | 2394 | int iass; /* I am sync source */ |
2353 | 2395 | ||
2354 | dev_info(DEV, "Resync of new storage after online grow\n"); | 2396 | drbd_info(device, "Resync of new storage after online grow\n"); |
2355 | if (mdev->state.role != mdev->state.peer) | 2397 | if (device->state.role != device->state.peer) |
2356 | iass = (mdev->state.role == R_PRIMARY); | 2398 | iass = (device->state.role == R_PRIMARY); |
2357 | else | 2399 | else |
2358 | iass = test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags); | 2400 | iass = test_bit(RESOLVE_CONFLICTS, &first_peer_device(device)->connection->flags); |
2359 | 2401 | ||
2360 | if (iass) | 2402 | if (iass) |
2361 | drbd_start_resync(mdev, C_SYNC_SOURCE); | 2403 | drbd_start_resync(device, C_SYNC_SOURCE); |
2362 | else | 2404 | else |
2363 | _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE); | 2405 | _drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE); |
2364 | } | 2406 | } |
2365 | 2407 | ||
2366 | int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | 2408 | int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) |
2367 | { | 2409 | { |
2368 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; | 2410 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; |
2369 | struct resize_parms rs; | 2411 | struct resize_parms rs; |
2370 | struct drbd_conf *mdev; | 2412 | struct drbd_device *device; |
2371 | enum drbd_ret_code retcode; | 2413 | enum drbd_ret_code retcode; |
2372 | enum determine_dev_size dd; | 2414 | enum determine_dev_size dd; |
2373 | bool change_al_layout = false; | 2415 | bool change_al_layout = false; |
@@ -2381,15 +2423,15 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2381 | if (retcode != NO_ERROR) | 2423 | if (retcode != NO_ERROR) |
2382 | goto fail; | 2424 | goto fail; |
2383 | 2425 | ||
2384 | mdev = adm_ctx.mdev; | 2426 | device = adm_ctx.device; |
2385 | if (!get_ldev(mdev)) { | 2427 | if (!get_ldev(device)) { |
2386 | retcode = ERR_NO_DISK; | 2428 | retcode = ERR_NO_DISK; |
2387 | goto fail; | 2429 | goto fail; |
2388 | } | 2430 | } |
2389 | 2431 | ||
2390 | memset(&rs, 0, sizeof(struct resize_parms)); | 2432 | memset(&rs, 0, sizeof(struct resize_parms)); |
2391 | rs.al_stripes = mdev->ldev->md.al_stripes; | 2433 | rs.al_stripes = device->ldev->md.al_stripes; |
2392 | rs.al_stripe_size = mdev->ldev->md.al_stripe_size_4k * 4; | 2434 | rs.al_stripe_size = device->ldev->md.al_stripe_size_4k * 4; |
2393 | if (info->attrs[DRBD_NLA_RESIZE_PARMS]) { | 2435 | if (info->attrs[DRBD_NLA_RESIZE_PARMS]) { |
2394 | err = resize_parms_from_attrs(&rs, info); | 2436 | err = resize_parms_from_attrs(&rs, info); |
2395 | if (err) { | 2437 | if (err) { |
@@ -2399,24 +2441,24 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2399 | } | 2441 | } |
2400 | } | 2442 | } |
2401 | 2443 | ||
2402 | if (mdev->state.conn > C_CONNECTED) { | 2444 | if (device->state.conn > C_CONNECTED) { |
2403 | retcode = ERR_RESIZE_RESYNC; | 2445 | retcode = ERR_RESIZE_RESYNC; |
2404 | goto fail_ldev; | 2446 | goto fail_ldev; |
2405 | } | 2447 | } |
2406 | 2448 | ||
2407 | if (mdev->state.role == R_SECONDARY && | 2449 | if (device->state.role == R_SECONDARY && |
2408 | mdev->state.peer == R_SECONDARY) { | 2450 | device->state.peer == R_SECONDARY) { |
2409 | retcode = ERR_NO_PRIMARY; | 2451 | retcode = ERR_NO_PRIMARY; |
2410 | goto fail_ldev; | 2452 | goto fail_ldev; |
2411 | } | 2453 | } |
2412 | 2454 | ||
2413 | if (rs.no_resync && mdev->tconn->agreed_pro_version < 93) { | 2455 | if (rs.no_resync && first_peer_device(device)->connection->agreed_pro_version < 93) { |
2414 | retcode = ERR_NEED_APV_93; | 2456 | retcode = ERR_NEED_APV_93; |
2415 | goto fail_ldev; | 2457 | goto fail_ldev; |
2416 | } | 2458 | } |
2417 | 2459 | ||
2418 | rcu_read_lock(); | 2460 | rcu_read_lock(); |
2419 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; | 2461 | u_size = rcu_dereference(device->ldev->disk_conf)->disk_size; |
2420 | rcu_read_unlock(); | 2462 | rcu_read_unlock(); |
2421 | if (u_size != (sector_t)rs.resize_size) { | 2463 | if (u_size != (sector_t)rs.resize_size) { |
2422 | new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL); | 2464 | new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL); |
@@ -2426,8 +2468,8 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2426 | } | 2468 | } |
2427 | } | 2469 | } |
2428 | 2470 | ||
2429 | if (mdev->ldev->md.al_stripes != rs.al_stripes || | 2471 | if (device->ldev->md.al_stripes != rs.al_stripes || |
2430 | mdev->ldev->md.al_stripe_size_4k != rs.al_stripe_size / 4) { | 2472 | device->ldev->md.al_stripe_size_4k != rs.al_stripe_size / 4) { |
2431 | u32 al_size_k = rs.al_stripes * rs.al_stripe_size; | 2473 | u32 al_size_k = rs.al_stripes * rs.al_stripe_size; |
2432 | 2474 | ||
2433 | if (al_size_k > (16 * 1024 * 1024)) { | 2475 | if (al_size_k > (16 * 1024 * 1024)) { |
@@ -2440,7 +2482,7 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2440 | goto fail_ldev; | 2482 | goto fail_ldev; |
2441 | } | 2483 | } |
2442 | 2484 | ||
2443 | if (mdev->state.conn != C_CONNECTED) { | 2485 | if (device->state.conn != C_CONNECTED) { |
2444 | retcode = ERR_MD_LAYOUT_CONNECTED; | 2486 | retcode = ERR_MD_LAYOUT_CONNECTED; |
2445 | goto fail_ldev; | 2487 | goto fail_ldev; |
2446 | } | 2488 | } |
@@ -2448,24 +2490,24 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2448 | change_al_layout = true; | 2490 | change_al_layout = true; |
2449 | } | 2491 | } |
2450 | 2492 | ||
2451 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) | 2493 | if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev)) |
2452 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); | 2494 | device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev); |
2453 | 2495 | ||
2454 | if (new_disk_conf) { | 2496 | if (new_disk_conf) { |
2455 | mutex_lock(&mdev->tconn->conf_update); | 2497 | mutex_lock(&device->resource->conf_update); |
2456 | old_disk_conf = mdev->ldev->disk_conf; | 2498 | old_disk_conf = device->ldev->disk_conf; |
2457 | *new_disk_conf = *old_disk_conf; | 2499 | *new_disk_conf = *old_disk_conf; |
2458 | new_disk_conf->disk_size = (sector_t)rs.resize_size; | 2500 | new_disk_conf->disk_size = (sector_t)rs.resize_size; |
2459 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); | 2501 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
2460 | mutex_unlock(&mdev->tconn->conf_update); | 2502 | mutex_unlock(&device->resource->conf_update); |
2461 | synchronize_rcu(); | 2503 | synchronize_rcu(); |
2462 | kfree(old_disk_conf); | 2504 | kfree(old_disk_conf); |
2463 | } | 2505 | } |
2464 | 2506 | ||
2465 | ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0); | 2507 | ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0); |
2466 | dd = drbd_determine_dev_size(mdev, ddsf, change_al_layout ? &rs : NULL); | 2508 | dd = drbd_determine_dev_size(device, ddsf, change_al_layout ? &rs : NULL); |
2467 | drbd_md_sync(mdev); | 2509 | drbd_md_sync(device); |
2468 | put_ldev(mdev); | 2510 | put_ldev(device); |
2469 | if (dd == DS_ERROR) { | 2511 | if (dd == DS_ERROR) { |
2470 | retcode = ERR_NOMEM_BITMAP; | 2512 | retcode = ERR_NOMEM_BITMAP; |
2471 | goto fail; | 2513 | goto fail; |
@@ -2477,12 +2519,12 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2477 | goto fail; | 2519 | goto fail; |
2478 | } | 2520 | } |
2479 | 2521 | ||
2480 | if (mdev->state.conn == C_CONNECTED) { | 2522 | if (device->state.conn == C_CONNECTED) { |
2481 | if (dd == DS_GREW) | 2523 | if (dd == DS_GREW) |
2482 | set_bit(RESIZE_PENDING, &mdev->flags); | 2524 | set_bit(RESIZE_PENDING, &device->flags); |
2483 | 2525 | ||
2484 | drbd_send_uuids(mdev); | 2526 | drbd_send_uuids(first_peer_device(device)); |
2485 | drbd_send_sizes(mdev, 1, ddsf); | 2527 | drbd_send_sizes(first_peer_device(device), 1, ddsf); |
2486 | } | 2528 | } |
2487 | 2529 | ||
2488 | fail: | 2530 | fail: |
@@ -2490,14 +2532,13 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) | |||
2490 | return 0; | 2532 | return 0; |
2491 | 2533 | ||
2492 | fail_ldev: | 2534 | fail_ldev: |
2493 | put_ldev(mdev); | 2535 | put_ldev(device); |
2494 | goto fail; | 2536 | goto fail; |
2495 | } | 2537 | } |
2496 | 2538 | ||
2497 | int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info) | 2539 | int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info) |
2498 | { | 2540 | { |
2499 | enum drbd_ret_code retcode; | 2541 | enum drbd_ret_code retcode; |
2500 | struct drbd_tconn *tconn; | ||
2501 | struct res_opts res_opts; | 2542 | struct res_opts res_opts; |
2502 | int err; | 2543 | int err; |
2503 | 2544 | ||
@@ -2506,9 +2547,8 @@ int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info) | |||
2506 | return retcode; | 2547 | return retcode; |
2507 | if (retcode != NO_ERROR) | 2548 | if (retcode != NO_ERROR) |
2508 | goto fail; | 2549 | goto fail; |
2509 | tconn = adm_ctx.tconn; | ||
2510 | 2550 | ||
2511 | res_opts = tconn->res_opts; | 2551 | res_opts = adm_ctx.resource->res_opts; |
2512 | if (should_set_defaults(info)) | 2552 | if (should_set_defaults(info)) |
2513 | set_res_opts_defaults(&res_opts); | 2553 | set_res_opts_defaults(&res_opts); |
2514 | 2554 | ||
@@ -2519,7 +2559,7 @@ int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info) | |||
2519 | goto fail; | 2559 | goto fail; |
2520 | } | 2560 | } |
2521 | 2561 | ||
2522 | err = set_resource_options(tconn, &res_opts); | 2562 | err = set_resource_options(adm_ctx.resource, &res_opts); |
2523 | if (err) { | 2563 | if (err) { |
2524 | retcode = ERR_INVALID_REQUEST; | 2564 | retcode = ERR_INVALID_REQUEST; |
2525 | if (err == -ENOMEM) | 2565 | if (err == -ENOMEM) |
@@ -2533,7 +2573,7 @@ fail: | |||
2533 | 2573 | ||
2534 | int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) | 2574 | int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) |
2535 | { | 2575 | { |
2536 | struct drbd_conf *mdev; | 2576 | struct drbd_device *device; |
2537 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ | 2577 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
2538 | 2578 | ||
2539 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); | 2579 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
@@ -2542,29 +2582,29 @@ int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) | |||
2542 | if (retcode != NO_ERROR) | 2582 | if (retcode != NO_ERROR) |
2543 | goto out; | 2583 | goto out; |
2544 | 2584 | ||
2545 | mdev = adm_ctx.mdev; | 2585 | device = adm_ctx.device; |
2546 | 2586 | ||
2547 | /* If there is still bitmap IO pending, probably because of a previous | 2587 | /* If there is still bitmap IO pending, probably because of a previous |
2548 | * resync just being finished, wait for it before requesting a new resync. | 2588 | * resync just being finished, wait for it before requesting a new resync. |
2549 | * Also wait for it's after_state_ch(). */ | 2589 | * Also wait for it's after_state_ch(). */ |
2550 | drbd_suspend_io(mdev); | 2590 | drbd_suspend_io(device); |
2551 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); | 2591 | wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags)); |
2552 | drbd_flush_workqueue(mdev); | 2592 | drbd_flush_workqueue(&first_peer_device(device)->connection->sender_work); |
2553 | 2593 | ||
2554 | /* If we happen to be C_STANDALONE R_SECONDARY, just change to | 2594 | /* If we happen to be C_STANDALONE R_SECONDARY, just change to |
2555 | * D_INCONSISTENT, and set all bits in the bitmap. Otherwise, | 2595 | * D_INCONSISTENT, and set all bits in the bitmap. Otherwise, |
2556 | * try to start a resync handshake as sync target for full sync. | 2596 | * try to start a resync handshake as sync target for full sync. |
2557 | */ | 2597 | */ |
2558 | if (mdev->state.conn == C_STANDALONE && mdev->state.role == R_SECONDARY) { | 2598 | if (device->state.conn == C_STANDALONE && device->state.role == R_SECONDARY) { |
2559 | retcode = drbd_request_state(mdev, NS(disk, D_INCONSISTENT)); | 2599 | retcode = drbd_request_state(device, NS(disk, D_INCONSISTENT)); |
2560 | if (retcode >= SS_SUCCESS) { | 2600 | if (retcode >= SS_SUCCESS) { |
2561 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, | 2601 | if (drbd_bitmap_io(device, &drbd_bmio_set_n_write, |
2562 | "set_n_write from invalidate", BM_LOCKED_MASK)) | 2602 | "set_n_write from invalidate", BM_LOCKED_MASK)) |
2563 | retcode = ERR_IO_MD_DISK; | 2603 | retcode = ERR_IO_MD_DISK; |
2564 | } | 2604 | } |
2565 | } else | 2605 | } else |
2566 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T)); | 2606 | retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_T)); |
2567 | drbd_resume_io(mdev); | 2607 | drbd_resume_io(device); |
2568 | 2608 | ||
2569 | out: | 2609 | out: |
2570 | drbd_adm_finish(info, retcode); | 2610 | drbd_adm_finish(info, retcode); |
@@ -2582,25 +2622,25 @@ static int drbd_adm_simple_request_state(struct sk_buff *skb, struct genl_info * | |||
2582 | if (retcode != NO_ERROR) | 2622 | if (retcode != NO_ERROR) |
2583 | goto out; | 2623 | goto out; |
2584 | 2624 | ||
2585 | retcode = drbd_request_state(adm_ctx.mdev, mask, val); | 2625 | retcode = drbd_request_state(adm_ctx.device, mask, val); |
2586 | out: | 2626 | out: |
2587 | drbd_adm_finish(info, retcode); | 2627 | drbd_adm_finish(info, retcode); |
2588 | return 0; | 2628 | return 0; |
2589 | } | 2629 | } |
2590 | 2630 | ||
2591 | static int drbd_bmio_set_susp_al(struct drbd_conf *mdev) | 2631 | static int drbd_bmio_set_susp_al(struct drbd_device *device) |
2592 | { | 2632 | { |
2593 | int rv; | 2633 | int rv; |
2594 | 2634 | ||
2595 | rv = drbd_bmio_set_n_write(mdev); | 2635 | rv = drbd_bmio_set_n_write(device); |
2596 | drbd_suspend_al(mdev); | 2636 | drbd_suspend_al(device); |
2597 | return rv; | 2637 | return rv; |
2598 | } | 2638 | } |
2599 | 2639 | ||
2600 | int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) | 2640 | int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) |
2601 | { | 2641 | { |
2602 | int retcode; /* drbd_ret_code, drbd_state_rv */ | 2642 | int retcode; /* drbd_ret_code, drbd_state_rv */ |
2603 | struct drbd_conf *mdev; | 2643 | struct drbd_device *device; |
2604 | 2644 | ||
2605 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); | 2645 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
2606 | if (!adm_ctx.reply_skb) | 2646 | if (!adm_ctx.reply_skb) |
@@ -2608,32 +2648,32 @@ int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) | |||
2608 | if (retcode != NO_ERROR) | 2648 | if (retcode != NO_ERROR) |
2609 | goto out; | 2649 | goto out; |
2610 | 2650 | ||
2611 | mdev = adm_ctx.mdev; | 2651 | device = adm_ctx.device; |
2612 | 2652 | ||
2613 | /* If there is still bitmap IO pending, probably because of a previous | 2653 | /* If there is still bitmap IO pending, probably because of a previous |
2614 | * resync just being finished, wait for it before requesting a new resync. | 2654 | * resync just being finished, wait for it before requesting a new resync. |
2615 | * Also wait for it's after_state_ch(). */ | 2655 | * Also wait for it's after_state_ch(). */ |
2616 | drbd_suspend_io(mdev); | 2656 | drbd_suspend_io(device); |
2617 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); | 2657 | wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags)); |
2618 | drbd_flush_workqueue(mdev); | 2658 | drbd_flush_workqueue(&first_peer_device(device)->connection->sender_work); |
2619 | 2659 | ||
2620 | /* If we happen to be C_STANDALONE R_PRIMARY, just set all bits | 2660 | /* If we happen to be C_STANDALONE R_PRIMARY, just set all bits |
2621 | * in the bitmap. Otherwise, try to start a resync handshake | 2661 | * in the bitmap. Otherwise, try to start a resync handshake |
2622 | * as sync source for full sync. | 2662 | * as sync source for full sync. |
2623 | */ | 2663 | */ |
2624 | if (mdev->state.conn == C_STANDALONE && mdev->state.role == R_PRIMARY) { | 2664 | if (device->state.conn == C_STANDALONE && device->state.role == R_PRIMARY) { |
2625 | /* The peer will get a resync upon connect anyways. Just make that | 2665 | /* The peer will get a resync upon connect anyways. Just make that |
2626 | into a full resync. */ | 2666 | into a full resync. */ |
2627 | retcode = drbd_request_state(mdev, NS(pdsk, D_INCONSISTENT)); | 2667 | retcode = drbd_request_state(device, NS(pdsk, D_INCONSISTENT)); |
2628 | if (retcode >= SS_SUCCESS) { | 2668 | if (retcode >= SS_SUCCESS) { |
2629 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_susp_al, | 2669 | if (drbd_bitmap_io(device, &drbd_bmio_set_susp_al, |
2630 | "set_n_write from invalidate_peer", | 2670 | "set_n_write from invalidate_peer", |
2631 | BM_LOCKED_SET_ALLOWED)) | 2671 | BM_LOCKED_SET_ALLOWED)) |
2632 | retcode = ERR_IO_MD_DISK; | 2672 | retcode = ERR_IO_MD_DISK; |
2633 | } | 2673 | } |
2634 | } else | 2674 | } else |
2635 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S)); | 2675 | retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_S)); |
2636 | drbd_resume_io(mdev); | 2676 | drbd_resume_io(device); |
2637 | 2677 | ||
2638 | out: | 2678 | out: |
2639 | drbd_adm_finish(info, retcode); | 2679 | drbd_adm_finish(info, retcode); |
@@ -2650,7 +2690,7 @@ int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info) | |||
2650 | if (retcode != NO_ERROR) | 2690 | if (retcode != NO_ERROR) |
2651 | goto out; | 2691 | goto out; |
2652 | 2692 | ||
2653 | if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 1)) == SS_NOTHING_TO_DO) | 2693 | if (drbd_request_state(adm_ctx.device, NS(user_isp, 1)) == SS_NOTHING_TO_DO) |
2654 | retcode = ERR_PAUSE_IS_SET; | 2694 | retcode = ERR_PAUSE_IS_SET; |
2655 | out: | 2695 | out: |
2656 | drbd_adm_finish(info, retcode); | 2696 | drbd_adm_finish(info, retcode); |
@@ -2668,8 +2708,8 @@ int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info) | |||
2668 | if (retcode != NO_ERROR) | 2708 | if (retcode != NO_ERROR) |
2669 | goto out; | 2709 | goto out; |
2670 | 2710 | ||
2671 | if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 0)) == SS_NOTHING_TO_DO) { | 2711 | if (drbd_request_state(adm_ctx.device, NS(user_isp, 0)) == SS_NOTHING_TO_DO) { |
2672 | s = adm_ctx.mdev->state; | 2712 | s = adm_ctx.device->state; |
2673 | if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) { | 2713 | if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) { |
2674 | retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP : | 2714 | retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP : |
2675 | s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR; | 2715 | s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR; |
@@ -2690,7 +2730,7 @@ int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info) | |||
2690 | 2730 | ||
2691 | int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info) | 2731 | int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info) |
2692 | { | 2732 | { |
2693 | struct drbd_conf *mdev; | 2733 | struct drbd_device *device; |
2694 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ | 2734 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
2695 | 2735 | ||
2696 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); | 2736 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
@@ -2699,20 +2739,20 @@ int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info) | |||
2699 | if (retcode != NO_ERROR) | 2739 | if (retcode != NO_ERROR) |
2700 | goto out; | 2740 | goto out; |
2701 | 2741 | ||
2702 | mdev = adm_ctx.mdev; | 2742 | device = adm_ctx.device; |
2703 | if (test_bit(NEW_CUR_UUID, &mdev->flags)) { | 2743 | if (test_bit(NEW_CUR_UUID, &device->flags)) { |
2704 | drbd_uuid_new_current(mdev); | 2744 | drbd_uuid_new_current(device); |
2705 | clear_bit(NEW_CUR_UUID, &mdev->flags); | 2745 | clear_bit(NEW_CUR_UUID, &device->flags); |
2706 | } | 2746 | } |
2707 | drbd_suspend_io(mdev); | 2747 | drbd_suspend_io(device); |
2708 | retcode = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0)); | 2748 | retcode = drbd_request_state(device, NS3(susp, 0, susp_nod, 0, susp_fen, 0)); |
2709 | if (retcode == SS_SUCCESS) { | 2749 | if (retcode == SS_SUCCESS) { |
2710 | if (mdev->state.conn < C_CONNECTED) | 2750 | if (device->state.conn < C_CONNECTED) |
2711 | tl_clear(mdev->tconn); | 2751 | tl_clear(first_peer_device(device)->connection); |
2712 | if (mdev->state.disk == D_DISKLESS || mdev->state.disk == D_FAILED) | 2752 | if (device->state.disk == D_DISKLESS || device->state.disk == D_FAILED) |
2713 | tl_restart(mdev->tconn, FAIL_FROZEN_DISK_IO); | 2753 | tl_restart(first_peer_device(device)->connection, FAIL_FROZEN_DISK_IO); |
2714 | } | 2754 | } |
2715 | drbd_resume_io(mdev); | 2755 | drbd_resume_io(device); |
2716 | 2756 | ||
2717 | out: | 2757 | out: |
2718 | drbd_adm_finish(info, retcode); | 2758 | drbd_adm_finish(info, retcode); |
@@ -2724,23 +2764,28 @@ int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info) | |||
2724 | return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED)); | 2764 | return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED)); |
2725 | } | 2765 | } |
2726 | 2766 | ||
2727 | int nla_put_drbd_cfg_context(struct sk_buff *skb, struct drbd_tconn *tconn, unsigned vnr) | 2767 | static int nla_put_drbd_cfg_context(struct sk_buff *skb, |
2768 | struct drbd_resource *resource, | ||
2769 | struct drbd_connection *connection, | ||
2770 | struct drbd_device *device) | ||
2728 | { | 2771 | { |
2729 | struct nlattr *nla; | 2772 | struct nlattr *nla; |
2730 | nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT); | 2773 | nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT); |
2731 | if (!nla) | 2774 | if (!nla) |
2732 | goto nla_put_failure; | 2775 | goto nla_put_failure; |
2733 | if (vnr != VOLUME_UNSPECIFIED && | 2776 | if (device && |
2734 | nla_put_u32(skb, T_ctx_volume, vnr)) | 2777 | nla_put_u32(skb, T_ctx_volume, device->vnr)) |
2735 | goto nla_put_failure; | ||
2736 | if (nla_put_string(skb, T_ctx_resource_name, tconn->name)) | ||
2737 | goto nla_put_failure; | ||
2738 | if (tconn->my_addr_len && | ||
2739 | nla_put(skb, T_ctx_my_addr, tconn->my_addr_len, &tconn->my_addr)) | ||
2740 | goto nla_put_failure; | 2778 | goto nla_put_failure; |
2741 | if (tconn->peer_addr_len && | 2779 | if (nla_put_string(skb, T_ctx_resource_name, resource->name)) |
2742 | nla_put(skb, T_ctx_peer_addr, tconn->peer_addr_len, &tconn->peer_addr)) | ||
2743 | goto nla_put_failure; | 2780 | goto nla_put_failure; |
2781 | if (connection) { | ||
2782 | if (connection->my_addr_len && | ||
2783 | nla_put(skb, T_ctx_my_addr, connection->my_addr_len, &connection->my_addr)) | ||
2784 | goto nla_put_failure; | ||
2785 | if (connection->peer_addr_len && | ||
2786 | nla_put(skb, T_ctx_peer_addr, connection->peer_addr_len, &connection->peer_addr)) | ||
2787 | goto nla_put_failure; | ||
2788 | } | ||
2744 | nla_nest_end(skb, nla); | 2789 | nla_nest_end(skb, nla); |
2745 | return 0; | 2790 | return 0; |
2746 | 2791 | ||
@@ -2750,9 +2795,22 @@ nla_put_failure: | |||
2750 | return -EMSGSIZE; | 2795 | return -EMSGSIZE; |
2751 | } | 2796 | } |
2752 | 2797 | ||
2753 | int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, | 2798 | /* |
2799 | * Return the connection of @resource if @resource has exactly one connection. | ||
2800 | */ | ||
2801 | static struct drbd_connection *the_only_connection(struct drbd_resource *resource) | ||
2802 | { | ||
2803 | struct list_head *connections = &resource->connections; | ||
2804 | |||
2805 | if (list_empty(connections) || connections->next->next != connections) | ||
2806 | return NULL; | ||
2807 | return list_first_entry(&resource->connections, struct drbd_connection, connections); | ||
2808 | } | ||
2809 | |||
2810 | int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device, | ||
2754 | const struct sib_info *sib) | 2811 | const struct sib_info *sib) |
2755 | { | 2812 | { |
2813 | struct drbd_resource *resource = device->resource; | ||
2756 | struct state_info *si = NULL; /* for sizeof(si->member); */ | 2814 | struct state_info *si = NULL; /* for sizeof(si->member); */ |
2757 | struct nlattr *nla; | 2815 | struct nlattr *nla; |
2758 | int got_ldev; | 2816 | int got_ldev; |
@@ -2772,27 +2830,27 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, | |||
2772 | * always in the context of the receiving process */ | 2830 | * always in the context of the receiving process */ |
2773 | exclude_sensitive = sib || !capable(CAP_SYS_ADMIN); | 2831 | exclude_sensitive = sib || !capable(CAP_SYS_ADMIN); |
2774 | 2832 | ||
2775 | got_ldev = get_ldev(mdev); | 2833 | got_ldev = get_ldev(device); |
2776 | 2834 | ||
2777 | /* We need to add connection name and volume number information still. | 2835 | /* We need to add connection name and volume number information still. |
2778 | * Minor number is in drbd_genlmsghdr. */ | 2836 | * Minor number is in drbd_genlmsghdr. */ |
2779 | if (nla_put_drbd_cfg_context(skb, mdev->tconn, mdev->vnr)) | 2837 | if (nla_put_drbd_cfg_context(skb, resource, the_only_connection(resource), device)) |
2780 | goto nla_put_failure; | 2838 | goto nla_put_failure; |
2781 | 2839 | ||
2782 | if (res_opts_to_skb(skb, &mdev->tconn->res_opts, exclude_sensitive)) | 2840 | if (res_opts_to_skb(skb, &device->resource->res_opts, exclude_sensitive)) |
2783 | goto nla_put_failure; | 2841 | goto nla_put_failure; |
2784 | 2842 | ||
2785 | rcu_read_lock(); | 2843 | rcu_read_lock(); |
2786 | if (got_ldev) { | 2844 | if (got_ldev) { |
2787 | struct disk_conf *disk_conf; | 2845 | struct disk_conf *disk_conf; |
2788 | 2846 | ||
2789 | disk_conf = rcu_dereference(mdev->ldev->disk_conf); | 2847 | disk_conf = rcu_dereference(device->ldev->disk_conf); |
2790 | err = disk_conf_to_skb(skb, disk_conf, exclude_sensitive); | 2848 | err = disk_conf_to_skb(skb, disk_conf, exclude_sensitive); |
2791 | } | 2849 | } |
2792 | if (!err) { | 2850 | if (!err) { |
2793 | struct net_conf *nc; | 2851 | struct net_conf *nc; |
2794 | 2852 | ||
2795 | nc = rcu_dereference(mdev->tconn->net_conf); | 2853 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
2796 | if (nc) | 2854 | if (nc) |
2797 | err = net_conf_to_skb(skb, nc, exclude_sensitive); | 2855 | err = net_conf_to_skb(skb, nc, exclude_sensitive); |
2798 | } | 2856 | } |
@@ -2804,38 +2862,38 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, | |||
2804 | if (!nla) | 2862 | if (!nla) |
2805 | goto nla_put_failure; | 2863 | goto nla_put_failure; |
2806 | if (nla_put_u32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY) || | 2864 | if (nla_put_u32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY) || |
2807 | nla_put_u32(skb, T_current_state, mdev->state.i) || | 2865 | nla_put_u32(skb, T_current_state, device->state.i) || |
2808 | nla_put_u64(skb, T_ed_uuid, mdev->ed_uuid) || | 2866 | nla_put_u64(skb, T_ed_uuid, device->ed_uuid) || |
2809 | nla_put_u64(skb, T_capacity, drbd_get_capacity(mdev->this_bdev)) || | 2867 | nla_put_u64(skb, T_capacity, drbd_get_capacity(device->this_bdev)) || |
2810 | nla_put_u64(skb, T_send_cnt, mdev->send_cnt) || | 2868 | nla_put_u64(skb, T_send_cnt, device->send_cnt) || |
2811 | nla_put_u64(skb, T_recv_cnt, mdev->recv_cnt) || | 2869 | nla_put_u64(skb, T_recv_cnt, device->recv_cnt) || |
2812 | nla_put_u64(skb, T_read_cnt, mdev->read_cnt) || | 2870 | nla_put_u64(skb, T_read_cnt, device->read_cnt) || |
2813 | nla_put_u64(skb, T_writ_cnt, mdev->writ_cnt) || | 2871 | nla_put_u64(skb, T_writ_cnt, device->writ_cnt) || |
2814 | nla_put_u64(skb, T_al_writ_cnt, mdev->al_writ_cnt) || | 2872 | nla_put_u64(skb, T_al_writ_cnt, device->al_writ_cnt) || |
2815 | nla_put_u64(skb, T_bm_writ_cnt, mdev->bm_writ_cnt) || | 2873 | nla_put_u64(skb, T_bm_writ_cnt, device->bm_writ_cnt) || |
2816 | nla_put_u32(skb, T_ap_bio_cnt, atomic_read(&mdev->ap_bio_cnt)) || | 2874 | nla_put_u32(skb, T_ap_bio_cnt, atomic_read(&device->ap_bio_cnt)) || |
2817 | nla_put_u32(skb, T_ap_pending_cnt, atomic_read(&mdev->ap_pending_cnt)) || | 2875 | nla_put_u32(skb, T_ap_pending_cnt, atomic_read(&device->ap_pending_cnt)) || |
2818 | nla_put_u32(skb, T_rs_pending_cnt, atomic_read(&mdev->rs_pending_cnt))) | 2876 | nla_put_u32(skb, T_rs_pending_cnt, atomic_read(&device->rs_pending_cnt))) |
2819 | goto nla_put_failure; | 2877 | goto nla_put_failure; |
2820 | 2878 | ||
2821 | if (got_ldev) { | 2879 | if (got_ldev) { |
2822 | int err; | 2880 | int err; |
2823 | 2881 | ||
2824 | spin_lock_irq(&mdev->ldev->md.uuid_lock); | 2882 | spin_lock_irq(&device->ldev->md.uuid_lock); |
2825 | err = nla_put(skb, T_uuids, sizeof(si->uuids), mdev->ldev->md.uuid); | 2883 | err = nla_put(skb, T_uuids, sizeof(si->uuids), device->ldev->md.uuid); |
2826 | spin_unlock_irq(&mdev->ldev->md.uuid_lock); | 2884 | spin_unlock_irq(&device->ldev->md.uuid_lock); |
2827 | 2885 | ||
2828 | if (err) | 2886 | if (err) |
2829 | goto nla_put_failure; | 2887 | goto nla_put_failure; |
2830 | 2888 | ||
2831 | if (nla_put_u32(skb, T_disk_flags, mdev->ldev->md.flags) || | 2889 | if (nla_put_u32(skb, T_disk_flags, device->ldev->md.flags) || |
2832 | nla_put_u64(skb, T_bits_total, drbd_bm_bits(mdev)) || | 2890 | nla_put_u64(skb, T_bits_total, drbd_bm_bits(device)) || |
2833 | nla_put_u64(skb, T_bits_oos, drbd_bm_total_weight(mdev))) | 2891 | nla_put_u64(skb, T_bits_oos, drbd_bm_total_weight(device))) |
2834 | goto nla_put_failure; | 2892 | goto nla_put_failure; |
2835 | if (C_SYNC_SOURCE <= mdev->state.conn && | 2893 | if (C_SYNC_SOURCE <= device->state.conn && |
2836 | C_PAUSED_SYNC_T >= mdev->state.conn) { | 2894 | C_PAUSED_SYNC_T >= device->state.conn) { |
2837 | if (nla_put_u64(skb, T_bits_rs_total, mdev->rs_total) || | 2895 | if (nla_put_u64(skb, T_bits_rs_total, device->rs_total) || |
2838 | nla_put_u64(skb, T_bits_rs_failed, mdev->rs_failed)) | 2896 | nla_put_u64(skb, T_bits_rs_failed, device->rs_failed)) |
2839 | goto nla_put_failure; | 2897 | goto nla_put_failure; |
2840 | } | 2898 | } |
2841 | } | 2899 | } |
@@ -2867,7 +2925,7 @@ int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, | |||
2867 | nla_put_failure: | 2925 | nla_put_failure: |
2868 | err = -EMSGSIZE; | 2926 | err = -EMSGSIZE; |
2869 | if (got_ldev) | 2927 | if (got_ldev) |
2870 | put_ldev(mdev); | 2928 | put_ldev(device); |
2871 | return err; | 2929 | return err; |
2872 | } | 2930 | } |
2873 | 2931 | ||
@@ -2882,7 +2940,7 @@ int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info) | |||
2882 | if (retcode != NO_ERROR) | 2940 | if (retcode != NO_ERROR) |
2883 | goto out; | 2941 | goto out; |
2884 | 2942 | ||
2885 | err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.mdev, NULL); | 2943 | err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.device, NULL); |
2886 | if (err) { | 2944 | if (err) { |
2887 | nlmsg_free(adm_ctx.reply_skb); | 2945 | nlmsg_free(adm_ctx.reply_skb); |
2888 | return err; | 2946 | return err; |
@@ -2892,22 +2950,23 @@ out: | |||
2892 | return 0; | 2950 | return 0; |
2893 | } | 2951 | } |
2894 | 2952 | ||
2895 | int get_one_status(struct sk_buff *skb, struct netlink_callback *cb) | 2953 | static int get_one_status(struct sk_buff *skb, struct netlink_callback *cb) |
2896 | { | 2954 | { |
2897 | struct drbd_conf *mdev; | 2955 | struct drbd_device *device; |
2898 | struct drbd_genlmsghdr *dh; | 2956 | struct drbd_genlmsghdr *dh; |
2899 | struct drbd_tconn *pos = (struct drbd_tconn*)cb->args[0]; | 2957 | struct drbd_resource *pos = (struct drbd_resource *)cb->args[0]; |
2900 | struct drbd_tconn *tconn = NULL; | 2958 | struct drbd_resource *resource = NULL; |
2901 | struct drbd_tconn *tmp; | 2959 | struct drbd_resource *tmp; |
2902 | unsigned volume = cb->args[1]; | 2960 | unsigned volume = cb->args[1]; |
2903 | 2961 | ||
2904 | /* Open coded, deferred, iteration: | 2962 | /* Open coded, deferred, iteration: |
2905 | * list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) { | 2963 | * for_each_resource_safe(resource, tmp, &drbd_resources) { |
2906 | * idr_for_each_entry(&tconn->volumes, mdev, i) { | 2964 | * connection = "first connection of resource or undefined"; |
2965 | * idr_for_each_entry(&resource->devices, device, i) { | ||
2907 | * ... | 2966 | * ... |
2908 | * } | 2967 | * } |
2909 | * } | 2968 | * } |
2910 | * where tconn is cb->args[0]; | 2969 | * where resource is cb->args[0]; |
2911 | * and i is cb->args[1]; | 2970 | * and i is cb->args[1]; |
2912 | * | 2971 | * |
2913 | * cb->args[2] indicates if we shall loop over all resources, | 2972 | * cb->args[2] indicates if we shall loop over all resources, |
@@ -2916,44 +2975,44 @@ int get_one_status(struct sk_buff *skb, struct netlink_callback *cb) | |||
2916 | * This may miss entries inserted after this dump started, | 2975 | * This may miss entries inserted after this dump started, |
2917 | * or entries deleted before they are reached. | 2976 | * or entries deleted before they are reached. |
2918 | * | 2977 | * |
2919 | * We need to make sure the mdev won't disappear while | 2978 | * We need to make sure the device won't disappear while |
2920 | * we are looking at it, and revalidate our iterators | 2979 | * we are looking at it, and revalidate our iterators |
2921 | * on each iteration. | 2980 | * on each iteration. |
2922 | */ | 2981 | */ |
2923 | 2982 | ||
2924 | /* synchronize with conn_create()/conn_destroy() */ | 2983 | /* synchronize with conn_create()/drbd_destroy_connection() */ |
2925 | rcu_read_lock(); | 2984 | rcu_read_lock(); |
2926 | /* revalidate iterator position */ | 2985 | /* revalidate iterator position */ |
2927 | list_for_each_entry_rcu(tmp, &drbd_tconns, all_tconn) { | 2986 | for_each_resource_rcu(tmp, &drbd_resources) { |
2928 | if (pos == NULL) { | 2987 | if (pos == NULL) { |
2929 | /* first iteration */ | 2988 | /* first iteration */ |
2930 | pos = tmp; | 2989 | pos = tmp; |
2931 | tconn = pos; | 2990 | resource = pos; |
2932 | break; | 2991 | break; |
2933 | } | 2992 | } |
2934 | if (tmp == pos) { | 2993 | if (tmp == pos) { |
2935 | tconn = pos; | 2994 | resource = pos; |
2936 | break; | 2995 | break; |
2937 | } | 2996 | } |
2938 | } | 2997 | } |
2939 | if (tconn) { | 2998 | if (resource) { |
2940 | next_tconn: | 2999 | next_resource: |
2941 | mdev = idr_get_next(&tconn->volumes, &volume); | 3000 | device = idr_get_next(&resource->devices, &volume); |
2942 | if (!mdev) { | 3001 | if (!device) { |
2943 | /* No more volumes to dump on this tconn. | 3002 | /* No more volumes to dump on this resource. |
2944 | * Advance tconn iterator. */ | 3003 | * Advance resource iterator. */ |
2945 | pos = list_entry_rcu(tconn->all_tconn.next, | 3004 | pos = list_entry_rcu(resource->resources.next, |
2946 | struct drbd_tconn, all_tconn); | 3005 | struct drbd_resource, resources); |
2947 | /* Did we dump any volume on this tconn yet? */ | 3006 | /* Did we dump any volume of this resource yet? */ |
2948 | if (volume != 0) { | 3007 | if (volume != 0) { |
2949 | /* If we reached the end of the list, | 3008 | /* If we reached the end of the list, |
2950 | * or only a single resource dump was requested, | 3009 | * or only a single resource dump was requested, |
2951 | * we are done. */ | 3010 | * we are done. */ |
2952 | if (&pos->all_tconn == &drbd_tconns || cb->args[2]) | 3011 | if (&pos->resources == &drbd_resources || cb->args[2]) |
2953 | goto out; | 3012 | goto out; |
2954 | volume = 0; | 3013 | volume = 0; |
2955 | tconn = pos; | 3014 | resource = pos; |
2956 | goto next_tconn; | 3015 | goto next_resource; |
2957 | } | 3016 | } |
2958 | } | 3017 | } |
2959 | 3018 | ||
@@ -2963,43 +3022,49 @@ next_tconn: | |||
2963 | if (!dh) | 3022 | if (!dh) |
2964 | goto out; | 3023 | goto out; |
2965 | 3024 | ||
2966 | if (!mdev) { | 3025 | if (!device) { |
2967 | /* This is a tconn without a single volume. | 3026 | /* This is a connection without a single volume. |
2968 | * Suprisingly enough, it may have a network | 3027 | * Suprisingly enough, it may have a network |
2969 | * configuration. */ | 3028 | * configuration. */ |
2970 | struct net_conf *nc; | 3029 | struct drbd_connection *connection; |
3030 | |||
2971 | dh->minor = -1U; | 3031 | dh->minor = -1U; |
2972 | dh->ret_code = NO_ERROR; | 3032 | dh->ret_code = NO_ERROR; |
2973 | if (nla_put_drbd_cfg_context(skb, tconn, VOLUME_UNSPECIFIED)) | 3033 | connection = the_only_connection(resource); |
2974 | goto cancel; | 3034 | if (nla_put_drbd_cfg_context(skb, resource, connection, NULL)) |
2975 | nc = rcu_dereference(tconn->net_conf); | ||
2976 | if (nc && net_conf_to_skb(skb, nc, 1) != 0) | ||
2977 | goto cancel; | 3035 | goto cancel; |
3036 | if (connection) { | ||
3037 | struct net_conf *nc; | ||
3038 | |||
3039 | nc = rcu_dereference(connection->net_conf); | ||
3040 | if (nc && net_conf_to_skb(skb, nc, 1) != 0) | ||
3041 | goto cancel; | ||
3042 | } | ||
2978 | goto done; | 3043 | goto done; |
2979 | } | 3044 | } |
2980 | 3045 | ||
2981 | D_ASSERT(mdev->vnr == volume); | 3046 | D_ASSERT(device, device->vnr == volume); |
2982 | D_ASSERT(mdev->tconn == tconn); | 3047 | D_ASSERT(device, device->resource == resource); |
2983 | 3048 | ||
2984 | dh->minor = mdev_to_minor(mdev); | 3049 | dh->minor = device_to_minor(device); |
2985 | dh->ret_code = NO_ERROR; | 3050 | dh->ret_code = NO_ERROR; |
2986 | 3051 | ||
2987 | if (nla_put_status_info(skb, mdev, NULL)) { | 3052 | if (nla_put_status_info(skb, device, NULL)) { |
2988 | cancel: | 3053 | cancel: |
2989 | genlmsg_cancel(skb, dh); | 3054 | genlmsg_cancel(skb, dh); |
2990 | goto out; | 3055 | goto out; |
2991 | } | 3056 | } |
2992 | done: | 3057 | done: |
2993 | genlmsg_end(skb, dh); | 3058 | genlmsg_end(skb, dh); |
2994 | } | 3059 | } |
2995 | 3060 | ||
2996 | out: | 3061 | out: |
2997 | rcu_read_unlock(); | 3062 | rcu_read_unlock(); |
2998 | /* where to start the next iteration */ | 3063 | /* where to start the next iteration */ |
2999 | cb->args[0] = (long)pos; | 3064 | cb->args[0] = (long)pos; |
3000 | cb->args[1] = (pos == tconn) ? volume + 1 : 0; | 3065 | cb->args[1] = (pos == resource) ? volume + 1 : 0; |
3001 | 3066 | ||
3002 | /* No more tconns/volumes/minors found results in an empty skb. | 3067 | /* No more resources/volumes/minors found results in an empty skb. |
3003 | * Which will terminate the dump. */ | 3068 | * Which will terminate the dump. */ |
3004 | return skb->len; | 3069 | return skb->len; |
3005 | } | 3070 | } |
@@ -3019,7 +3084,7 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) | |||
3019 | const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ; | 3084 | const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ; |
3020 | struct nlattr *nla; | 3085 | struct nlattr *nla; |
3021 | const char *resource_name; | 3086 | const char *resource_name; |
3022 | struct drbd_tconn *tconn; | 3087 | struct drbd_resource *resource; |
3023 | int maxtype; | 3088 | int maxtype; |
3024 | 3089 | ||
3025 | /* Is this a followup call? */ | 3090 | /* Is this a followup call? */ |
@@ -3048,18 +3113,19 @@ int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) | |||
3048 | if (!nla) | 3113 | if (!nla) |
3049 | return -EINVAL; | 3114 | return -EINVAL; |
3050 | resource_name = nla_data(nla); | 3115 | resource_name = nla_data(nla); |
3051 | tconn = conn_get_by_name(resource_name); | 3116 | if (!*resource_name) |
3052 | 3117 | return -ENODEV; | |
3053 | if (!tconn) | 3118 | resource = drbd_find_resource(resource_name); |
3119 | if (!resource) | ||
3054 | return -ENODEV; | 3120 | return -ENODEV; |
3055 | 3121 | ||
3056 | kref_put(&tconn->kref, &conn_destroy); /* get_one_status() (re)validates tconn by itself */ | 3122 | kref_put(&resource->kref, drbd_destroy_resource); /* get_one_status() revalidates the resource */ |
3057 | 3123 | ||
3058 | /* prime iterators, and set "filter" mode mark: | 3124 | /* prime iterators, and set "filter" mode mark: |
3059 | * only dump this tconn. */ | 3125 | * only dump this connection. */ |
3060 | cb->args[0] = (long)tconn; | 3126 | cb->args[0] = (long)resource; |
3061 | /* cb->args[1] = 0; passed in this way. */ | 3127 | /* cb->args[1] = 0; passed in this way. */ |
3062 | cb->args[2] = (long)tconn; | 3128 | cb->args[2] = (long)resource; |
3063 | 3129 | ||
3064 | dump: | 3130 | dump: |
3065 | return get_one_status(skb, cb); | 3131 | return get_one_status(skb, cb); |
@@ -3078,8 +3144,8 @@ int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info) | |||
3078 | goto out; | 3144 | goto out; |
3079 | 3145 | ||
3080 | tp.timeout_type = | 3146 | tp.timeout_type = |
3081 | adm_ctx.mdev->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED : | 3147 | adm_ctx.device->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED : |
3082 | test_bit(USE_DEGR_WFC_T, &adm_ctx.mdev->flags) ? UT_DEGRADED : | 3148 | test_bit(USE_DEGR_WFC_T, &adm_ctx.device->flags) ? UT_DEGRADED : |
3083 | UT_DEFAULT; | 3149 | UT_DEFAULT; |
3084 | 3150 | ||
3085 | err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp); | 3151 | err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp); |
@@ -3094,7 +3160,7 @@ out: | |||
3094 | 3160 | ||
3095 | int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) | 3161 | int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) |
3096 | { | 3162 | { |
3097 | struct drbd_conf *mdev; | 3163 | struct drbd_device *device; |
3098 | enum drbd_ret_code retcode; | 3164 | enum drbd_ret_code retcode; |
3099 | struct start_ov_parms parms; | 3165 | struct start_ov_parms parms; |
3100 | 3166 | ||
@@ -3104,10 +3170,10 @@ int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) | |||
3104 | if (retcode != NO_ERROR) | 3170 | if (retcode != NO_ERROR) |
3105 | goto out; | 3171 | goto out; |
3106 | 3172 | ||
3107 | mdev = adm_ctx.mdev; | 3173 | device = adm_ctx.device; |
3108 | 3174 | ||
3109 | /* resume from last known position, if possible */ | 3175 | /* resume from last known position, if possible */ |
3110 | parms.ov_start_sector = mdev->ov_start_sector; | 3176 | parms.ov_start_sector = device->ov_start_sector; |
3111 | parms.ov_stop_sector = ULLONG_MAX; | 3177 | parms.ov_stop_sector = ULLONG_MAX; |
3112 | if (info->attrs[DRBD_NLA_START_OV_PARMS]) { | 3178 | if (info->attrs[DRBD_NLA_START_OV_PARMS]) { |
3113 | int err = start_ov_parms_from_attrs(&parms, info); | 3179 | int err = start_ov_parms_from_attrs(&parms, info); |
@@ -3118,15 +3184,15 @@ int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) | |||
3118 | } | 3184 | } |
3119 | } | 3185 | } |
3120 | /* w_make_ov_request expects position to be aligned */ | 3186 | /* w_make_ov_request expects position to be aligned */ |
3121 | mdev->ov_start_sector = parms.ov_start_sector & ~(BM_SECT_PER_BIT-1); | 3187 | device->ov_start_sector = parms.ov_start_sector & ~(BM_SECT_PER_BIT-1); |
3122 | mdev->ov_stop_sector = parms.ov_stop_sector; | 3188 | device->ov_stop_sector = parms.ov_stop_sector; |
3123 | 3189 | ||
3124 | /* If there is still bitmap IO pending, e.g. previous resync or verify | 3190 | /* If there is still bitmap IO pending, e.g. previous resync or verify |
3125 | * just being finished, wait for it before requesting a new resync. */ | 3191 | * just being finished, wait for it before requesting a new resync. */ |
3126 | drbd_suspend_io(mdev); | 3192 | drbd_suspend_io(device); |
3127 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); | 3193 | wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags)); |
3128 | retcode = drbd_request_state(mdev,NS(conn,C_VERIFY_S)); | 3194 | retcode = drbd_request_state(device, NS(conn, C_VERIFY_S)); |
3129 | drbd_resume_io(mdev); | 3195 | drbd_resume_io(device); |
3130 | out: | 3196 | out: |
3131 | drbd_adm_finish(info, retcode); | 3197 | drbd_adm_finish(info, retcode); |
3132 | return 0; | 3198 | return 0; |
@@ -3135,7 +3201,7 @@ out: | |||
3135 | 3201 | ||
3136 | int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info) | 3202 | int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info) |
3137 | { | 3203 | { |
3138 | struct drbd_conf *mdev; | 3204 | struct drbd_device *device; |
3139 | enum drbd_ret_code retcode; | 3205 | enum drbd_ret_code retcode; |
3140 | int skip_initial_sync = 0; | 3206 | int skip_initial_sync = 0; |
3141 | int err; | 3207 | int err; |
@@ -3147,7 +3213,7 @@ int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info) | |||
3147 | if (retcode != NO_ERROR) | 3213 | if (retcode != NO_ERROR) |
3148 | goto out_nolock; | 3214 | goto out_nolock; |
3149 | 3215 | ||
3150 | mdev = adm_ctx.mdev; | 3216 | device = adm_ctx.device; |
3151 | memset(&args, 0, sizeof(args)); | 3217 | memset(&args, 0, sizeof(args)); |
3152 | if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) { | 3218 | if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) { |
3153 | err = new_c_uuid_parms_from_attrs(&args, info); | 3219 | err = new_c_uuid_parms_from_attrs(&args, info); |
@@ -3158,49 +3224,50 @@ int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info) | |||
3158 | } | 3224 | } |
3159 | } | 3225 | } |
3160 | 3226 | ||
3161 | mutex_lock(mdev->state_mutex); /* Protects us against serialized state changes. */ | 3227 | mutex_lock(device->state_mutex); /* Protects us against serialized state changes. */ |
3162 | 3228 | ||
3163 | if (!get_ldev(mdev)) { | 3229 | if (!get_ldev(device)) { |
3164 | retcode = ERR_NO_DISK; | 3230 | retcode = ERR_NO_DISK; |
3165 | goto out; | 3231 | goto out; |
3166 | } | 3232 | } |
3167 | 3233 | ||
3168 | /* this is "skip initial sync", assume to be clean */ | 3234 | /* this is "skip initial sync", assume to be clean */ |
3169 | if (mdev->state.conn == C_CONNECTED && mdev->tconn->agreed_pro_version >= 90 && | 3235 | if (device->state.conn == C_CONNECTED && |
3170 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) { | 3236 | first_peer_device(device)->connection->agreed_pro_version >= 90 && |
3171 | dev_info(DEV, "Preparing to skip initial sync\n"); | 3237 | device->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) { |
3238 | drbd_info(device, "Preparing to skip initial sync\n"); | ||
3172 | skip_initial_sync = 1; | 3239 | skip_initial_sync = 1; |
3173 | } else if (mdev->state.conn != C_STANDALONE) { | 3240 | } else if (device->state.conn != C_STANDALONE) { |
3174 | retcode = ERR_CONNECTED; | 3241 | retcode = ERR_CONNECTED; |
3175 | goto out_dec; | 3242 | goto out_dec; |
3176 | } | 3243 | } |
3177 | 3244 | ||
3178 | drbd_uuid_set(mdev, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */ | 3245 | drbd_uuid_set(device, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */ |
3179 | drbd_uuid_new_current(mdev); /* New current, previous to UI_BITMAP */ | 3246 | drbd_uuid_new_current(device); /* New current, previous to UI_BITMAP */ |
3180 | 3247 | ||
3181 | if (args.clear_bm) { | 3248 | if (args.clear_bm) { |
3182 | err = drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, | 3249 | err = drbd_bitmap_io(device, &drbd_bmio_clear_n_write, |
3183 | "clear_n_write from new_c_uuid", BM_LOCKED_MASK); | 3250 | "clear_n_write from new_c_uuid", BM_LOCKED_MASK); |
3184 | if (err) { | 3251 | if (err) { |
3185 | dev_err(DEV, "Writing bitmap failed with %d\n",err); | 3252 | drbd_err(device, "Writing bitmap failed with %d\n", err); |
3186 | retcode = ERR_IO_MD_DISK; | 3253 | retcode = ERR_IO_MD_DISK; |
3187 | } | 3254 | } |
3188 | if (skip_initial_sync) { | 3255 | if (skip_initial_sync) { |
3189 | drbd_send_uuids_skip_initial_sync(mdev); | 3256 | drbd_send_uuids_skip_initial_sync(first_peer_device(device)); |
3190 | _drbd_uuid_set(mdev, UI_BITMAP, 0); | 3257 | _drbd_uuid_set(device, UI_BITMAP, 0); |
3191 | drbd_print_uuids(mdev, "cleared bitmap UUID"); | 3258 | drbd_print_uuids(device, "cleared bitmap UUID"); |
3192 | spin_lock_irq(&mdev->tconn->req_lock); | 3259 | spin_lock_irq(&device->resource->req_lock); |
3193 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), | 3260 | _drbd_set_state(_NS2(device, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
3194 | CS_VERBOSE, NULL); | 3261 | CS_VERBOSE, NULL); |
3195 | spin_unlock_irq(&mdev->tconn->req_lock); | 3262 | spin_unlock_irq(&device->resource->req_lock); |
3196 | } | 3263 | } |
3197 | } | 3264 | } |
3198 | 3265 | ||
3199 | drbd_md_sync(mdev); | 3266 | drbd_md_sync(device); |
3200 | out_dec: | 3267 | out_dec: |
3201 | put_ldev(mdev); | 3268 | put_ldev(device); |
3202 | out: | 3269 | out: |
3203 | mutex_unlock(mdev->state_mutex); | 3270 | mutex_unlock(device->state_mutex); |
3204 | out_nolock: | 3271 | out_nolock: |
3205 | drbd_adm_finish(info, retcode); | 3272 | drbd_adm_finish(info, retcode); |
3206 | return 0; | 3273 | return 0; |
@@ -3246,7 +3313,7 @@ int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info) | |||
3246 | if (retcode != NO_ERROR) | 3313 | if (retcode != NO_ERROR) |
3247 | goto out; | 3314 | goto out; |
3248 | 3315 | ||
3249 | if (adm_ctx.tconn) { | 3316 | if (adm_ctx.resource) { |
3250 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) { | 3317 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) { |
3251 | retcode = ERR_INVALID_REQUEST; | 3318 | retcode = ERR_INVALID_REQUEST; |
3252 | drbd_msg_put_info("resource exists"); | 3319 | drbd_msg_put_info("resource exists"); |
@@ -3262,7 +3329,7 @@ out: | |||
3262 | return 0; | 3329 | return 0; |
3263 | } | 3330 | } |
3264 | 3331 | ||
3265 | int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info) | 3332 | int drbd_adm_new_minor(struct sk_buff *skb, struct genl_info *info) |
3266 | { | 3333 | { |
3267 | struct drbd_genlmsghdr *dh = info->userhdr; | 3334 | struct drbd_genlmsghdr *dh = info->userhdr; |
3268 | enum drbd_ret_code retcode; | 3335 | enum drbd_ret_code retcode; |
@@ -3285,41 +3352,36 @@ int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info) | |||
3285 | } | 3352 | } |
3286 | 3353 | ||
3287 | /* drbd_adm_prepare made sure already | 3354 | /* drbd_adm_prepare made sure already |
3288 | * that mdev->tconn and mdev->vnr match the request. */ | 3355 | * that first_peer_device(device)->connection and device->vnr match the request. */ |
3289 | if (adm_ctx.mdev) { | 3356 | if (adm_ctx.device) { |
3290 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) | 3357 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) |
3291 | retcode = ERR_MINOR_EXISTS; | 3358 | retcode = ERR_MINOR_EXISTS; |
3292 | /* else: still NO_ERROR */ | 3359 | /* else: still NO_ERROR */ |
3293 | goto out; | 3360 | goto out; |
3294 | } | 3361 | } |
3295 | 3362 | ||
3296 | retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume); | 3363 | retcode = drbd_create_device(adm_ctx.resource, dh->minor, adm_ctx.volume); |
3297 | out: | 3364 | out: |
3298 | drbd_adm_finish(info, retcode); | 3365 | drbd_adm_finish(info, retcode); |
3299 | return 0; | 3366 | return 0; |
3300 | } | 3367 | } |
3301 | 3368 | ||
3302 | static enum drbd_ret_code adm_delete_minor(struct drbd_conf *mdev) | 3369 | static enum drbd_ret_code adm_del_minor(struct drbd_device *device) |
3303 | { | 3370 | { |
3304 | if (mdev->state.disk == D_DISKLESS && | 3371 | if (device->state.disk == D_DISKLESS && |
3305 | /* no need to be mdev->state.conn == C_STANDALONE && | 3372 | /* no need to be device->state.conn == C_STANDALONE && |
3306 | * we may want to delete a minor from a live replication group. | 3373 | * we may want to delete a minor from a live replication group. |
3307 | */ | 3374 | */ |
3308 | mdev->state.role == R_SECONDARY) { | 3375 | device->state.role == R_SECONDARY) { |
3309 | _drbd_request_state(mdev, NS(conn, C_WF_REPORT_PARAMS), | 3376 | _drbd_request_state(device, NS(conn, C_WF_REPORT_PARAMS), |
3310 | CS_VERBOSE + CS_WAIT_COMPLETE); | 3377 | CS_VERBOSE + CS_WAIT_COMPLETE); |
3311 | idr_remove(&mdev->tconn->volumes, mdev->vnr); | 3378 | drbd_delete_device(device); |
3312 | idr_remove(&minors, mdev_to_minor(mdev)); | ||
3313 | destroy_workqueue(mdev->submit.wq); | ||
3314 | del_gendisk(mdev->vdisk); | ||
3315 | synchronize_rcu(); | ||
3316 | kref_put(&mdev->kref, &drbd_minor_destroy); | ||
3317 | return NO_ERROR; | 3379 | return NO_ERROR; |
3318 | } else | 3380 | } else |
3319 | return ERR_MINOR_CONFIGURED; | 3381 | return ERR_MINOR_CONFIGURED; |
3320 | } | 3382 | } |
3321 | 3383 | ||
3322 | int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info) | 3384 | int drbd_adm_del_minor(struct sk_buff *skb, struct genl_info *info) |
3323 | { | 3385 | { |
3324 | enum drbd_ret_code retcode; | 3386 | enum drbd_ret_code retcode; |
3325 | 3387 | ||
@@ -3329,7 +3391,7 @@ int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info) | |||
3329 | if (retcode != NO_ERROR) | 3391 | if (retcode != NO_ERROR) |
3330 | goto out; | 3392 | goto out; |
3331 | 3393 | ||
3332 | retcode = adm_delete_minor(adm_ctx.mdev); | 3394 | retcode = adm_del_minor(adm_ctx.device); |
3333 | out: | 3395 | out: |
3334 | drbd_adm_finish(info, retcode); | 3396 | drbd_adm_finish(info, retcode); |
3335 | return 0; | 3397 | return 0; |
@@ -3337,55 +3399,58 @@ out: | |||
3337 | 3399 | ||
3338 | int drbd_adm_down(struct sk_buff *skb, struct genl_info *info) | 3400 | int drbd_adm_down(struct sk_buff *skb, struct genl_info *info) |
3339 | { | 3401 | { |
3402 | struct drbd_resource *resource; | ||
3403 | struct drbd_connection *connection; | ||
3404 | struct drbd_device *device; | ||
3340 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ | 3405 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
3341 | struct drbd_conf *mdev; | ||
3342 | unsigned i; | 3406 | unsigned i; |
3343 | 3407 | ||
3344 | retcode = drbd_adm_prepare(skb, info, 0); | 3408 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
3345 | if (!adm_ctx.reply_skb) | 3409 | if (!adm_ctx.reply_skb) |
3346 | return retcode; | 3410 | return retcode; |
3347 | if (retcode != NO_ERROR) | 3411 | if (retcode != NO_ERROR) |
3348 | goto out; | 3412 | goto out; |
3349 | 3413 | ||
3350 | if (!adm_ctx.tconn) { | 3414 | resource = adm_ctx.resource; |
3351 | retcode = ERR_RES_NOT_KNOWN; | ||
3352 | goto out; | ||
3353 | } | ||
3354 | |||
3355 | /* demote */ | 3415 | /* demote */ |
3356 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { | 3416 | for_each_connection(connection, resource) { |
3357 | retcode = drbd_set_role(mdev, R_SECONDARY, 0); | 3417 | struct drbd_peer_device *peer_device; |
3418 | |||
3419 | idr_for_each_entry(&connection->peer_devices, peer_device, i) { | ||
3420 | retcode = drbd_set_role(peer_device->device, R_SECONDARY, 0); | ||
3421 | if (retcode < SS_SUCCESS) { | ||
3422 | drbd_msg_put_info("failed to demote"); | ||
3423 | goto out; | ||
3424 | } | ||
3425 | } | ||
3426 | |||
3427 | retcode = conn_try_disconnect(connection, 0); | ||
3358 | if (retcode < SS_SUCCESS) { | 3428 | if (retcode < SS_SUCCESS) { |
3359 | drbd_msg_put_info("failed to demote"); | 3429 | drbd_msg_put_info("failed to disconnect"); |
3360 | goto out; | 3430 | goto out; |
3361 | } | 3431 | } |
3362 | } | 3432 | } |
3363 | 3433 | ||
3364 | retcode = conn_try_disconnect(adm_ctx.tconn, 0); | ||
3365 | if (retcode < SS_SUCCESS) { | ||
3366 | drbd_msg_put_info("failed to disconnect"); | ||
3367 | goto out; | ||
3368 | } | ||
3369 | |||
3370 | /* detach */ | 3434 | /* detach */ |
3371 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { | 3435 | idr_for_each_entry(&resource->devices, device, i) { |
3372 | retcode = adm_detach(mdev, 0); | 3436 | retcode = adm_detach(device, 0); |
3373 | if (retcode < SS_SUCCESS || retcode > NO_ERROR) { | 3437 | if (retcode < SS_SUCCESS || retcode > NO_ERROR) { |
3374 | drbd_msg_put_info("failed to detach"); | 3438 | drbd_msg_put_info("failed to detach"); |
3375 | goto out; | 3439 | goto out; |
3376 | } | 3440 | } |
3377 | } | 3441 | } |
3378 | 3442 | ||
3379 | /* If we reach this, all volumes (of this tconn) are Secondary, | 3443 | /* If we reach this, all volumes (of this connection) are Secondary, |
3380 | * Disconnected, Diskless, aka Unconfigured. Make sure all threads have | 3444 | * Disconnected, Diskless, aka Unconfigured. Make sure all threads have |
3381 | * actually stopped, state handling only does drbd_thread_stop_nowait(). */ | 3445 | * actually stopped, state handling only does drbd_thread_stop_nowait(). */ |
3382 | drbd_thread_stop(&adm_ctx.tconn->worker); | 3446 | for_each_connection(connection, resource) |
3447 | drbd_thread_stop(&connection->worker); | ||
3383 | 3448 | ||
3384 | /* Now, nothing can fail anymore */ | 3449 | /* Now, nothing can fail anymore */ |
3385 | 3450 | ||
3386 | /* delete volumes */ | 3451 | /* delete volumes */ |
3387 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { | 3452 | idr_for_each_entry(&resource->devices, device, i) { |
3388 | retcode = adm_delete_minor(mdev); | 3453 | retcode = adm_del_minor(device); |
3389 | if (retcode != NO_ERROR) { | 3454 | if (retcode != NO_ERROR) { |
3390 | /* "can not happen" */ | 3455 | /* "can not happen" */ |
3391 | drbd_msg_put_info("failed to delete volume"); | 3456 | drbd_msg_put_info("failed to delete volume"); |
@@ -3393,19 +3458,11 @@ int drbd_adm_down(struct sk_buff *skb, struct genl_info *info) | |||
3393 | } | 3458 | } |
3394 | } | 3459 | } |
3395 | 3460 | ||
3396 | /* delete connection */ | 3461 | list_del_rcu(&resource->resources); |
3397 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { | 3462 | synchronize_rcu(); |
3398 | list_del_rcu(&adm_ctx.tconn->all_tconn); | 3463 | drbd_free_resource(resource); |
3399 | synchronize_rcu(); | 3464 | retcode = NO_ERROR; |
3400 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); | ||
3401 | 3465 | ||
3402 | retcode = NO_ERROR; | ||
3403 | } else { | ||
3404 | /* "can not happen" */ | ||
3405 | retcode = ERR_RES_IN_USE; | ||
3406 | drbd_msg_put_info("failed to delete connection"); | ||
3407 | } | ||
3408 | goto out; | ||
3409 | out: | 3466 | out: |
3410 | drbd_adm_finish(info, retcode); | 3467 | drbd_adm_finish(info, retcode); |
3411 | return 0; | 3468 | return 0; |
@@ -3413,6 +3470,8 @@ out: | |||
3413 | 3470 | ||
3414 | int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info) | 3471 | int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info) |
3415 | { | 3472 | { |
3473 | struct drbd_resource *resource; | ||
3474 | struct drbd_connection *connection; | ||
3416 | enum drbd_ret_code retcode; | 3475 | enum drbd_ret_code retcode; |
3417 | 3476 | ||
3418 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); | 3477 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
@@ -3421,24 +3480,30 @@ int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info) | |||
3421 | if (retcode != NO_ERROR) | 3480 | if (retcode != NO_ERROR) |
3422 | goto out; | 3481 | goto out; |
3423 | 3482 | ||
3424 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { | 3483 | resource = adm_ctx.resource; |
3425 | list_del_rcu(&adm_ctx.tconn->all_tconn); | 3484 | for_each_connection(connection, resource) { |
3426 | synchronize_rcu(); | 3485 | if (connection->cstate > C_STANDALONE) { |
3427 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); | 3486 | retcode = ERR_NET_CONFIGURED; |
3428 | 3487 | goto out; | |
3429 | retcode = NO_ERROR; | 3488 | } |
3430 | } else { | 3489 | } |
3490 | if (!idr_is_empty(&resource->devices)) { | ||
3431 | retcode = ERR_RES_IN_USE; | 3491 | retcode = ERR_RES_IN_USE; |
3492 | goto out; | ||
3432 | } | 3493 | } |
3433 | 3494 | ||
3434 | if (retcode == NO_ERROR) | 3495 | list_del_rcu(&resource->resources); |
3435 | drbd_thread_stop(&adm_ctx.tconn->worker); | 3496 | for_each_connection(connection, resource) |
3497 | drbd_thread_stop(&connection->worker); | ||
3498 | synchronize_rcu(); | ||
3499 | drbd_free_resource(resource); | ||
3500 | retcode = NO_ERROR; | ||
3436 | out: | 3501 | out: |
3437 | drbd_adm_finish(info, retcode); | 3502 | drbd_adm_finish(info, retcode); |
3438 | return 0; | 3503 | return 0; |
3439 | } | 3504 | } |
3440 | 3505 | ||
3441 | void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib) | 3506 | void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib) |
3442 | { | 3507 | { |
3443 | static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */ | 3508 | static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */ |
3444 | struct sk_buff *msg; | 3509 | struct sk_buff *msg; |
@@ -3447,8 +3512,8 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib) | |||
3447 | int err = -ENOMEM; | 3512 | int err = -ENOMEM; |
3448 | 3513 | ||
3449 | if (sib->sib_reason == SIB_SYNC_PROGRESS) { | 3514 | if (sib->sib_reason == SIB_SYNC_PROGRESS) { |
3450 | if (time_after(jiffies, mdev->rs_last_bcast + HZ)) | 3515 | if (time_after(jiffies, device->rs_last_bcast + HZ)) |
3451 | mdev->rs_last_bcast = jiffies; | 3516 | device->rs_last_bcast = jiffies; |
3452 | else | 3517 | else |
3453 | return; | 3518 | return; |
3454 | } | 3519 | } |
@@ -3462,10 +3527,10 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib) | |||
3462 | d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT); | 3527 | d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT); |
3463 | if (!d_out) /* cannot happen, but anyways. */ | 3528 | if (!d_out) /* cannot happen, but anyways. */ |
3464 | goto nla_put_failure; | 3529 | goto nla_put_failure; |
3465 | d_out->minor = mdev_to_minor(mdev); | 3530 | d_out->minor = device_to_minor(device); |
3466 | d_out->ret_code = NO_ERROR; | 3531 | d_out->ret_code = NO_ERROR; |
3467 | 3532 | ||
3468 | if (nla_put_status_info(msg, mdev, sib)) | 3533 | if (nla_put_status_info(msg, device, sib)) |
3469 | goto nla_put_failure; | 3534 | goto nla_put_failure; |
3470 | genlmsg_end(msg, d_out); | 3535 | genlmsg_end(msg, d_out); |
3471 | err = drbd_genl_multicast_events(msg, 0); | 3536 | err = drbd_genl_multicast_events(msg, 0); |
@@ -3478,7 +3543,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib) | |||
3478 | nla_put_failure: | 3543 | nla_put_failure: |
3479 | nlmsg_free(msg); | 3544 | nlmsg_free(msg); |
3480 | failed: | 3545 | failed: |
3481 | dev_err(DEV, "Error %d while broadcasting event. " | 3546 | drbd_err(device, "Error %d while broadcasting event. " |
3482 | "Event seq:%u sib_reason:%u\n", | 3547 | "Event seq:%u sib_reason:%u\n", |
3483 | err, seq, sib->sib_reason); | 3548 | err, seq, sib->sib_reason); |
3484 | } | 3549 | } |
diff --git a/drivers/block/drbd/drbd_proc.c b/drivers/block/drbd/drbd_proc.c index bf31d41dbaad..2f26e8ffa45b 100644 --- a/drivers/block/drbd/drbd_proc.c +++ b/drivers/block/drbd/drbd_proc.c | |||
@@ -46,7 +46,7 @@ const struct file_operations drbd_proc_fops = { | |||
46 | .release = drbd_proc_release, | 46 | .release = drbd_proc_release, |
47 | }; | 47 | }; |
48 | 48 | ||
49 | void seq_printf_with_thousands_grouping(struct seq_file *seq, long v) | 49 | static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v) |
50 | { | 50 | { |
51 | /* v is in kB/sec. We don't expect TiByte/sec yet. */ | 51 | /* v is in kB/sec. We don't expect TiByte/sec yet. */ |
52 | if (unlikely(v >= 1000000)) { | 52 | if (unlikely(v >= 1000000)) { |
@@ -66,14 +66,14 @@ void seq_printf_with_thousands_grouping(struct seq_file *seq, long v) | |||
66 | * [=====>..............] 33.5% (23456/123456) | 66 | * [=====>..............] 33.5% (23456/123456) |
67 | * finish: 2:20:20 speed: 6,345 (6,456) K/sec | 67 | * finish: 2:20:20 speed: 6,345 (6,456) K/sec |
68 | */ | 68 | */ |
69 | static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq) | 69 | static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq) |
70 | { | 70 | { |
71 | unsigned long db, dt, dbdt, rt, rs_left; | 71 | unsigned long db, dt, dbdt, rt, rs_left; |
72 | unsigned int res; | 72 | unsigned int res; |
73 | int i, x, y; | 73 | int i, x, y; |
74 | int stalled = 0; | 74 | int stalled = 0; |
75 | 75 | ||
76 | drbd_get_syncer_progress(mdev, &rs_left, &res); | 76 | drbd_get_syncer_progress(device, &rs_left, &res); |
77 | 77 | ||
78 | x = res/50; | 78 | x = res/50; |
79 | y = 20-x; | 79 | y = 20-x; |
@@ -85,21 +85,21 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq) | |||
85 | seq_printf(seq, "."); | 85 | seq_printf(seq, "."); |
86 | seq_printf(seq, "] "); | 86 | seq_printf(seq, "] "); |
87 | 87 | ||
88 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) | 88 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
89 | seq_printf(seq, "verified:"); | 89 | seq_printf(seq, "verified:"); |
90 | else | 90 | else |
91 | seq_printf(seq, "sync'ed:"); | 91 | seq_printf(seq, "sync'ed:"); |
92 | seq_printf(seq, "%3u.%u%% ", res / 10, res % 10); | 92 | seq_printf(seq, "%3u.%u%% ", res / 10, res % 10); |
93 | 93 | ||
94 | /* if more than a few GB, display in MB */ | 94 | /* if more than a few GB, display in MB */ |
95 | if (mdev->rs_total > (4UL << (30 - BM_BLOCK_SHIFT))) | 95 | if (device->rs_total > (4UL << (30 - BM_BLOCK_SHIFT))) |
96 | seq_printf(seq, "(%lu/%lu)M", | 96 | seq_printf(seq, "(%lu/%lu)M", |
97 | (unsigned long) Bit2KB(rs_left >> 10), | 97 | (unsigned long) Bit2KB(rs_left >> 10), |
98 | (unsigned long) Bit2KB(mdev->rs_total >> 10)); | 98 | (unsigned long) Bit2KB(device->rs_total >> 10)); |
99 | else | 99 | else |
100 | seq_printf(seq, "(%lu/%lu)K\n\t", | 100 | seq_printf(seq, "(%lu/%lu)K\n\t", |
101 | (unsigned long) Bit2KB(rs_left), | 101 | (unsigned long) Bit2KB(rs_left), |
102 | (unsigned long) Bit2KB(mdev->rs_total)); | 102 | (unsigned long) Bit2KB(device->rs_total)); |
103 | 103 | ||
104 | /* see drivers/md/md.c | 104 | /* see drivers/md/md.c |
105 | * We do not want to overflow, so the order of operands and | 105 | * We do not want to overflow, so the order of operands and |
@@ -114,14 +114,14 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq) | |||
114 | * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at | 114 | * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at |
115 | * least DRBD_SYNC_MARK_STEP time before it will be modified. */ | 115 | * least DRBD_SYNC_MARK_STEP time before it will be modified. */ |
116 | /* ------------------------ ~18s average ------------------------ */ | 116 | /* ------------------------ ~18s average ------------------------ */ |
117 | i = (mdev->rs_last_mark + 2) % DRBD_SYNC_MARKS; | 117 | i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS; |
118 | dt = (jiffies - mdev->rs_mark_time[i]) / HZ; | 118 | dt = (jiffies - device->rs_mark_time[i]) / HZ; |
119 | if (dt > (DRBD_SYNC_MARK_STEP * DRBD_SYNC_MARKS)) | 119 | if (dt > (DRBD_SYNC_MARK_STEP * DRBD_SYNC_MARKS)) |
120 | stalled = 1; | 120 | stalled = 1; |
121 | 121 | ||
122 | if (!dt) | 122 | if (!dt) |
123 | dt++; | 123 | dt++; |
124 | db = mdev->rs_mark_left[i] - rs_left; | 124 | db = device->rs_mark_left[i] - rs_left; |
125 | rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */ | 125 | rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */ |
126 | 126 | ||
127 | seq_printf(seq, "finish: %lu:%02lu:%02lu", | 127 | seq_printf(seq, "finish: %lu:%02lu:%02lu", |
@@ -134,11 +134,11 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq) | |||
134 | /* ------------------------- ~3s average ------------------------ */ | 134 | /* ------------------------- ~3s average ------------------------ */ |
135 | if (proc_details >= 1) { | 135 | if (proc_details >= 1) { |
136 | /* this is what drbd_rs_should_slow_down() uses */ | 136 | /* this is what drbd_rs_should_slow_down() uses */ |
137 | i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; | 137 | i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
138 | dt = (jiffies - mdev->rs_mark_time[i]) / HZ; | 138 | dt = (jiffies - device->rs_mark_time[i]) / HZ; |
139 | if (!dt) | 139 | if (!dt) |
140 | dt++; | 140 | dt++; |
141 | db = mdev->rs_mark_left[i] - rs_left; | 141 | db = device->rs_mark_left[i] - rs_left; |
142 | dbdt = Bit2KB(db/dt); | 142 | dbdt = Bit2KB(db/dt); |
143 | seq_printf_with_thousands_grouping(seq, dbdt); | 143 | seq_printf_with_thousands_grouping(seq, dbdt); |
144 | seq_printf(seq, " -- "); | 144 | seq_printf(seq, " -- "); |
@@ -147,34 +147,34 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq) | |||
147 | /* --------------------- long term average ---------------------- */ | 147 | /* --------------------- long term average ---------------------- */ |
148 | /* mean speed since syncer started | 148 | /* mean speed since syncer started |
149 | * we do account for PausedSync periods */ | 149 | * we do account for PausedSync periods */ |
150 | dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ; | 150 | dt = (jiffies - device->rs_start - device->rs_paused) / HZ; |
151 | if (dt == 0) | 151 | if (dt == 0) |
152 | dt = 1; | 152 | dt = 1; |
153 | db = mdev->rs_total - rs_left; | 153 | db = device->rs_total - rs_left; |
154 | dbdt = Bit2KB(db/dt); | 154 | dbdt = Bit2KB(db/dt); |
155 | seq_printf_with_thousands_grouping(seq, dbdt); | 155 | seq_printf_with_thousands_grouping(seq, dbdt); |
156 | seq_printf(seq, ")"); | 156 | seq_printf(seq, ")"); |
157 | 157 | ||
158 | if (mdev->state.conn == C_SYNC_TARGET || | 158 | if (device->state.conn == C_SYNC_TARGET || |
159 | mdev->state.conn == C_VERIFY_S) { | 159 | device->state.conn == C_VERIFY_S) { |
160 | seq_printf(seq, " want: "); | 160 | seq_printf(seq, " want: "); |
161 | seq_printf_with_thousands_grouping(seq, mdev->c_sync_rate); | 161 | seq_printf_with_thousands_grouping(seq, device->c_sync_rate); |
162 | } | 162 | } |
163 | seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : ""); | 163 | seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : ""); |
164 | 164 | ||
165 | if (proc_details >= 1) { | 165 | if (proc_details >= 1) { |
166 | /* 64 bit: | 166 | /* 64 bit: |
167 | * we convert to sectors in the display below. */ | 167 | * we convert to sectors in the display below. */ |
168 | unsigned long bm_bits = drbd_bm_bits(mdev); | 168 | unsigned long bm_bits = drbd_bm_bits(device); |
169 | unsigned long bit_pos; | 169 | unsigned long bit_pos; |
170 | unsigned long long stop_sector = 0; | 170 | unsigned long long stop_sector = 0; |
171 | if (mdev->state.conn == C_VERIFY_S || | 171 | if (device->state.conn == C_VERIFY_S || |
172 | mdev->state.conn == C_VERIFY_T) { | 172 | device->state.conn == C_VERIFY_T) { |
173 | bit_pos = bm_bits - mdev->ov_left; | 173 | bit_pos = bm_bits - device->ov_left; |
174 | if (verify_can_do_stop_sector(mdev)) | 174 | if (verify_can_do_stop_sector(device)) |
175 | stop_sector = mdev->ov_stop_sector; | 175 | stop_sector = device->ov_stop_sector; |
176 | } else | 176 | } else |
177 | bit_pos = mdev->bm_resync_fo; | 177 | bit_pos = device->bm_resync_fo; |
178 | /* Total sectors may be slightly off for oddly | 178 | /* Total sectors may be slightly off for oddly |
179 | * sized devices. So what. */ | 179 | * sized devices. So what. */ |
180 | seq_printf(seq, | 180 | seq_printf(seq, |
@@ -202,7 +202,7 @@ static int drbd_seq_show(struct seq_file *seq, void *v) | |||
202 | { | 202 | { |
203 | int i, prev_i = -1; | 203 | int i, prev_i = -1; |
204 | const char *sn; | 204 | const char *sn; |
205 | struct drbd_conf *mdev; | 205 | struct drbd_device *device; |
206 | struct net_conf *nc; | 206 | struct net_conf *nc; |
207 | char wp; | 207 | char wp; |
208 | 208 | ||
@@ -236,72 +236,72 @@ static int drbd_seq_show(struct seq_file *seq, void *v) | |||
236 | */ | 236 | */ |
237 | 237 | ||
238 | rcu_read_lock(); | 238 | rcu_read_lock(); |
239 | idr_for_each_entry(&minors, mdev, i) { | 239 | idr_for_each_entry(&drbd_devices, device, i) { |
240 | if (prev_i != i - 1) | 240 | if (prev_i != i - 1) |
241 | seq_printf(seq, "\n"); | 241 | seq_printf(seq, "\n"); |
242 | prev_i = i; | 242 | prev_i = i; |
243 | 243 | ||
244 | sn = drbd_conn_str(mdev->state.conn); | 244 | sn = drbd_conn_str(device->state.conn); |
245 | 245 | ||
246 | if (mdev->state.conn == C_STANDALONE && | 246 | if (device->state.conn == C_STANDALONE && |
247 | mdev->state.disk == D_DISKLESS && | 247 | device->state.disk == D_DISKLESS && |
248 | mdev->state.role == R_SECONDARY) { | 248 | device->state.role == R_SECONDARY) { |
249 | seq_printf(seq, "%2d: cs:Unconfigured\n", i); | 249 | seq_printf(seq, "%2d: cs:Unconfigured\n", i); |
250 | } else { | 250 | } else { |
251 | /* reset mdev->congestion_reason */ | 251 | /* reset device->congestion_reason */ |
252 | bdi_rw_congested(&mdev->rq_queue->backing_dev_info); | 252 | bdi_rw_congested(&device->rq_queue->backing_dev_info); |
253 | 253 | ||
254 | nc = rcu_dereference(mdev->tconn->net_conf); | 254 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
255 | wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' '; | 255 | wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' '; |
256 | seq_printf(seq, | 256 | seq_printf(seq, |
257 | "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n" | 257 | "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n" |
258 | " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u " | 258 | " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u " |
259 | "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c", | 259 | "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c", |
260 | i, sn, | 260 | i, sn, |
261 | drbd_role_str(mdev->state.role), | 261 | drbd_role_str(device->state.role), |
262 | drbd_role_str(mdev->state.peer), | 262 | drbd_role_str(device->state.peer), |
263 | drbd_disk_str(mdev->state.disk), | 263 | drbd_disk_str(device->state.disk), |
264 | drbd_disk_str(mdev->state.pdsk), | 264 | drbd_disk_str(device->state.pdsk), |
265 | wp, | 265 | wp, |
266 | drbd_suspended(mdev) ? 's' : 'r', | 266 | drbd_suspended(device) ? 's' : 'r', |
267 | mdev->state.aftr_isp ? 'a' : '-', | 267 | device->state.aftr_isp ? 'a' : '-', |
268 | mdev->state.peer_isp ? 'p' : '-', | 268 | device->state.peer_isp ? 'p' : '-', |
269 | mdev->state.user_isp ? 'u' : '-', | 269 | device->state.user_isp ? 'u' : '-', |
270 | mdev->congestion_reason ?: '-', | 270 | device->congestion_reason ?: '-', |
271 | test_bit(AL_SUSPENDED, &mdev->flags) ? 's' : '-', | 271 | test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-', |
272 | mdev->send_cnt/2, | 272 | device->send_cnt/2, |
273 | mdev->recv_cnt/2, | 273 | device->recv_cnt/2, |
274 | mdev->writ_cnt/2, | 274 | device->writ_cnt/2, |
275 | mdev->read_cnt/2, | 275 | device->read_cnt/2, |
276 | mdev->al_writ_cnt, | 276 | device->al_writ_cnt, |
277 | mdev->bm_writ_cnt, | 277 | device->bm_writ_cnt, |
278 | atomic_read(&mdev->local_cnt), | 278 | atomic_read(&device->local_cnt), |
279 | atomic_read(&mdev->ap_pending_cnt) + | 279 | atomic_read(&device->ap_pending_cnt) + |
280 | atomic_read(&mdev->rs_pending_cnt), | 280 | atomic_read(&device->rs_pending_cnt), |
281 | atomic_read(&mdev->unacked_cnt), | 281 | atomic_read(&device->unacked_cnt), |
282 | atomic_read(&mdev->ap_bio_cnt), | 282 | atomic_read(&device->ap_bio_cnt), |
283 | mdev->tconn->epochs, | 283 | first_peer_device(device)->connection->epochs, |
284 | write_ordering_chars[mdev->tconn->write_ordering] | 284 | write_ordering_chars[first_peer_device(device)->connection->write_ordering] |
285 | ); | 285 | ); |
286 | seq_printf(seq, " oos:%llu\n", | 286 | seq_printf(seq, " oos:%llu\n", |
287 | Bit2KB((unsigned long long) | 287 | Bit2KB((unsigned long long) |
288 | drbd_bm_total_weight(mdev))); | 288 | drbd_bm_total_weight(device))); |
289 | } | 289 | } |
290 | if (mdev->state.conn == C_SYNC_SOURCE || | 290 | if (device->state.conn == C_SYNC_SOURCE || |
291 | mdev->state.conn == C_SYNC_TARGET || | 291 | device->state.conn == C_SYNC_TARGET || |
292 | mdev->state.conn == C_VERIFY_S || | 292 | device->state.conn == C_VERIFY_S || |
293 | mdev->state.conn == C_VERIFY_T) | 293 | device->state.conn == C_VERIFY_T) |
294 | drbd_syncer_progress(mdev, seq); | 294 | drbd_syncer_progress(device, seq); |
295 | 295 | ||
296 | if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) { | 296 | if (proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) { |
297 | lc_seq_printf_stats(seq, mdev->resync); | 297 | lc_seq_printf_stats(seq, device->resync); |
298 | lc_seq_printf_stats(seq, mdev->act_log); | 298 | lc_seq_printf_stats(seq, device->act_log); |
299 | put_ldev(mdev); | 299 | put_ldev(device); |
300 | } | 300 | } |
301 | 301 | ||
302 | if (proc_details >= 2) { | 302 | if (proc_details >= 2) { |
303 | if (mdev->resync) { | 303 | if (device->resync) { |
304 | lc_seq_dump_details(seq, mdev->resync, "rs_left", | 304 | lc_seq_dump_details(seq, device->resync, "rs_left", |
305 | resync_dump_detail); | 305 | resync_dump_detail); |
306 | } | 306 | } |
307 | } | 307 | } |
diff --git a/drivers/block/drbd/drbd_protocol.h b/drivers/block/drbd/drbd_protocol.h new file mode 100644 index 000000000000..3c04ec0ea333 --- /dev/null +++ b/drivers/block/drbd/drbd_protocol.h | |||
@@ -0,0 +1,295 @@ | |||
1 | #ifndef __DRBD_PROTOCOL_H | ||
2 | #define __DRBD_PROTOCOL_H | ||
3 | |||
4 | enum drbd_packet { | ||
5 | /* receiver (data socket) */ | ||
6 | P_DATA = 0x00, | ||
7 | P_DATA_REPLY = 0x01, /* Response to P_DATA_REQUEST */ | ||
8 | P_RS_DATA_REPLY = 0x02, /* Response to P_RS_DATA_REQUEST */ | ||
9 | P_BARRIER = 0x03, | ||
10 | P_BITMAP = 0x04, | ||
11 | P_BECOME_SYNC_TARGET = 0x05, | ||
12 | P_BECOME_SYNC_SOURCE = 0x06, | ||
13 | P_UNPLUG_REMOTE = 0x07, /* Used at various times to hint the peer */ | ||
14 | P_DATA_REQUEST = 0x08, /* Used to ask for a data block */ | ||
15 | P_RS_DATA_REQUEST = 0x09, /* Used to ask for a data block for resync */ | ||
16 | P_SYNC_PARAM = 0x0a, | ||
17 | P_PROTOCOL = 0x0b, | ||
18 | P_UUIDS = 0x0c, | ||
19 | P_SIZES = 0x0d, | ||
20 | P_STATE = 0x0e, | ||
21 | P_SYNC_UUID = 0x0f, | ||
22 | P_AUTH_CHALLENGE = 0x10, | ||
23 | P_AUTH_RESPONSE = 0x11, | ||
24 | P_STATE_CHG_REQ = 0x12, | ||
25 | |||
26 | /* asender (meta socket */ | ||
27 | P_PING = 0x13, | ||
28 | P_PING_ACK = 0x14, | ||
29 | P_RECV_ACK = 0x15, /* Used in protocol B */ | ||
30 | P_WRITE_ACK = 0x16, /* Used in protocol C */ | ||
31 | P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */ | ||
32 | P_SUPERSEDED = 0x18, /* Used in proto C, two-primaries conflict detection */ | ||
33 | P_NEG_ACK = 0x19, /* Sent if local disk is unusable */ | ||
34 | P_NEG_DREPLY = 0x1a, /* Local disk is broken... */ | ||
35 | P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */ | ||
36 | P_BARRIER_ACK = 0x1c, | ||
37 | P_STATE_CHG_REPLY = 0x1d, | ||
38 | |||
39 | /* "new" commands, no longer fitting into the ordering scheme above */ | ||
40 | |||
41 | P_OV_REQUEST = 0x1e, /* data socket */ | ||
42 | P_OV_REPLY = 0x1f, | ||
43 | P_OV_RESULT = 0x20, /* meta socket */ | ||
44 | P_CSUM_RS_REQUEST = 0x21, /* data socket */ | ||
45 | P_RS_IS_IN_SYNC = 0x22, /* meta socket */ | ||
46 | P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */ | ||
47 | P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */ | ||
48 | /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */ | ||
49 | /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */ | ||
50 | P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */ | ||
51 | P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */ | ||
52 | P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */ | ||
53 | P_CONN_ST_CHG_REQ = 0x2a, /* data sock: Connection wide state request */ | ||
54 | P_CONN_ST_CHG_REPLY = 0x2b, /* meta sock: Connection side state req reply */ | ||
55 | P_RETRY_WRITE = 0x2c, /* Protocol C: retry conflicting write request */ | ||
56 | P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */ | ||
57 | |||
58 | P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */ | ||
59 | P_MAX_OPT_CMD = 0x101, | ||
60 | |||
61 | /* special command ids for handshake */ | ||
62 | |||
63 | P_INITIAL_META = 0xfff1, /* First Packet on the MetaSock */ | ||
64 | P_INITIAL_DATA = 0xfff2, /* First Packet on the Socket */ | ||
65 | |||
66 | P_CONNECTION_FEATURES = 0xfffe /* FIXED for the next century! */ | ||
67 | }; | ||
68 | |||
69 | #ifndef __packed | ||
70 | #define __packed __attribute__((packed)) | ||
71 | #endif | ||
72 | |||
73 | /* This is the layout for a packet on the wire. | ||
74 | * The byteorder is the network byte order. | ||
75 | * (except block_id and barrier fields. | ||
76 | * these are pointers to local structs | ||
77 | * and have no relevance for the partner, | ||
78 | * which just echoes them as received.) | ||
79 | * | ||
80 | * NOTE that the payload starts at a long aligned offset, | ||
81 | * regardless of 32 or 64 bit arch! | ||
82 | */ | ||
83 | struct p_header80 { | ||
84 | u32 magic; | ||
85 | u16 command; | ||
86 | u16 length; /* bytes of data after this header */ | ||
87 | } __packed; | ||
88 | |||
89 | /* Header for big packets, Used for data packets exceeding 64kB */ | ||
90 | struct p_header95 { | ||
91 | u16 magic; /* use DRBD_MAGIC_BIG here */ | ||
92 | u16 command; | ||
93 | u32 length; | ||
94 | } __packed; | ||
95 | |||
96 | struct p_header100 { | ||
97 | u32 magic; | ||
98 | u16 volume; | ||
99 | u16 command; | ||
100 | u32 length; | ||
101 | u32 pad; | ||
102 | } __packed; | ||
103 | |||
104 | /* these defines must not be changed without changing the protocol version */ | ||
105 | #define DP_HARDBARRIER 1 /* depricated */ | ||
106 | #define DP_RW_SYNC 2 /* equals REQ_SYNC */ | ||
107 | #define DP_MAY_SET_IN_SYNC 4 | ||
108 | #define DP_UNPLUG 8 /* not used anymore */ | ||
109 | #define DP_FUA 16 /* equals REQ_FUA */ | ||
110 | #define DP_FLUSH 32 /* equals REQ_FLUSH */ | ||
111 | #define DP_DISCARD 64 /* equals REQ_DISCARD */ | ||
112 | #define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */ | ||
113 | #define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */ | ||
114 | |||
115 | struct p_data { | ||
116 | u64 sector; /* 64 bits sector number */ | ||
117 | u64 block_id; /* to identify the request in protocol B&C */ | ||
118 | u32 seq_num; | ||
119 | u32 dp_flags; | ||
120 | } __packed; | ||
121 | |||
122 | /* | ||
123 | * commands which share a struct: | ||
124 | * p_block_ack: | ||
125 | * P_RECV_ACK (proto B), P_WRITE_ACK (proto C), | ||
126 | * P_SUPERSEDED (proto C, two-primaries conflict detection) | ||
127 | * p_block_req: | ||
128 | * P_DATA_REQUEST, P_RS_DATA_REQUEST | ||
129 | */ | ||
130 | struct p_block_ack { | ||
131 | u64 sector; | ||
132 | u64 block_id; | ||
133 | u32 blksize; | ||
134 | u32 seq_num; | ||
135 | } __packed; | ||
136 | |||
137 | struct p_block_req { | ||
138 | u64 sector; | ||
139 | u64 block_id; | ||
140 | u32 blksize; | ||
141 | u32 pad; /* to multiple of 8 Byte */ | ||
142 | } __packed; | ||
143 | |||
144 | /* | ||
145 | * commands with their own struct for additional fields: | ||
146 | * P_CONNECTION_FEATURES | ||
147 | * P_BARRIER | ||
148 | * P_BARRIER_ACK | ||
149 | * P_SYNC_PARAM | ||
150 | * ReportParams | ||
151 | */ | ||
152 | |||
153 | struct p_connection_features { | ||
154 | u32 protocol_min; | ||
155 | u32 feature_flags; | ||
156 | u32 protocol_max; | ||
157 | |||
158 | /* should be more than enough for future enhancements | ||
159 | * for now, feature_flags and the reserved array shall be zero. | ||
160 | */ | ||
161 | |||
162 | u32 _pad; | ||
163 | u64 reserved[7]; | ||
164 | } __packed; | ||
165 | |||
166 | struct p_barrier { | ||
167 | u32 barrier; /* barrier number _handle_ only */ | ||
168 | u32 pad; /* to multiple of 8 Byte */ | ||
169 | } __packed; | ||
170 | |||
171 | struct p_barrier_ack { | ||
172 | u32 barrier; | ||
173 | u32 set_size; | ||
174 | } __packed; | ||
175 | |||
176 | struct p_rs_param { | ||
177 | u32 resync_rate; | ||
178 | |||
179 | /* Since protocol version 88 and higher. */ | ||
180 | char verify_alg[0]; | ||
181 | } __packed; | ||
182 | |||
183 | struct p_rs_param_89 { | ||
184 | u32 resync_rate; | ||
185 | /* protocol version 89: */ | ||
186 | char verify_alg[SHARED_SECRET_MAX]; | ||
187 | char csums_alg[SHARED_SECRET_MAX]; | ||
188 | } __packed; | ||
189 | |||
190 | struct p_rs_param_95 { | ||
191 | u32 resync_rate; | ||
192 | char verify_alg[SHARED_SECRET_MAX]; | ||
193 | char csums_alg[SHARED_SECRET_MAX]; | ||
194 | u32 c_plan_ahead; | ||
195 | u32 c_delay_target; | ||
196 | u32 c_fill_target; | ||
197 | u32 c_max_rate; | ||
198 | } __packed; | ||
199 | |||
200 | enum drbd_conn_flags { | ||
201 | CF_DISCARD_MY_DATA = 1, | ||
202 | CF_DRY_RUN = 2, | ||
203 | }; | ||
204 | |||
205 | struct p_protocol { | ||
206 | u32 protocol; | ||
207 | u32 after_sb_0p; | ||
208 | u32 after_sb_1p; | ||
209 | u32 after_sb_2p; | ||
210 | u32 conn_flags; | ||
211 | u32 two_primaries; | ||
212 | |||
213 | /* Since protocol version 87 and higher. */ | ||
214 | char integrity_alg[0]; | ||
215 | |||
216 | } __packed; | ||
217 | |||
218 | struct p_uuids { | ||
219 | u64 uuid[UI_EXTENDED_SIZE]; | ||
220 | } __packed; | ||
221 | |||
222 | struct p_rs_uuid { | ||
223 | u64 uuid; | ||
224 | } __packed; | ||
225 | |||
226 | struct p_sizes { | ||
227 | u64 d_size; /* size of disk */ | ||
228 | u64 u_size; /* user requested size */ | ||
229 | u64 c_size; /* current exported size */ | ||
230 | u32 max_bio_size; /* Maximal size of a BIO */ | ||
231 | u16 queue_order_type; /* not yet implemented in DRBD*/ | ||
232 | u16 dds_flags; /* use enum dds_flags here. */ | ||
233 | } __packed; | ||
234 | |||
235 | struct p_state { | ||
236 | u32 state; | ||
237 | } __packed; | ||
238 | |||
239 | struct p_req_state { | ||
240 | u32 mask; | ||
241 | u32 val; | ||
242 | } __packed; | ||
243 | |||
244 | struct p_req_state_reply { | ||
245 | u32 retcode; | ||
246 | } __packed; | ||
247 | |||
248 | struct p_drbd06_param { | ||
249 | u64 size; | ||
250 | u32 state; | ||
251 | u32 blksize; | ||
252 | u32 protocol; | ||
253 | u32 version; | ||
254 | u32 gen_cnt[5]; | ||
255 | u32 bit_map_gen[5]; | ||
256 | } __packed; | ||
257 | |||
258 | struct p_block_desc { | ||
259 | u64 sector; | ||
260 | u32 blksize; | ||
261 | u32 pad; /* to multiple of 8 Byte */ | ||
262 | } __packed; | ||
263 | |||
264 | /* Valid values for the encoding field. | ||
265 | * Bump proto version when changing this. */ | ||
266 | enum drbd_bitmap_code { | ||
267 | /* RLE_VLI_Bytes = 0, | ||
268 | * and other bit variants had been defined during | ||
269 | * algorithm evaluation. */ | ||
270 | RLE_VLI_Bits = 2, | ||
271 | }; | ||
272 | |||
273 | struct p_compressed_bm { | ||
274 | /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code | ||
275 | * (encoding & 0x80): polarity (set/unset) of first runlength | ||
276 | * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits | ||
277 | * used to pad up to head.length bytes | ||
278 | */ | ||
279 | u8 encoding; | ||
280 | |||
281 | u8 code[0]; | ||
282 | } __packed; | ||
283 | |||
284 | struct p_delay_probe93 { | ||
285 | u32 seq_num; /* sequence number to match the two probe packets */ | ||
286 | u32 offset; /* usecs the probe got sent after the reference time point */ | ||
287 | } __packed; | ||
288 | |||
289 | /* | ||
290 | * Bitmap packets need to fit within a single page on the sender and receiver, | ||
291 | * so we are limited to 4 KiB (and not to PAGE_SIZE, which can be bigger). | ||
292 | */ | ||
293 | #define DRBD_SOCKET_BUFFER_SIZE 4096 | ||
294 | |||
295 | #endif /* __DRBD_PROTOCOL_H */ | ||
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c index d073305ffd5e..18c76e84d540 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/string.h> | 44 | #include <linux/string.h> |
45 | #include <linux/scatterlist.h> | 45 | #include <linux/scatterlist.h> |
46 | #include "drbd_int.h" | 46 | #include "drbd_int.h" |
47 | #include "drbd_protocol.h" | ||
47 | #include "drbd_req.h" | 48 | #include "drbd_req.h" |
48 | 49 | ||
49 | #include "drbd_vli.h" | 50 | #include "drbd_vli.h" |
@@ -61,11 +62,11 @@ enum finish_epoch { | |||
61 | FE_RECYCLED, | 62 | FE_RECYCLED, |
62 | }; | 63 | }; |
63 | 64 | ||
64 | static int drbd_do_features(struct drbd_tconn *tconn); | 65 | static int drbd_do_features(struct drbd_connection *connection); |
65 | static int drbd_do_auth(struct drbd_tconn *tconn); | 66 | static int drbd_do_auth(struct drbd_connection *connection); |
66 | static int drbd_disconnected(struct drbd_conf *mdev); | 67 | static int drbd_disconnected(struct drbd_peer_device *); |
67 | 68 | ||
68 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *, struct drbd_epoch *, enum epoch_event); | 69 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *, struct drbd_epoch *, enum epoch_event); |
69 | static int e_end_block(struct drbd_work *, int); | 70 | static int e_end_block(struct drbd_work *, int); |
70 | 71 | ||
71 | 72 | ||
@@ -150,7 +151,7 @@ static void page_chain_add(struct page **head, | |||
150 | *head = chain_first; | 151 | *head = chain_first; |
151 | } | 152 | } |
152 | 153 | ||
153 | static struct page *__drbd_alloc_pages(struct drbd_conf *mdev, | 154 | static struct page *__drbd_alloc_pages(struct drbd_device *device, |
154 | unsigned int number) | 155 | unsigned int number) |
155 | { | 156 | { |
156 | struct page *page = NULL; | 157 | struct page *page = NULL; |
@@ -196,41 +197,39 @@ static struct page *__drbd_alloc_pages(struct drbd_conf *mdev, | |||
196 | return NULL; | 197 | return NULL; |
197 | } | 198 | } |
198 | 199 | ||
199 | static void reclaim_finished_net_peer_reqs(struct drbd_conf *mdev, | 200 | static void reclaim_finished_net_peer_reqs(struct drbd_device *device, |
200 | struct list_head *to_be_freed) | 201 | struct list_head *to_be_freed) |
201 | { | 202 | { |
202 | struct drbd_peer_request *peer_req; | 203 | struct drbd_peer_request *peer_req, *tmp; |
203 | struct list_head *le, *tle; | ||
204 | 204 | ||
205 | /* The EEs are always appended to the end of the list. Since | 205 | /* The EEs are always appended to the end of the list. Since |
206 | they are sent in order over the wire, they have to finish | 206 | they are sent in order over the wire, they have to finish |
207 | in order. As soon as we see the first not finished we can | 207 | in order. As soon as we see the first not finished we can |
208 | stop to examine the list... */ | 208 | stop to examine the list... */ |
209 | 209 | ||
210 | list_for_each_safe(le, tle, &mdev->net_ee) { | 210 | list_for_each_entry_safe(peer_req, tmp, &device->net_ee, w.list) { |
211 | peer_req = list_entry(le, struct drbd_peer_request, w.list); | ||
212 | if (drbd_peer_req_has_active_page(peer_req)) | 211 | if (drbd_peer_req_has_active_page(peer_req)) |
213 | break; | 212 | break; |
214 | list_move(le, to_be_freed); | 213 | list_move(&peer_req->w.list, to_be_freed); |
215 | } | 214 | } |
216 | } | 215 | } |
217 | 216 | ||
218 | static void drbd_kick_lo_and_reclaim_net(struct drbd_conf *mdev) | 217 | static void drbd_kick_lo_and_reclaim_net(struct drbd_device *device) |
219 | { | 218 | { |
220 | LIST_HEAD(reclaimed); | 219 | LIST_HEAD(reclaimed); |
221 | struct drbd_peer_request *peer_req, *t; | 220 | struct drbd_peer_request *peer_req, *t; |
222 | 221 | ||
223 | spin_lock_irq(&mdev->tconn->req_lock); | 222 | spin_lock_irq(&device->resource->req_lock); |
224 | reclaim_finished_net_peer_reqs(mdev, &reclaimed); | 223 | reclaim_finished_net_peer_reqs(device, &reclaimed); |
225 | spin_unlock_irq(&mdev->tconn->req_lock); | 224 | spin_unlock_irq(&device->resource->req_lock); |
226 | 225 | ||
227 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) | 226 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
228 | drbd_free_net_peer_req(mdev, peer_req); | 227 | drbd_free_net_peer_req(device, peer_req); |
229 | } | 228 | } |
230 | 229 | ||
231 | /** | 230 | /** |
232 | * drbd_alloc_pages() - Returns @number pages, retries forever (or until signalled) | 231 | * drbd_alloc_pages() - Returns @number pages, retries forever (or until signalled) |
233 | * @mdev: DRBD device. | 232 | * @device: DRBD device. |
234 | * @number: number of pages requested | 233 | * @number: number of pages requested |
235 | * @retry: whether to retry, if not enough pages are available right now | 234 | * @retry: whether to retry, if not enough pages are available right now |
236 | * | 235 | * |
@@ -240,9 +239,10 @@ static void drbd_kick_lo_and_reclaim_net(struct drbd_conf *mdev) | |||
240 | * | 239 | * |
241 | * Returns a page chain linked via page->private. | 240 | * Returns a page chain linked via page->private. |
242 | */ | 241 | */ |
243 | struct page *drbd_alloc_pages(struct drbd_conf *mdev, unsigned int number, | 242 | struct page *drbd_alloc_pages(struct drbd_peer_device *peer_device, unsigned int number, |
244 | bool retry) | 243 | bool retry) |
245 | { | 244 | { |
245 | struct drbd_device *device = peer_device->device; | ||
246 | struct page *page = NULL; | 246 | struct page *page = NULL; |
247 | struct net_conf *nc; | 247 | struct net_conf *nc; |
248 | DEFINE_WAIT(wait); | 248 | DEFINE_WAIT(wait); |
@@ -251,20 +251,20 @@ struct page *drbd_alloc_pages(struct drbd_conf *mdev, unsigned int number, | |||
251 | /* Yes, we may run up to @number over max_buffers. If we | 251 | /* Yes, we may run up to @number over max_buffers. If we |
252 | * follow it strictly, the admin will get it wrong anyways. */ | 252 | * follow it strictly, the admin will get it wrong anyways. */ |
253 | rcu_read_lock(); | 253 | rcu_read_lock(); |
254 | nc = rcu_dereference(mdev->tconn->net_conf); | 254 | nc = rcu_dereference(peer_device->connection->net_conf); |
255 | mxb = nc ? nc->max_buffers : 1000000; | 255 | mxb = nc ? nc->max_buffers : 1000000; |
256 | rcu_read_unlock(); | 256 | rcu_read_unlock(); |
257 | 257 | ||
258 | if (atomic_read(&mdev->pp_in_use) < mxb) | 258 | if (atomic_read(&device->pp_in_use) < mxb) |
259 | page = __drbd_alloc_pages(mdev, number); | 259 | page = __drbd_alloc_pages(device, number); |
260 | 260 | ||
261 | while (page == NULL) { | 261 | while (page == NULL) { |
262 | prepare_to_wait(&drbd_pp_wait, &wait, TASK_INTERRUPTIBLE); | 262 | prepare_to_wait(&drbd_pp_wait, &wait, TASK_INTERRUPTIBLE); |
263 | 263 | ||
264 | drbd_kick_lo_and_reclaim_net(mdev); | 264 | drbd_kick_lo_and_reclaim_net(device); |
265 | 265 | ||
266 | if (atomic_read(&mdev->pp_in_use) < mxb) { | 266 | if (atomic_read(&device->pp_in_use) < mxb) { |
267 | page = __drbd_alloc_pages(mdev, number); | 267 | page = __drbd_alloc_pages(device, number); |
268 | if (page) | 268 | if (page) |
269 | break; | 269 | break; |
270 | } | 270 | } |
@@ -273,7 +273,7 @@ struct page *drbd_alloc_pages(struct drbd_conf *mdev, unsigned int number, | |||
273 | break; | 273 | break; |
274 | 274 | ||
275 | if (signal_pending(current)) { | 275 | if (signal_pending(current)) { |
276 | dev_warn(DEV, "drbd_alloc_pages interrupted!\n"); | 276 | drbd_warn(device, "drbd_alloc_pages interrupted!\n"); |
277 | break; | 277 | break; |
278 | } | 278 | } |
279 | 279 | ||
@@ -282,17 +282,17 @@ struct page *drbd_alloc_pages(struct drbd_conf *mdev, unsigned int number, | |||
282 | finish_wait(&drbd_pp_wait, &wait); | 282 | finish_wait(&drbd_pp_wait, &wait); |
283 | 283 | ||
284 | if (page) | 284 | if (page) |
285 | atomic_add(number, &mdev->pp_in_use); | 285 | atomic_add(number, &device->pp_in_use); |
286 | return page; | 286 | return page; |
287 | } | 287 | } |
288 | 288 | ||
289 | /* Must not be used from irq, as that may deadlock: see drbd_alloc_pages. | 289 | /* Must not be used from irq, as that may deadlock: see drbd_alloc_pages. |
290 | * Is also used from inside an other spin_lock_irq(&mdev->tconn->req_lock); | 290 | * Is also used from inside an other spin_lock_irq(&resource->req_lock); |
291 | * Either links the page chain back to the global pool, | 291 | * Either links the page chain back to the global pool, |
292 | * or returns all pages to the system. */ | 292 | * or returns all pages to the system. */ |
293 | static void drbd_free_pages(struct drbd_conf *mdev, struct page *page, int is_net) | 293 | static void drbd_free_pages(struct drbd_device *device, struct page *page, int is_net) |
294 | { | 294 | { |
295 | atomic_t *a = is_net ? &mdev->pp_in_use_by_net : &mdev->pp_in_use; | 295 | atomic_t *a = is_net ? &device->pp_in_use_by_net : &device->pp_in_use; |
296 | int i; | 296 | int i; |
297 | 297 | ||
298 | if (page == NULL) | 298 | if (page == NULL) |
@@ -310,7 +310,7 @@ static void drbd_free_pages(struct drbd_conf *mdev, struct page *page, int is_ne | |||
310 | } | 310 | } |
311 | i = atomic_sub_return(i, a); | 311 | i = atomic_sub_return(i, a); |
312 | if (i < 0) | 312 | if (i < 0) |
313 | dev_warn(DEV, "ASSERTION FAILED: %s: %d < 0\n", | 313 | drbd_warn(device, "ASSERTION FAILED: %s: %d < 0\n", |
314 | is_net ? "pp_in_use_by_net" : "pp_in_use", i); | 314 | is_net ? "pp_in_use_by_net" : "pp_in_use", i); |
315 | wake_up(&drbd_pp_wait); | 315 | wake_up(&drbd_pp_wait); |
316 | } | 316 | } |
@@ -330,25 +330,26 @@ You must not have the req_lock: | |||
330 | */ | 330 | */ |
331 | 331 | ||
332 | struct drbd_peer_request * | 332 | struct drbd_peer_request * |
333 | drbd_alloc_peer_req(struct drbd_conf *mdev, u64 id, sector_t sector, | 333 | drbd_alloc_peer_req(struct drbd_peer_device *peer_device, u64 id, sector_t sector, |
334 | unsigned int data_size, gfp_t gfp_mask) __must_hold(local) | 334 | unsigned int data_size, gfp_t gfp_mask) __must_hold(local) |
335 | { | 335 | { |
336 | struct drbd_device *device = peer_device->device; | ||
336 | struct drbd_peer_request *peer_req; | 337 | struct drbd_peer_request *peer_req; |
337 | struct page *page = NULL; | 338 | struct page *page = NULL; |
338 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; | 339 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; |
339 | 340 | ||
340 | if (drbd_insert_fault(mdev, DRBD_FAULT_AL_EE)) | 341 | if (drbd_insert_fault(device, DRBD_FAULT_AL_EE)) |
341 | return NULL; | 342 | return NULL; |
342 | 343 | ||
343 | peer_req = mempool_alloc(drbd_ee_mempool, gfp_mask & ~__GFP_HIGHMEM); | 344 | peer_req = mempool_alloc(drbd_ee_mempool, gfp_mask & ~__GFP_HIGHMEM); |
344 | if (!peer_req) { | 345 | if (!peer_req) { |
345 | if (!(gfp_mask & __GFP_NOWARN)) | 346 | if (!(gfp_mask & __GFP_NOWARN)) |
346 | dev_err(DEV, "%s: allocation failed\n", __func__); | 347 | drbd_err(device, "%s: allocation failed\n", __func__); |
347 | return NULL; | 348 | return NULL; |
348 | } | 349 | } |
349 | 350 | ||
350 | if (data_size) { | 351 | if (data_size) { |
351 | page = drbd_alloc_pages(mdev, nr_pages, (gfp_mask & __GFP_WAIT)); | 352 | page = drbd_alloc_pages(peer_device, nr_pages, (gfp_mask & __GFP_WAIT)); |
352 | if (!page) | 353 | if (!page) |
353 | goto fail; | 354 | goto fail; |
354 | } | 355 | } |
@@ -360,7 +361,7 @@ drbd_alloc_peer_req(struct drbd_conf *mdev, u64 id, sector_t sector, | |||
360 | peer_req->i.waiting = false; | 361 | peer_req->i.waiting = false; |
361 | 362 | ||
362 | peer_req->epoch = NULL; | 363 | peer_req->epoch = NULL; |
363 | peer_req->w.mdev = mdev; | 364 | peer_req->peer_device = peer_device; |
364 | peer_req->pages = page; | 365 | peer_req->pages = page; |
365 | atomic_set(&peer_req->pending_bios, 0); | 366 | atomic_set(&peer_req->pending_bios, 0); |
366 | peer_req->flags = 0; | 367 | peer_req->flags = 0; |
@@ -377,30 +378,30 @@ drbd_alloc_peer_req(struct drbd_conf *mdev, u64 id, sector_t sector, | |||
377 | return NULL; | 378 | return NULL; |
378 | } | 379 | } |
379 | 380 | ||
380 | void __drbd_free_peer_req(struct drbd_conf *mdev, struct drbd_peer_request *peer_req, | 381 | void __drbd_free_peer_req(struct drbd_device *device, struct drbd_peer_request *peer_req, |
381 | int is_net) | 382 | int is_net) |
382 | { | 383 | { |
383 | if (peer_req->flags & EE_HAS_DIGEST) | 384 | if (peer_req->flags & EE_HAS_DIGEST) |
384 | kfree(peer_req->digest); | 385 | kfree(peer_req->digest); |
385 | drbd_free_pages(mdev, peer_req->pages, is_net); | 386 | drbd_free_pages(device, peer_req->pages, is_net); |
386 | D_ASSERT(atomic_read(&peer_req->pending_bios) == 0); | 387 | D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0); |
387 | D_ASSERT(drbd_interval_empty(&peer_req->i)); | 388 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
388 | mempool_free(peer_req, drbd_ee_mempool); | 389 | mempool_free(peer_req, drbd_ee_mempool); |
389 | } | 390 | } |
390 | 391 | ||
391 | int drbd_free_peer_reqs(struct drbd_conf *mdev, struct list_head *list) | 392 | int drbd_free_peer_reqs(struct drbd_device *device, struct list_head *list) |
392 | { | 393 | { |
393 | LIST_HEAD(work_list); | 394 | LIST_HEAD(work_list); |
394 | struct drbd_peer_request *peer_req, *t; | 395 | struct drbd_peer_request *peer_req, *t; |
395 | int count = 0; | 396 | int count = 0; |
396 | int is_net = list == &mdev->net_ee; | 397 | int is_net = list == &device->net_ee; |
397 | 398 | ||
398 | spin_lock_irq(&mdev->tconn->req_lock); | 399 | spin_lock_irq(&device->resource->req_lock); |
399 | list_splice_init(list, &work_list); | 400 | list_splice_init(list, &work_list); |
400 | spin_unlock_irq(&mdev->tconn->req_lock); | 401 | spin_unlock_irq(&device->resource->req_lock); |
401 | 402 | ||
402 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { | 403 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
403 | __drbd_free_peer_req(mdev, peer_req, is_net); | 404 | __drbd_free_peer_req(device, peer_req, is_net); |
404 | count++; | 405 | count++; |
405 | } | 406 | } |
406 | return count; | 407 | return count; |
@@ -409,20 +410,20 @@ int drbd_free_peer_reqs(struct drbd_conf *mdev, struct list_head *list) | |||
409 | /* | 410 | /* |
410 | * See also comments in _req_mod(,BARRIER_ACKED) and receive_Barrier. | 411 | * See also comments in _req_mod(,BARRIER_ACKED) and receive_Barrier. |
411 | */ | 412 | */ |
412 | static int drbd_finish_peer_reqs(struct drbd_conf *mdev) | 413 | static int drbd_finish_peer_reqs(struct drbd_device *device) |
413 | { | 414 | { |
414 | LIST_HEAD(work_list); | 415 | LIST_HEAD(work_list); |
415 | LIST_HEAD(reclaimed); | 416 | LIST_HEAD(reclaimed); |
416 | struct drbd_peer_request *peer_req, *t; | 417 | struct drbd_peer_request *peer_req, *t; |
417 | int err = 0; | 418 | int err = 0; |
418 | 419 | ||
419 | spin_lock_irq(&mdev->tconn->req_lock); | 420 | spin_lock_irq(&device->resource->req_lock); |
420 | reclaim_finished_net_peer_reqs(mdev, &reclaimed); | 421 | reclaim_finished_net_peer_reqs(device, &reclaimed); |
421 | list_splice_init(&mdev->done_ee, &work_list); | 422 | list_splice_init(&device->done_ee, &work_list); |
422 | spin_unlock_irq(&mdev->tconn->req_lock); | 423 | spin_unlock_irq(&device->resource->req_lock); |
423 | 424 | ||
424 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) | 425 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
425 | drbd_free_net_peer_req(mdev, peer_req); | 426 | drbd_free_net_peer_req(device, peer_req); |
426 | 427 | ||
427 | /* possible callbacks here: | 428 | /* possible callbacks here: |
428 | * e_end_block, and e_end_resync_block, e_send_superseded. | 429 | * e_end_block, and e_end_resync_block, e_send_superseded. |
@@ -435,14 +436,14 @@ static int drbd_finish_peer_reqs(struct drbd_conf *mdev) | |||
435 | err2 = peer_req->w.cb(&peer_req->w, !!err); | 436 | err2 = peer_req->w.cb(&peer_req->w, !!err); |
436 | if (!err) | 437 | if (!err) |
437 | err = err2; | 438 | err = err2; |
438 | drbd_free_peer_req(mdev, peer_req); | 439 | drbd_free_peer_req(device, peer_req); |
439 | } | 440 | } |
440 | wake_up(&mdev->ee_wait); | 441 | wake_up(&device->ee_wait); |
441 | 442 | ||
442 | return err; | 443 | return err; |
443 | } | 444 | } |
444 | 445 | ||
445 | static void _drbd_wait_ee_list_empty(struct drbd_conf *mdev, | 446 | static void _drbd_wait_ee_list_empty(struct drbd_device *device, |
446 | struct list_head *head) | 447 | struct list_head *head) |
447 | { | 448 | { |
448 | DEFINE_WAIT(wait); | 449 | DEFINE_WAIT(wait); |
@@ -450,20 +451,20 @@ static void _drbd_wait_ee_list_empty(struct drbd_conf *mdev, | |||
450 | /* avoids spin_lock/unlock | 451 | /* avoids spin_lock/unlock |
451 | * and calling prepare_to_wait in the fast path */ | 452 | * and calling prepare_to_wait in the fast path */ |
452 | while (!list_empty(head)) { | 453 | while (!list_empty(head)) { |
453 | prepare_to_wait(&mdev->ee_wait, &wait, TASK_UNINTERRUPTIBLE); | 454 | prepare_to_wait(&device->ee_wait, &wait, TASK_UNINTERRUPTIBLE); |
454 | spin_unlock_irq(&mdev->tconn->req_lock); | 455 | spin_unlock_irq(&device->resource->req_lock); |
455 | io_schedule(); | 456 | io_schedule(); |
456 | finish_wait(&mdev->ee_wait, &wait); | 457 | finish_wait(&device->ee_wait, &wait); |
457 | spin_lock_irq(&mdev->tconn->req_lock); | 458 | spin_lock_irq(&device->resource->req_lock); |
458 | } | 459 | } |
459 | } | 460 | } |
460 | 461 | ||
461 | static void drbd_wait_ee_list_empty(struct drbd_conf *mdev, | 462 | static void drbd_wait_ee_list_empty(struct drbd_device *device, |
462 | struct list_head *head) | 463 | struct list_head *head) |
463 | { | 464 | { |
464 | spin_lock_irq(&mdev->tconn->req_lock); | 465 | spin_lock_irq(&device->resource->req_lock); |
465 | _drbd_wait_ee_list_empty(mdev, head); | 466 | _drbd_wait_ee_list_empty(device, head); |
466 | spin_unlock_irq(&mdev->tconn->req_lock); | 467 | spin_unlock_irq(&device->resource->req_lock); |
467 | } | 468 | } |
468 | 469 | ||
469 | static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flags) | 470 | static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flags) |
@@ -488,44 +489,44 @@ static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flag | |||
488 | return rv; | 489 | return rv; |
489 | } | 490 | } |
490 | 491 | ||
491 | static int drbd_recv(struct drbd_tconn *tconn, void *buf, size_t size) | 492 | static int drbd_recv(struct drbd_connection *connection, void *buf, size_t size) |
492 | { | 493 | { |
493 | int rv; | 494 | int rv; |
494 | 495 | ||
495 | rv = drbd_recv_short(tconn->data.socket, buf, size, 0); | 496 | rv = drbd_recv_short(connection->data.socket, buf, size, 0); |
496 | 497 | ||
497 | if (rv < 0) { | 498 | if (rv < 0) { |
498 | if (rv == -ECONNRESET) | 499 | if (rv == -ECONNRESET) |
499 | conn_info(tconn, "sock was reset by peer\n"); | 500 | drbd_info(connection, "sock was reset by peer\n"); |
500 | else if (rv != -ERESTARTSYS) | 501 | else if (rv != -ERESTARTSYS) |
501 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); | 502 | drbd_err(connection, "sock_recvmsg returned %d\n", rv); |
502 | } else if (rv == 0) { | 503 | } else if (rv == 0) { |
503 | if (test_bit(DISCONNECT_SENT, &tconn->flags)) { | 504 | if (test_bit(DISCONNECT_SENT, &connection->flags)) { |
504 | long t; | 505 | long t; |
505 | rcu_read_lock(); | 506 | rcu_read_lock(); |
506 | t = rcu_dereference(tconn->net_conf)->ping_timeo * HZ/10; | 507 | t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10; |
507 | rcu_read_unlock(); | 508 | rcu_read_unlock(); |
508 | 509 | ||
509 | t = wait_event_timeout(tconn->ping_wait, tconn->cstate < C_WF_REPORT_PARAMS, t); | 510 | t = wait_event_timeout(connection->ping_wait, connection->cstate < C_WF_REPORT_PARAMS, t); |
510 | 511 | ||
511 | if (t) | 512 | if (t) |
512 | goto out; | 513 | goto out; |
513 | } | 514 | } |
514 | conn_info(tconn, "sock was shut down by peer\n"); | 515 | drbd_info(connection, "sock was shut down by peer\n"); |
515 | } | 516 | } |
516 | 517 | ||
517 | if (rv != size) | 518 | if (rv != size) |
518 | conn_request_state(tconn, NS(conn, C_BROKEN_PIPE), CS_HARD); | 519 | conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD); |
519 | 520 | ||
520 | out: | 521 | out: |
521 | return rv; | 522 | return rv; |
522 | } | 523 | } |
523 | 524 | ||
524 | static int drbd_recv_all(struct drbd_tconn *tconn, void *buf, size_t size) | 525 | static int drbd_recv_all(struct drbd_connection *connection, void *buf, size_t size) |
525 | { | 526 | { |
526 | int err; | 527 | int err; |
527 | 528 | ||
528 | err = drbd_recv(tconn, buf, size); | 529 | err = drbd_recv(connection, buf, size); |
529 | if (err != size) { | 530 | if (err != size) { |
530 | if (err >= 0) | 531 | if (err >= 0) |
531 | err = -EIO; | 532 | err = -EIO; |
@@ -534,13 +535,13 @@ static int drbd_recv_all(struct drbd_tconn *tconn, void *buf, size_t size) | |||
534 | return err; | 535 | return err; |
535 | } | 536 | } |
536 | 537 | ||
537 | static int drbd_recv_all_warn(struct drbd_tconn *tconn, void *buf, size_t size) | 538 | static int drbd_recv_all_warn(struct drbd_connection *connection, void *buf, size_t size) |
538 | { | 539 | { |
539 | int err; | 540 | int err; |
540 | 541 | ||
541 | err = drbd_recv_all(tconn, buf, size); | 542 | err = drbd_recv_all(connection, buf, size); |
542 | if (err && !signal_pending(current)) | 543 | if (err && !signal_pending(current)) |
543 | conn_warn(tconn, "short read (expected size %d)\n", (int)size); | 544 | drbd_warn(connection, "short read (expected size %d)\n", (int)size); |
544 | return err; | 545 | return err; |
545 | } | 546 | } |
546 | 547 | ||
@@ -563,7 +564,7 @@ static void drbd_setbufsize(struct socket *sock, unsigned int snd, | |||
563 | } | 564 | } |
564 | } | 565 | } |
565 | 566 | ||
566 | static struct socket *drbd_try_connect(struct drbd_tconn *tconn) | 567 | static struct socket *drbd_try_connect(struct drbd_connection *connection) |
567 | { | 568 | { |
568 | const char *what; | 569 | const char *what; |
569 | struct socket *sock; | 570 | struct socket *sock; |
@@ -575,7 +576,7 @@ static struct socket *drbd_try_connect(struct drbd_tconn *tconn) | |||
575 | int disconnect_on_error = 1; | 576 | int disconnect_on_error = 1; |
576 | 577 | ||
577 | rcu_read_lock(); | 578 | rcu_read_lock(); |
578 | nc = rcu_dereference(tconn->net_conf); | 579 | nc = rcu_dereference(connection->net_conf); |
579 | if (!nc) { | 580 | if (!nc) { |
580 | rcu_read_unlock(); | 581 | rcu_read_unlock(); |
581 | return NULL; | 582 | return NULL; |
@@ -585,16 +586,16 @@ static struct socket *drbd_try_connect(struct drbd_tconn *tconn) | |||
585 | connect_int = nc->connect_int; | 586 | connect_int = nc->connect_int; |
586 | rcu_read_unlock(); | 587 | rcu_read_unlock(); |
587 | 588 | ||
588 | my_addr_len = min_t(int, tconn->my_addr_len, sizeof(src_in6)); | 589 | my_addr_len = min_t(int, connection->my_addr_len, sizeof(src_in6)); |
589 | memcpy(&src_in6, &tconn->my_addr, my_addr_len); | 590 | memcpy(&src_in6, &connection->my_addr, my_addr_len); |
590 | 591 | ||
591 | if (((struct sockaddr *)&tconn->my_addr)->sa_family == AF_INET6) | 592 | if (((struct sockaddr *)&connection->my_addr)->sa_family == AF_INET6) |
592 | src_in6.sin6_port = 0; | 593 | src_in6.sin6_port = 0; |
593 | else | 594 | else |
594 | ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ | 595 | ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ |
595 | 596 | ||
596 | peer_addr_len = min_t(int, tconn->peer_addr_len, sizeof(src_in6)); | 597 | peer_addr_len = min_t(int, connection->peer_addr_len, sizeof(src_in6)); |
597 | memcpy(&peer_in6, &tconn->peer_addr, peer_addr_len); | 598 | memcpy(&peer_in6, &connection->peer_addr, peer_addr_len); |
598 | 599 | ||
599 | what = "sock_create_kern"; | 600 | what = "sock_create_kern"; |
600 | err = sock_create_kern(((struct sockaddr *)&src_in6)->sa_family, | 601 | err = sock_create_kern(((struct sockaddr *)&src_in6)->sa_family, |
@@ -642,17 +643,17 @@ out: | |||
642 | disconnect_on_error = 0; | 643 | disconnect_on_error = 0; |
643 | break; | 644 | break; |
644 | default: | 645 | default: |
645 | conn_err(tconn, "%s failed, err = %d\n", what, err); | 646 | drbd_err(connection, "%s failed, err = %d\n", what, err); |
646 | } | 647 | } |
647 | if (disconnect_on_error) | 648 | if (disconnect_on_error) |
648 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 649 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
649 | } | 650 | } |
650 | 651 | ||
651 | return sock; | 652 | return sock; |
652 | } | 653 | } |
653 | 654 | ||
654 | struct accept_wait_data { | 655 | struct accept_wait_data { |
655 | struct drbd_tconn *tconn; | 656 | struct drbd_connection *connection; |
656 | struct socket *s_listen; | 657 | struct socket *s_listen; |
657 | struct completion door_bell; | 658 | struct completion door_bell; |
658 | void (*original_sk_state_change)(struct sock *sk); | 659 | void (*original_sk_state_change)(struct sock *sk); |
@@ -670,7 +671,7 @@ static void drbd_incoming_connection(struct sock *sk) | |||
670 | state_change(sk); | 671 | state_change(sk); |
671 | } | 672 | } |
672 | 673 | ||
673 | static int prepare_listen_socket(struct drbd_tconn *tconn, struct accept_wait_data *ad) | 674 | static int prepare_listen_socket(struct drbd_connection *connection, struct accept_wait_data *ad) |
674 | { | 675 | { |
675 | int err, sndbuf_size, rcvbuf_size, my_addr_len; | 676 | int err, sndbuf_size, rcvbuf_size, my_addr_len; |
676 | struct sockaddr_in6 my_addr; | 677 | struct sockaddr_in6 my_addr; |
@@ -679,7 +680,7 @@ static int prepare_listen_socket(struct drbd_tconn *tconn, struct accept_wait_da | |||
679 | const char *what; | 680 | const char *what; |
680 | 681 | ||
681 | rcu_read_lock(); | 682 | rcu_read_lock(); |
682 | nc = rcu_dereference(tconn->net_conf); | 683 | nc = rcu_dereference(connection->net_conf); |
683 | if (!nc) { | 684 | if (!nc) { |
684 | rcu_read_unlock(); | 685 | rcu_read_unlock(); |
685 | return -EIO; | 686 | return -EIO; |
@@ -688,8 +689,8 @@ static int prepare_listen_socket(struct drbd_tconn *tconn, struct accept_wait_da | |||
688 | rcvbuf_size = nc->rcvbuf_size; | 689 | rcvbuf_size = nc->rcvbuf_size; |
689 | rcu_read_unlock(); | 690 | rcu_read_unlock(); |
690 | 691 | ||
691 | my_addr_len = min_t(int, tconn->my_addr_len, sizeof(struct sockaddr_in6)); | 692 | my_addr_len = min_t(int, connection->my_addr_len, sizeof(struct sockaddr_in6)); |
692 | memcpy(&my_addr, &tconn->my_addr, my_addr_len); | 693 | memcpy(&my_addr, &connection->my_addr, my_addr_len); |
693 | 694 | ||
694 | what = "sock_create_kern"; | 695 | what = "sock_create_kern"; |
695 | err = sock_create_kern(((struct sockaddr *)&my_addr)->sa_family, | 696 | err = sock_create_kern(((struct sockaddr *)&my_addr)->sa_family, |
@@ -725,8 +726,8 @@ out: | |||
725 | sock_release(s_listen); | 726 | sock_release(s_listen); |
726 | if (err < 0) { | 727 | if (err < 0) { |
727 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { | 728 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
728 | conn_err(tconn, "%s failed, err = %d\n", what, err); | 729 | drbd_err(connection, "%s failed, err = %d\n", what, err); |
729 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 730 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
730 | } | 731 | } |
731 | } | 732 | } |
732 | 733 | ||
@@ -741,14 +742,14 @@ static void unregister_state_change(struct sock *sk, struct accept_wait_data *ad | |||
741 | write_unlock_bh(&sk->sk_callback_lock); | 742 | write_unlock_bh(&sk->sk_callback_lock); |
742 | } | 743 | } |
743 | 744 | ||
744 | static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn, struct accept_wait_data *ad) | 745 | static struct socket *drbd_wait_for_connect(struct drbd_connection *connection, struct accept_wait_data *ad) |
745 | { | 746 | { |
746 | int timeo, connect_int, err = 0; | 747 | int timeo, connect_int, err = 0; |
747 | struct socket *s_estab = NULL; | 748 | struct socket *s_estab = NULL; |
748 | struct net_conf *nc; | 749 | struct net_conf *nc; |
749 | 750 | ||
750 | rcu_read_lock(); | 751 | rcu_read_lock(); |
751 | nc = rcu_dereference(tconn->net_conf); | 752 | nc = rcu_dereference(connection->net_conf); |
752 | if (!nc) { | 753 | if (!nc) { |
753 | rcu_read_unlock(); | 754 | rcu_read_unlock(); |
754 | return NULL; | 755 | return NULL; |
@@ -767,8 +768,8 @@ static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn, struct acc | |||
767 | err = kernel_accept(ad->s_listen, &s_estab, 0); | 768 | err = kernel_accept(ad->s_listen, &s_estab, 0); |
768 | if (err < 0) { | 769 | if (err < 0) { |
769 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { | 770 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
770 | conn_err(tconn, "accept failed, err = %d\n", err); | 771 | drbd_err(connection, "accept failed, err = %d\n", err); |
771 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 772 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
772 | } | 773 | } |
773 | } | 774 | } |
774 | 775 | ||
@@ -778,29 +779,29 @@ static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn, struct acc | |||
778 | return s_estab; | 779 | return s_estab; |
779 | } | 780 | } |
780 | 781 | ||
781 | static int decode_header(struct drbd_tconn *, void *, struct packet_info *); | 782 | static int decode_header(struct drbd_connection *, void *, struct packet_info *); |
782 | 783 | ||
783 | static int send_first_packet(struct drbd_tconn *tconn, struct drbd_socket *sock, | 784 | static int send_first_packet(struct drbd_connection *connection, struct drbd_socket *sock, |
784 | enum drbd_packet cmd) | 785 | enum drbd_packet cmd) |
785 | { | 786 | { |
786 | if (!conn_prepare_command(tconn, sock)) | 787 | if (!conn_prepare_command(connection, sock)) |
787 | return -EIO; | 788 | return -EIO; |
788 | return conn_send_command(tconn, sock, cmd, 0, NULL, 0); | 789 | return conn_send_command(connection, sock, cmd, 0, NULL, 0); |
789 | } | 790 | } |
790 | 791 | ||
791 | static int receive_first_packet(struct drbd_tconn *tconn, struct socket *sock) | 792 | static int receive_first_packet(struct drbd_connection *connection, struct socket *sock) |
792 | { | 793 | { |
793 | unsigned int header_size = drbd_header_size(tconn); | 794 | unsigned int header_size = drbd_header_size(connection); |
794 | struct packet_info pi; | 795 | struct packet_info pi; |
795 | int err; | 796 | int err; |
796 | 797 | ||
797 | err = drbd_recv_short(sock, tconn->data.rbuf, header_size, 0); | 798 | err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0); |
798 | if (err != header_size) { | 799 | if (err != header_size) { |
799 | if (err >= 0) | 800 | if (err >= 0) |
800 | err = -EIO; | 801 | err = -EIO; |
801 | return err; | 802 | return err; |
802 | } | 803 | } |
803 | err = decode_header(tconn, tconn->data.rbuf, &pi); | 804 | err = decode_header(connection, connection->data.rbuf, &pi); |
804 | if (err) | 805 | if (err) |
805 | return err; | 806 | return err; |
806 | return pi.cmd; | 807 | return pi.cmd; |
@@ -830,28 +831,29 @@ static int drbd_socket_okay(struct socket **sock) | |||
830 | } | 831 | } |
831 | /* Gets called if a connection is established, or if a new minor gets created | 832 | /* Gets called if a connection is established, or if a new minor gets created |
832 | in a connection */ | 833 | in a connection */ |
833 | int drbd_connected(struct drbd_conf *mdev) | 834 | int drbd_connected(struct drbd_peer_device *peer_device) |
834 | { | 835 | { |
836 | struct drbd_device *device = peer_device->device; | ||
835 | int err; | 837 | int err; |
836 | 838 | ||
837 | atomic_set(&mdev->packet_seq, 0); | 839 | atomic_set(&device->packet_seq, 0); |
838 | mdev->peer_seq = 0; | 840 | device->peer_seq = 0; |
839 | 841 | ||
840 | mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ? | 842 | device->state_mutex = peer_device->connection->agreed_pro_version < 100 ? |
841 | &mdev->tconn->cstate_mutex : | 843 | &peer_device->connection->cstate_mutex : |
842 | &mdev->own_state_mutex; | 844 | &device->own_state_mutex; |
843 | 845 | ||
844 | err = drbd_send_sync_param(mdev); | 846 | err = drbd_send_sync_param(peer_device); |
845 | if (!err) | 847 | if (!err) |
846 | err = drbd_send_sizes(mdev, 0, 0); | 848 | err = drbd_send_sizes(peer_device, 0, 0); |
847 | if (!err) | 849 | if (!err) |
848 | err = drbd_send_uuids(mdev); | 850 | err = drbd_send_uuids(peer_device); |
849 | if (!err) | 851 | if (!err) |
850 | err = drbd_send_current_state(mdev); | 852 | err = drbd_send_current_state(peer_device); |
851 | clear_bit(USE_DEGR_WFC_T, &mdev->flags); | 853 | clear_bit(USE_DEGR_WFC_T, &device->flags); |
852 | clear_bit(RESIZE_PENDING, &mdev->flags); | 854 | clear_bit(RESIZE_PENDING, &device->flags); |
853 | atomic_set(&mdev->ap_in_flight, 0); | 855 | atomic_set(&device->ap_in_flight, 0); |
854 | mod_timer(&mdev->request_timer, jiffies + HZ); /* just start it here. */ | 856 | mod_timer(&device->request_timer, jiffies + HZ); /* just start it here. */ |
855 | return err; | 857 | return err; |
856 | } | 858 | } |
857 | 859 | ||
@@ -863,59 +865,59 @@ int drbd_connected(struct drbd_conf *mdev) | |||
863 | * no point in trying again, please go standalone. | 865 | * no point in trying again, please go standalone. |
864 | * -2 We do not have a network config... | 866 | * -2 We do not have a network config... |
865 | */ | 867 | */ |
866 | static int conn_connect(struct drbd_tconn *tconn) | 868 | static int conn_connect(struct drbd_connection *connection) |
867 | { | 869 | { |
868 | struct drbd_socket sock, msock; | 870 | struct drbd_socket sock, msock; |
869 | struct drbd_conf *mdev; | 871 | struct drbd_peer_device *peer_device; |
870 | struct net_conf *nc; | 872 | struct net_conf *nc; |
871 | int vnr, timeout, h, ok; | 873 | int vnr, timeout, h, ok; |
872 | bool discard_my_data; | 874 | bool discard_my_data; |
873 | enum drbd_state_rv rv; | 875 | enum drbd_state_rv rv; |
874 | struct accept_wait_data ad = { | 876 | struct accept_wait_data ad = { |
875 | .tconn = tconn, | 877 | .connection = connection, |
876 | .door_bell = COMPLETION_INITIALIZER_ONSTACK(ad.door_bell), | 878 | .door_bell = COMPLETION_INITIALIZER_ONSTACK(ad.door_bell), |
877 | }; | 879 | }; |
878 | 880 | ||
879 | clear_bit(DISCONNECT_SENT, &tconn->flags); | 881 | clear_bit(DISCONNECT_SENT, &connection->flags); |
880 | if (conn_request_state(tconn, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS) | 882 | if (conn_request_state(connection, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS) |
881 | return -2; | 883 | return -2; |
882 | 884 | ||
883 | mutex_init(&sock.mutex); | 885 | mutex_init(&sock.mutex); |
884 | sock.sbuf = tconn->data.sbuf; | 886 | sock.sbuf = connection->data.sbuf; |
885 | sock.rbuf = tconn->data.rbuf; | 887 | sock.rbuf = connection->data.rbuf; |
886 | sock.socket = NULL; | 888 | sock.socket = NULL; |
887 | mutex_init(&msock.mutex); | 889 | mutex_init(&msock.mutex); |
888 | msock.sbuf = tconn->meta.sbuf; | 890 | msock.sbuf = connection->meta.sbuf; |
889 | msock.rbuf = tconn->meta.rbuf; | 891 | msock.rbuf = connection->meta.rbuf; |
890 | msock.socket = NULL; | 892 | msock.socket = NULL; |
891 | 893 | ||
892 | /* Assume that the peer only understands protocol 80 until we know better. */ | 894 | /* Assume that the peer only understands protocol 80 until we know better. */ |
893 | tconn->agreed_pro_version = 80; | 895 | connection->agreed_pro_version = 80; |
894 | 896 | ||
895 | if (prepare_listen_socket(tconn, &ad)) | 897 | if (prepare_listen_socket(connection, &ad)) |
896 | return 0; | 898 | return 0; |
897 | 899 | ||
898 | do { | 900 | do { |
899 | struct socket *s; | 901 | struct socket *s; |
900 | 902 | ||
901 | s = drbd_try_connect(tconn); | 903 | s = drbd_try_connect(connection); |
902 | if (s) { | 904 | if (s) { |
903 | if (!sock.socket) { | 905 | if (!sock.socket) { |
904 | sock.socket = s; | 906 | sock.socket = s; |
905 | send_first_packet(tconn, &sock, P_INITIAL_DATA); | 907 | send_first_packet(connection, &sock, P_INITIAL_DATA); |
906 | } else if (!msock.socket) { | 908 | } else if (!msock.socket) { |
907 | clear_bit(RESOLVE_CONFLICTS, &tconn->flags); | 909 | clear_bit(RESOLVE_CONFLICTS, &connection->flags); |
908 | msock.socket = s; | 910 | msock.socket = s; |
909 | send_first_packet(tconn, &msock, P_INITIAL_META); | 911 | send_first_packet(connection, &msock, P_INITIAL_META); |
910 | } else { | 912 | } else { |
911 | conn_err(tconn, "Logic error in conn_connect()\n"); | 913 | drbd_err(connection, "Logic error in conn_connect()\n"); |
912 | goto out_release_sockets; | 914 | goto out_release_sockets; |
913 | } | 915 | } |
914 | } | 916 | } |
915 | 917 | ||
916 | if (sock.socket && msock.socket) { | 918 | if (sock.socket && msock.socket) { |
917 | rcu_read_lock(); | 919 | rcu_read_lock(); |
918 | nc = rcu_dereference(tconn->net_conf); | 920 | nc = rcu_dereference(connection->net_conf); |
919 | timeout = nc->ping_timeo * HZ / 10; | 921 | timeout = nc->ping_timeo * HZ / 10; |
920 | rcu_read_unlock(); | 922 | rcu_read_unlock(); |
921 | schedule_timeout_interruptible(timeout); | 923 | schedule_timeout_interruptible(timeout); |
@@ -926,15 +928,15 @@ static int conn_connect(struct drbd_tconn *tconn) | |||
926 | } | 928 | } |
927 | 929 | ||
928 | retry: | 930 | retry: |
929 | s = drbd_wait_for_connect(tconn, &ad); | 931 | s = drbd_wait_for_connect(connection, &ad); |
930 | if (s) { | 932 | if (s) { |
931 | int fp = receive_first_packet(tconn, s); | 933 | int fp = receive_first_packet(connection, s); |
932 | drbd_socket_okay(&sock.socket); | 934 | drbd_socket_okay(&sock.socket); |
933 | drbd_socket_okay(&msock.socket); | 935 | drbd_socket_okay(&msock.socket); |
934 | switch (fp) { | 936 | switch (fp) { |
935 | case P_INITIAL_DATA: | 937 | case P_INITIAL_DATA: |
936 | if (sock.socket) { | 938 | if (sock.socket) { |
937 | conn_warn(tconn, "initial packet S crossed\n"); | 939 | drbd_warn(connection, "initial packet S crossed\n"); |
938 | sock_release(sock.socket); | 940 | sock_release(sock.socket); |
939 | sock.socket = s; | 941 | sock.socket = s; |
940 | goto randomize; | 942 | goto randomize; |
@@ -942,9 +944,9 @@ retry: | |||
942 | sock.socket = s; | 944 | sock.socket = s; |
943 | break; | 945 | break; |
944 | case P_INITIAL_META: | 946 | case P_INITIAL_META: |
945 | set_bit(RESOLVE_CONFLICTS, &tconn->flags); | 947 | set_bit(RESOLVE_CONFLICTS, &connection->flags); |
946 | if (msock.socket) { | 948 | if (msock.socket) { |
947 | conn_warn(tconn, "initial packet M crossed\n"); | 949 | drbd_warn(connection, "initial packet M crossed\n"); |
948 | sock_release(msock.socket); | 950 | sock_release(msock.socket); |
949 | msock.socket = s; | 951 | msock.socket = s; |
950 | goto randomize; | 952 | goto randomize; |
@@ -952,7 +954,7 @@ retry: | |||
952 | msock.socket = s; | 954 | msock.socket = s; |
953 | break; | 955 | break; |
954 | default: | 956 | default: |
955 | conn_warn(tconn, "Error receiving initial packet\n"); | 957 | drbd_warn(connection, "Error receiving initial packet\n"); |
956 | sock_release(s); | 958 | sock_release(s); |
957 | randomize: | 959 | randomize: |
958 | if (prandom_u32() & 1) | 960 | if (prandom_u32() & 1) |
@@ -960,12 +962,12 @@ randomize: | |||
960 | } | 962 | } |
961 | } | 963 | } |
962 | 964 | ||
963 | if (tconn->cstate <= C_DISCONNECTING) | 965 | if (connection->cstate <= C_DISCONNECTING) |
964 | goto out_release_sockets; | 966 | goto out_release_sockets; |
965 | if (signal_pending(current)) { | 967 | if (signal_pending(current)) { |
966 | flush_signals(current); | 968 | flush_signals(current); |
967 | smp_rmb(); | 969 | smp_rmb(); |
968 | if (get_t_state(&tconn->receiver) == EXITING) | 970 | if (get_t_state(&connection->receiver) == EXITING) |
969 | goto out_release_sockets; | 971 | goto out_release_sockets; |
970 | } | 972 | } |
971 | 973 | ||
@@ -986,12 +988,12 @@ randomize: | |||
986 | msock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE; | 988 | msock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE; |
987 | 989 | ||
988 | /* NOT YET ... | 990 | /* NOT YET ... |
989 | * sock.socket->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10; | 991 | * sock.socket->sk->sk_sndtimeo = connection->net_conf->timeout*HZ/10; |
990 | * sock.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; | 992 | * sock.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
991 | * first set it to the P_CONNECTION_FEATURES timeout, | 993 | * first set it to the P_CONNECTION_FEATURES timeout, |
992 | * which we set to 4x the configured ping_timeout. */ | 994 | * which we set to 4x the configured ping_timeout. */ |
993 | rcu_read_lock(); | 995 | rcu_read_lock(); |
994 | nc = rcu_dereference(tconn->net_conf); | 996 | nc = rcu_dereference(connection->net_conf); |
995 | 997 | ||
996 | sock.socket->sk->sk_sndtimeo = | 998 | sock.socket->sk->sk_sndtimeo = |
997 | sock.socket->sk->sk_rcvtimeo = nc->ping_timeo*4*HZ/10; | 999 | sock.socket->sk->sk_rcvtimeo = nc->ping_timeo*4*HZ/10; |
@@ -1008,37 +1010,38 @@ randomize: | |||
1008 | drbd_tcp_nodelay(sock.socket); | 1010 | drbd_tcp_nodelay(sock.socket); |
1009 | drbd_tcp_nodelay(msock.socket); | 1011 | drbd_tcp_nodelay(msock.socket); |
1010 | 1012 | ||
1011 | tconn->data.socket = sock.socket; | 1013 | connection->data.socket = sock.socket; |
1012 | tconn->meta.socket = msock.socket; | 1014 | connection->meta.socket = msock.socket; |
1013 | tconn->last_received = jiffies; | 1015 | connection->last_received = jiffies; |
1014 | 1016 | ||
1015 | h = drbd_do_features(tconn); | 1017 | h = drbd_do_features(connection); |
1016 | if (h <= 0) | 1018 | if (h <= 0) |
1017 | return h; | 1019 | return h; |
1018 | 1020 | ||
1019 | if (tconn->cram_hmac_tfm) { | 1021 | if (connection->cram_hmac_tfm) { |
1020 | /* drbd_request_state(mdev, NS(conn, WFAuth)); */ | 1022 | /* drbd_request_state(device, NS(conn, WFAuth)); */ |
1021 | switch (drbd_do_auth(tconn)) { | 1023 | switch (drbd_do_auth(connection)) { |
1022 | case -1: | 1024 | case -1: |
1023 | conn_err(tconn, "Authentication of peer failed\n"); | 1025 | drbd_err(connection, "Authentication of peer failed\n"); |
1024 | return -1; | 1026 | return -1; |
1025 | case 0: | 1027 | case 0: |
1026 | conn_err(tconn, "Authentication of peer failed, trying again.\n"); | 1028 | drbd_err(connection, "Authentication of peer failed, trying again.\n"); |
1027 | return 0; | 1029 | return 0; |
1028 | } | 1030 | } |
1029 | } | 1031 | } |
1030 | 1032 | ||
1031 | tconn->data.socket->sk->sk_sndtimeo = timeout; | 1033 | connection->data.socket->sk->sk_sndtimeo = timeout; |
1032 | tconn->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; | 1034 | connection->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
1033 | 1035 | ||
1034 | if (drbd_send_protocol(tconn) == -EOPNOTSUPP) | 1036 | if (drbd_send_protocol(connection) == -EOPNOTSUPP) |
1035 | return -1; | 1037 | return -1; |
1036 | 1038 | ||
1037 | set_bit(STATE_SENT, &tconn->flags); | 1039 | set_bit(STATE_SENT, &connection->flags); |
1038 | 1040 | ||
1039 | rcu_read_lock(); | 1041 | rcu_read_lock(); |
1040 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1042 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1041 | kref_get(&mdev->kref); | 1043 | struct drbd_device *device = peer_device->device; |
1044 | kref_get(&device->kref); | ||
1042 | rcu_read_unlock(); | 1045 | rcu_read_unlock(); |
1043 | 1046 | ||
1044 | /* Prevent a race between resync-handshake and | 1047 | /* Prevent a race between resync-handshake and |
@@ -1048,35 +1051,35 @@ randomize: | |||
1048 | * drbd_set_role() is finished, and any incoming drbd_set_role | 1051 | * drbd_set_role() is finished, and any incoming drbd_set_role |
1049 | * will see the STATE_SENT flag, and wait for it to be cleared. | 1052 | * will see the STATE_SENT flag, and wait for it to be cleared. |
1050 | */ | 1053 | */ |
1051 | mutex_lock(mdev->state_mutex); | 1054 | mutex_lock(device->state_mutex); |
1052 | mutex_unlock(mdev->state_mutex); | 1055 | mutex_unlock(device->state_mutex); |
1053 | 1056 | ||
1054 | if (discard_my_data) | 1057 | if (discard_my_data) |
1055 | set_bit(DISCARD_MY_DATA, &mdev->flags); | 1058 | set_bit(DISCARD_MY_DATA, &device->flags); |
1056 | else | 1059 | else |
1057 | clear_bit(DISCARD_MY_DATA, &mdev->flags); | 1060 | clear_bit(DISCARD_MY_DATA, &device->flags); |
1058 | 1061 | ||
1059 | drbd_connected(mdev); | 1062 | drbd_connected(peer_device); |
1060 | kref_put(&mdev->kref, &drbd_minor_destroy); | 1063 | kref_put(&device->kref, drbd_destroy_device); |
1061 | rcu_read_lock(); | 1064 | rcu_read_lock(); |
1062 | } | 1065 | } |
1063 | rcu_read_unlock(); | 1066 | rcu_read_unlock(); |
1064 | 1067 | ||
1065 | rv = conn_request_state(tconn, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE); | 1068 | rv = conn_request_state(connection, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE); |
1066 | if (rv < SS_SUCCESS || tconn->cstate != C_WF_REPORT_PARAMS) { | 1069 | if (rv < SS_SUCCESS || connection->cstate != C_WF_REPORT_PARAMS) { |
1067 | clear_bit(STATE_SENT, &tconn->flags); | 1070 | clear_bit(STATE_SENT, &connection->flags); |
1068 | return 0; | 1071 | return 0; |
1069 | } | 1072 | } |
1070 | 1073 | ||
1071 | drbd_thread_start(&tconn->asender); | 1074 | drbd_thread_start(&connection->asender); |
1072 | 1075 | ||
1073 | mutex_lock(&tconn->conf_update); | 1076 | mutex_lock(&connection->resource->conf_update); |
1074 | /* The discard_my_data flag is a single-shot modifier to the next | 1077 | /* The discard_my_data flag is a single-shot modifier to the next |
1075 | * connection attempt, the handshake of which is now well underway. | 1078 | * connection attempt, the handshake of which is now well underway. |
1076 | * No need for rcu style copying of the whole struct | 1079 | * No need for rcu style copying of the whole struct |
1077 | * just to clear a single value. */ | 1080 | * just to clear a single value. */ |
1078 | tconn->net_conf->discard_my_data = 0; | 1081 | connection->net_conf->discard_my_data = 0; |
1079 | mutex_unlock(&tconn->conf_update); | 1082 | mutex_unlock(&connection->resource->conf_update); |
1080 | 1083 | ||
1081 | return h; | 1084 | return h; |
1082 | 1085 | ||
@@ -1090,15 +1093,15 @@ out_release_sockets: | |||
1090 | return -1; | 1093 | return -1; |
1091 | } | 1094 | } |
1092 | 1095 | ||
1093 | static int decode_header(struct drbd_tconn *tconn, void *header, struct packet_info *pi) | 1096 | static int decode_header(struct drbd_connection *connection, void *header, struct packet_info *pi) |
1094 | { | 1097 | { |
1095 | unsigned int header_size = drbd_header_size(tconn); | 1098 | unsigned int header_size = drbd_header_size(connection); |
1096 | 1099 | ||
1097 | if (header_size == sizeof(struct p_header100) && | 1100 | if (header_size == sizeof(struct p_header100) && |
1098 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC_100)) { | 1101 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC_100)) { |
1099 | struct p_header100 *h = header; | 1102 | struct p_header100 *h = header; |
1100 | if (h->pad != 0) { | 1103 | if (h->pad != 0) { |
1101 | conn_err(tconn, "Header padding is not zero\n"); | 1104 | drbd_err(connection, "Header padding is not zero\n"); |
1102 | return -EINVAL; | 1105 | return -EINVAL; |
1103 | } | 1106 | } |
1104 | pi->vnr = be16_to_cpu(h->volume); | 1107 | pi->vnr = be16_to_cpu(h->volume); |
@@ -1117,55 +1120,57 @@ static int decode_header(struct drbd_tconn *tconn, void *header, struct packet_i | |||
1117 | pi->size = be16_to_cpu(h->length); | 1120 | pi->size = be16_to_cpu(h->length); |
1118 | pi->vnr = 0; | 1121 | pi->vnr = 0; |
1119 | } else { | 1122 | } else { |
1120 | conn_err(tconn, "Wrong magic value 0x%08x in protocol version %d\n", | 1123 | drbd_err(connection, "Wrong magic value 0x%08x in protocol version %d\n", |
1121 | be32_to_cpu(*(__be32 *)header), | 1124 | be32_to_cpu(*(__be32 *)header), |
1122 | tconn->agreed_pro_version); | 1125 | connection->agreed_pro_version); |
1123 | return -EINVAL; | 1126 | return -EINVAL; |
1124 | } | 1127 | } |
1125 | pi->data = header + header_size; | 1128 | pi->data = header + header_size; |
1126 | return 0; | 1129 | return 0; |
1127 | } | 1130 | } |
1128 | 1131 | ||
1129 | static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi) | 1132 | static int drbd_recv_header(struct drbd_connection *connection, struct packet_info *pi) |
1130 | { | 1133 | { |
1131 | void *buffer = tconn->data.rbuf; | 1134 | void *buffer = connection->data.rbuf; |
1132 | int err; | 1135 | int err; |
1133 | 1136 | ||
1134 | err = drbd_recv_all_warn(tconn, buffer, drbd_header_size(tconn)); | 1137 | err = drbd_recv_all_warn(connection, buffer, drbd_header_size(connection)); |
1135 | if (err) | 1138 | if (err) |
1136 | return err; | 1139 | return err; |
1137 | 1140 | ||
1138 | err = decode_header(tconn, buffer, pi); | 1141 | err = decode_header(connection, buffer, pi); |
1139 | tconn->last_received = jiffies; | 1142 | connection->last_received = jiffies; |
1140 | 1143 | ||
1141 | return err; | 1144 | return err; |
1142 | } | 1145 | } |
1143 | 1146 | ||
1144 | static void drbd_flush(struct drbd_tconn *tconn) | 1147 | static void drbd_flush(struct drbd_connection *connection) |
1145 | { | 1148 | { |
1146 | int rv; | 1149 | int rv; |
1147 | struct drbd_conf *mdev; | 1150 | struct drbd_peer_device *peer_device; |
1148 | int vnr; | 1151 | int vnr; |
1149 | 1152 | ||
1150 | if (tconn->write_ordering >= WO_bdev_flush) { | 1153 | if (connection->write_ordering >= WO_bdev_flush) { |
1151 | rcu_read_lock(); | 1154 | rcu_read_lock(); |
1152 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1155 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1153 | if (!get_ldev(mdev)) | 1156 | struct drbd_device *device = peer_device->device; |
1157 | |||
1158 | if (!get_ldev(device)) | ||
1154 | continue; | 1159 | continue; |
1155 | kref_get(&mdev->kref); | 1160 | kref_get(&device->kref); |
1156 | rcu_read_unlock(); | 1161 | rcu_read_unlock(); |
1157 | 1162 | ||
1158 | rv = blkdev_issue_flush(mdev->ldev->backing_bdev, | 1163 | rv = blkdev_issue_flush(device->ldev->backing_bdev, |
1159 | GFP_NOIO, NULL); | 1164 | GFP_NOIO, NULL); |
1160 | if (rv) { | 1165 | if (rv) { |
1161 | dev_info(DEV, "local disk flush failed with status %d\n", rv); | 1166 | drbd_info(device, "local disk flush failed with status %d\n", rv); |
1162 | /* would rather check on EOPNOTSUPP, but that is not reliable. | 1167 | /* would rather check on EOPNOTSUPP, but that is not reliable. |
1163 | * don't try again for ANY return value != 0 | 1168 | * don't try again for ANY return value != 0 |
1164 | * if (rv == -EOPNOTSUPP) */ | 1169 | * if (rv == -EOPNOTSUPP) */ |
1165 | drbd_bump_write_ordering(tconn, WO_drain_io); | 1170 | drbd_bump_write_ordering(connection, WO_drain_io); |
1166 | } | 1171 | } |
1167 | put_ldev(mdev); | 1172 | put_ldev(device); |
1168 | kref_put(&mdev->kref, &drbd_minor_destroy); | 1173 | kref_put(&device->kref, drbd_destroy_device); |
1169 | 1174 | ||
1170 | rcu_read_lock(); | 1175 | rcu_read_lock(); |
1171 | if (rv) | 1176 | if (rv) |
@@ -1177,11 +1182,11 @@ static void drbd_flush(struct drbd_tconn *tconn) | |||
1177 | 1182 | ||
1178 | /** | 1183 | /** |
1179 | * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it. | 1184 | * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it. |
1180 | * @mdev: DRBD device. | 1185 | * @device: DRBD device. |
1181 | * @epoch: Epoch object. | 1186 | * @epoch: Epoch object. |
1182 | * @ev: Epoch event. | 1187 | * @ev: Epoch event. |
1183 | */ | 1188 | */ |
1184 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn, | 1189 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connection, |
1185 | struct drbd_epoch *epoch, | 1190 | struct drbd_epoch *epoch, |
1186 | enum epoch_event ev) | 1191 | enum epoch_event ev) |
1187 | { | 1192 | { |
@@ -1189,7 +1194,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn, | |||
1189 | struct drbd_epoch *next_epoch; | 1194 | struct drbd_epoch *next_epoch; |
1190 | enum finish_epoch rv = FE_STILL_LIVE; | 1195 | enum finish_epoch rv = FE_STILL_LIVE; |
1191 | 1196 | ||
1192 | spin_lock(&tconn->epoch_lock); | 1197 | spin_lock(&connection->epoch_lock); |
1193 | do { | 1198 | do { |
1194 | next_epoch = NULL; | 1199 | next_epoch = NULL; |
1195 | 1200 | ||
@@ -1211,22 +1216,22 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn, | |||
1211 | atomic_read(&epoch->active) == 0 && | 1216 | atomic_read(&epoch->active) == 0 && |
1212 | (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) || ev & EV_CLEANUP)) { | 1217 | (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) || ev & EV_CLEANUP)) { |
1213 | if (!(ev & EV_CLEANUP)) { | 1218 | if (!(ev & EV_CLEANUP)) { |
1214 | spin_unlock(&tconn->epoch_lock); | 1219 | spin_unlock(&connection->epoch_lock); |
1215 | drbd_send_b_ack(epoch->tconn, epoch->barrier_nr, epoch_size); | 1220 | drbd_send_b_ack(epoch->connection, epoch->barrier_nr, epoch_size); |
1216 | spin_lock(&tconn->epoch_lock); | 1221 | spin_lock(&connection->epoch_lock); |
1217 | } | 1222 | } |
1218 | #if 0 | 1223 | #if 0 |
1219 | /* FIXME: dec unacked on connection, once we have | 1224 | /* FIXME: dec unacked on connection, once we have |
1220 | * something to count pending connection packets in. */ | 1225 | * something to count pending connection packets in. */ |
1221 | if (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) | 1226 | if (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) |
1222 | dec_unacked(epoch->tconn); | 1227 | dec_unacked(epoch->connection); |
1223 | #endif | 1228 | #endif |
1224 | 1229 | ||
1225 | if (tconn->current_epoch != epoch) { | 1230 | if (connection->current_epoch != epoch) { |
1226 | next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); | 1231 | next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); |
1227 | list_del(&epoch->list); | 1232 | list_del(&epoch->list); |
1228 | ev = EV_BECAME_LAST | (ev & EV_CLEANUP); | 1233 | ev = EV_BECAME_LAST | (ev & EV_CLEANUP); |
1229 | tconn->epochs--; | 1234 | connection->epochs--; |
1230 | kfree(epoch); | 1235 | kfree(epoch); |
1231 | 1236 | ||
1232 | if (rv == FE_STILL_LIVE) | 1237 | if (rv == FE_STILL_LIVE) |
@@ -1246,20 +1251,20 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn, | |||
1246 | epoch = next_epoch; | 1251 | epoch = next_epoch; |
1247 | } while (1); | 1252 | } while (1); |
1248 | 1253 | ||
1249 | spin_unlock(&tconn->epoch_lock); | 1254 | spin_unlock(&connection->epoch_lock); |
1250 | 1255 | ||
1251 | return rv; | 1256 | return rv; |
1252 | } | 1257 | } |
1253 | 1258 | ||
1254 | /** | 1259 | /** |
1255 | * drbd_bump_write_ordering() - Fall back to an other write ordering method | 1260 | * drbd_bump_write_ordering() - Fall back to an other write ordering method |
1256 | * @tconn: DRBD connection. | 1261 | * @connection: DRBD connection. |
1257 | * @wo: Write ordering method to try. | 1262 | * @wo: Write ordering method to try. |
1258 | */ | 1263 | */ |
1259 | void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo) | 1264 | void drbd_bump_write_ordering(struct drbd_connection *connection, enum write_ordering_e wo) |
1260 | { | 1265 | { |
1261 | struct disk_conf *dc; | 1266 | struct disk_conf *dc; |
1262 | struct drbd_conf *mdev; | 1267 | struct drbd_peer_device *peer_device; |
1263 | enum write_ordering_e pwo; | 1268 | enum write_ordering_e pwo; |
1264 | int vnr; | 1269 | int vnr; |
1265 | static char *write_ordering_str[] = { | 1270 | static char *write_ordering_str[] = { |
@@ -1268,29 +1273,31 @@ void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo | |||
1268 | [WO_bdev_flush] = "flush", | 1273 | [WO_bdev_flush] = "flush", |
1269 | }; | 1274 | }; |
1270 | 1275 | ||
1271 | pwo = tconn->write_ordering; | 1276 | pwo = connection->write_ordering; |
1272 | wo = min(pwo, wo); | 1277 | wo = min(pwo, wo); |
1273 | rcu_read_lock(); | 1278 | rcu_read_lock(); |
1274 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1279 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1275 | if (!get_ldev_if_state(mdev, D_ATTACHING)) | 1280 | struct drbd_device *device = peer_device->device; |
1281 | |||
1282 | if (!get_ldev_if_state(device, D_ATTACHING)) | ||
1276 | continue; | 1283 | continue; |
1277 | dc = rcu_dereference(mdev->ldev->disk_conf); | 1284 | dc = rcu_dereference(device->ldev->disk_conf); |
1278 | 1285 | ||
1279 | if (wo == WO_bdev_flush && !dc->disk_flushes) | 1286 | if (wo == WO_bdev_flush && !dc->disk_flushes) |
1280 | wo = WO_drain_io; | 1287 | wo = WO_drain_io; |
1281 | if (wo == WO_drain_io && !dc->disk_drain) | 1288 | if (wo == WO_drain_io && !dc->disk_drain) |
1282 | wo = WO_none; | 1289 | wo = WO_none; |
1283 | put_ldev(mdev); | 1290 | put_ldev(device); |
1284 | } | 1291 | } |
1285 | rcu_read_unlock(); | 1292 | rcu_read_unlock(); |
1286 | tconn->write_ordering = wo; | 1293 | connection->write_ordering = wo; |
1287 | if (pwo != tconn->write_ordering || wo == WO_bdev_flush) | 1294 | if (pwo != connection->write_ordering || wo == WO_bdev_flush) |
1288 | conn_info(tconn, "Method to ensure write ordering: %s\n", write_ordering_str[tconn->write_ordering]); | 1295 | drbd_info(connection, "Method to ensure write ordering: %s\n", write_ordering_str[connection->write_ordering]); |
1289 | } | 1296 | } |
1290 | 1297 | ||
1291 | /** | 1298 | /** |
1292 | * drbd_submit_peer_request() | 1299 | * drbd_submit_peer_request() |
1293 | * @mdev: DRBD device. | 1300 | * @device: DRBD device. |
1294 | * @peer_req: peer request | 1301 | * @peer_req: peer request |
1295 | * @rw: flag field, see bio->bi_rw | 1302 | * @rw: flag field, see bio->bi_rw |
1296 | * | 1303 | * |
@@ -1305,7 +1312,7 @@ void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo | |||
1305 | * on certain Xen deployments. | 1312 | * on certain Xen deployments. |
1306 | */ | 1313 | */ |
1307 | /* TODO allocate from our own bio_set. */ | 1314 | /* TODO allocate from our own bio_set. */ |
1308 | int drbd_submit_peer_request(struct drbd_conf *mdev, | 1315 | int drbd_submit_peer_request(struct drbd_device *device, |
1309 | struct drbd_peer_request *peer_req, | 1316 | struct drbd_peer_request *peer_req, |
1310 | const unsigned rw, const int fault_type) | 1317 | const unsigned rw, const int fault_type) |
1311 | { | 1318 | { |
@@ -1329,12 +1336,12 @@ int drbd_submit_peer_request(struct drbd_conf *mdev, | |||
1329 | next_bio: | 1336 | next_bio: |
1330 | bio = bio_alloc(GFP_NOIO, nr_pages); | 1337 | bio = bio_alloc(GFP_NOIO, nr_pages); |
1331 | if (!bio) { | 1338 | if (!bio) { |
1332 | dev_err(DEV, "submit_ee: Allocation of a bio failed\n"); | 1339 | drbd_err(device, "submit_ee: Allocation of a bio failed\n"); |
1333 | goto fail; | 1340 | goto fail; |
1334 | } | 1341 | } |
1335 | /* > peer_req->i.sector, unless this is the first bio */ | 1342 | /* > peer_req->i.sector, unless this is the first bio */ |
1336 | bio->bi_iter.bi_sector = sector; | 1343 | bio->bi_iter.bi_sector = sector; |
1337 | bio->bi_bdev = mdev->ldev->backing_bdev; | 1344 | bio->bi_bdev = device->ldev->backing_bdev; |
1338 | bio->bi_rw = rw; | 1345 | bio->bi_rw = rw; |
1339 | bio->bi_private = peer_req; | 1346 | bio->bi_private = peer_req; |
1340 | bio->bi_end_io = drbd_peer_request_endio; | 1347 | bio->bi_end_io = drbd_peer_request_endio; |
@@ -1350,7 +1357,7 @@ next_bio: | |||
1350 | * But in case it fails anyways, | 1357 | * But in case it fails anyways, |
1351 | * we deal with it, and complain (below). */ | 1358 | * we deal with it, and complain (below). */ |
1352 | if (bio->bi_vcnt == 0) { | 1359 | if (bio->bi_vcnt == 0) { |
1353 | dev_err(DEV, | 1360 | drbd_err(device, |
1354 | "bio_add_page failed for len=%u, " | 1361 | "bio_add_page failed for len=%u, " |
1355 | "bi_vcnt=0 (bi_sector=%llu)\n", | 1362 | "bi_vcnt=0 (bi_sector=%llu)\n", |
1356 | len, (uint64_t)bio->bi_iter.bi_sector); | 1363 | len, (uint64_t)bio->bi_iter.bi_sector); |
@@ -1363,8 +1370,8 @@ next_bio: | |||
1363 | sector += len >> 9; | 1370 | sector += len >> 9; |
1364 | --nr_pages; | 1371 | --nr_pages; |
1365 | } | 1372 | } |
1366 | D_ASSERT(page == NULL); | 1373 | D_ASSERT(device, page == NULL); |
1367 | D_ASSERT(ds == 0); | 1374 | D_ASSERT(device, ds == 0); |
1368 | 1375 | ||
1369 | atomic_set(&peer_req->pending_bios, n_bios); | 1376 | atomic_set(&peer_req->pending_bios, n_bios); |
1370 | do { | 1377 | do { |
@@ -1372,7 +1379,7 @@ next_bio: | |||
1372 | bios = bios->bi_next; | 1379 | bios = bios->bi_next; |
1373 | bio->bi_next = NULL; | 1380 | bio->bi_next = NULL; |
1374 | 1381 | ||
1375 | drbd_generic_make_request(mdev, fault_type, bio); | 1382 | drbd_generic_make_request(device, fault_type, bio); |
1376 | } while (bios); | 1383 | } while (bios); |
1377 | return 0; | 1384 | return 0; |
1378 | 1385 | ||
@@ -1385,36 +1392,44 @@ fail: | |||
1385 | return err; | 1392 | return err; |
1386 | } | 1393 | } |
1387 | 1394 | ||
1388 | static void drbd_remove_epoch_entry_interval(struct drbd_conf *mdev, | 1395 | static void drbd_remove_epoch_entry_interval(struct drbd_device *device, |
1389 | struct drbd_peer_request *peer_req) | 1396 | struct drbd_peer_request *peer_req) |
1390 | { | 1397 | { |
1391 | struct drbd_interval *i = &peer_req->i; | 1398 | struct drbd_interval *i = &peer_req->i; |
1392 | 1399 | ||
1393 | drbd_remove_interval(&mdev->write_requests, i); | 1400 | drbd_remove_interval(&device->write_requests, i); |
1394 | drbd_clear_interval(i); | 1401 | drbd_clear_interval(i); |
1395 | 1402 | ||
1396 | /* Wake up any processes waiting for this peer request to complete. */ | 1403 | /* Wake up any processes waiting for this peer request to complete. */ |
1397 | if (i->waiting) | 1404 | if (i->waiting) |
1398 | wake_up(&mdev->misc_wait); | 1405 | wake_up(&device->misc_wait); |
1399 | } | 1406 | } |
1400 | 1407 | ||
1401 | void conn_wait_active_ee_empty(struct drbd_tconn *tconn) | 1408 | static void conn_wait_active_ee_empty(struct drbd_connection *connection) |
1402 | { | 1409 | { |
1403 | struct drbd_conf *mdev; | 1410 | struct drbd_peer_device *peer_device; |
1404 | int vnr; | 1411 | int vnr; |
1405 | 1412 | ||
1406 | rcu_read_lock(); | 1413 | rcu_read_lock(); |
1407 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1414 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1408 | kref_get(&mdev->kref); | 1415 | struct drbd_device *device = peer_device->device; |
1416 | |||
1417 | kref_get(&device->kref); | ||
1409 | rcu_read_unlock(); | 1418 | rcu_read_unlock(); |
1410 | drbd_wait_ee_list_empty(mdev, &mdev->active_ee); | 1419 | drbd_wait_ee_list_empty(device, &device->active_ee); |
1411 | kref_put(&mdev->kref, &drbd_minor_destroy); | 1420 | kref_put(&device->kref, drbd_destroy_device); |
1412 | rcu_read_lock(); | 1421 | rcu_read_lock(); |
1413 | } | 1422 | } |
1414 | rcu_read_unlock(); | 1423 | rcu_read_unlock(); |
1415 | } | 1424 | } |
1416 | 1425 | ||
1417 | static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | 1426 | static struct drbd_peer_device * |
1427 | conn_peer_device(struct drbd_connection *connection, int volume_number) | ||
1428 | { | ||
1429 | return idr_find(&connection->peer_devices, volume_number); | ||
1430 | } | ||
1431 | |||
1432 | static int receive_Barrier(struct drbd_connection *connection, struct packet_info *pi) | ||
1418 | { | 1433 | { |
1419 | int rv; | 1434 | int rv; |
1420 | struct p_barrier *p = pi->data; | 1435 | struct p_barrier *p = pi->data; |
@@ -1423,16 +1438,16 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1423 | /* FIXME these are unacked on connection, | 1438 | /* FIXME these are unacked on connection, |
1424 | * not a specific (peer)device. | 1439 | * not a specific (peer)device. |
1425 | */ | 1440 | */ |
1426 | tconn->current_epoch->barrier_nr = p->barrier; | 1441 | connection->current_epoch->barrier_nr = p->barrier; |
1427 | tconn->current_epoch->tconn = tconn; | 1442 | connection->current_epoch->connection = connection; |
1428 | rv = drbd_may_finish_epoch(tconn, tconn->current_epoch, EV_GOT_BARRIER_NR); | 1443 | rv = drbd_may_finish_epoch(connection, connection->current_epoch, EV_GOT_BARRIER_NR); |
1429 | 1444 | ||
1430 | /* P_BARRIER_ACK may imply that the corresponding extent is dropped from | 1445 | /* P_BARRIER_ACK may imply that the corresponding extent is dropped from |
1431 | * the activity log, which means it would not be resynced in case the | 1446 | * the activity log, which means it would not be resynced in case the |
1432 | * R_PRIMARY crashes now. | 1447 | * R_PRIMARY crashes now. |
1433 | * Therefore we must send the barrier_ack after the barrier request was | 1448 | * Therefore we must send the barrier_ack after the barrier request was |
1434 | * completed. */ | 1449 | * completed. */ |
1435 | switch (tconn->write_ordering) { | 1450 | switch (connection->write_ordering) { |
1436 | case WO_none: | 1451 | case WO_none: |
1437 | if (rv == FE_RECYCLED) | 1452 | if (rv == FE_RECYCLED) |
1438 | return 0; | 1453 | return 0; |
@@ -1443,15 +1458,15 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1443 | if (epoch) | 1458 | if (epoch) |
1444 | break; | 1459 | break; |
1445 | else | 1460 | else |
1446 | conn_warn(tconn, "Allocation of an epoch failed, slowing down\n"); | 1461 | drbd_warn(connection, "Allocation of an epoch failed, slowing down\n"); |
1447 | /* Fall through */ | 1462 | /* Fall through */ |
1448 | 1463 | ||
1449 | case WO_bdev_flush: | 1464 | case WO_bdev_flush: |
1450 | case WO_drain_io: | 1465 | case WO_drain_io: |
1451 | conn_wait_active_ee_empty(tconn); | 1466 | conn_wait_active_ee_empty(connection); |
1452 | drbd_flush(tconn); | 1467 | drbd_flush(connection); |
1453 | 1468 | ||
1454 | if (atomic_read(&tconn->current_epoch->epoch_size)) { | 1469 | if (atomic_read(&connection->current_epoch->epoch_size)) { |
1455 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); | 1470 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
1456 | if (epoch) | 1471 | if (epoch) |
1457 | break; | 1472 | break; |
@@ -1459,7 +1474,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1459 | 1474 | ||
1460 | return 0; | 1475 | return 0; |
1461 | default: | 1476 | default: |
1462 | conn_err(tconn, "Strangeness in tconn->write_ordering %d\n", tconn->write_ordering); | 1477 | drbd_err(connection, "Strangeness in connection->write_ordering %d\n", connection->write_ordering); |
1463 | return -EIO; | 1478 | return -EIO; |
1464 | } | 1479 | } |
1465 | 1480 | ||
@@ -1467,16 +1482,16 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1467 | atomic_set(&epoch->epoch_size, 0); | 1482 | atomic_set(&epoch->epoch_size, 0); |
1468 | atomic_set(&epoch->active, 0); | 1483 | atomic_set(&epoch->active, 0); |
1469 | 1484 | ||
1470 | spin_lock(&tconn->epoch_lock); | 1485 | spin_lock(&connection->epoch_lock); |
1471 | if (atomic_read(&tconn->current_epoch->epoch_size)) { | 1486 | if (atomic_read(&connection->current_epoch->epoch_size)) { |
1472 | list_add(&epoch->list, &tconn->current_epoch->list); | 1487 | list_add(&epoch->list, &connection->current_epoch->list); |
1473 | tconn->current_epoch = epoch; | 1488 | connection->current_epoch = epoch; |
1474 | tconn->epochs++; | 1489 | connection->epochs++; |
1475 | } else { | 1490 | } else { |
1476 | /* The current_epoch got recycled while we allocated this one... */ | 1491 | /* The current_epoch got recycled while we allocated this one... */ |
1477 | kfree(epoch); | 1492 | kfree(epoch); |
1478 | } | 1493 | } |
1479 | spin_unlock(&tconn->epoch_lock); | 1494 | spin_unlock(&connection->epoch_lock); |
1480 | 1495 | ||
1481 | return 0; | 1496 | return 0; |
1482 | } | 1497 | } |
@@ -1484,25 +1499,26 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1484 | /* used from receive_RSDataReply (recv_resync_read) | 1499 | /* used from receive_RSDataReply (recv_resync_read) |
1485 | * and from receive_Data */ | 1500 | * and from receive_Data */ |
1486 | static struct drbd_peer_request * | 1501 | static struct drbd_peer_request * |
1487 | read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, | 1502 | read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, |
1488 | int data_size) __must_hold(local) | 1503 | int data_size) __must_hold(local) |
1489 | { | 1504 | { |
1490 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); | 1505 | struct drbd_device *device = peer_device->device; |
1506 | const sector_t capacity = drbd_get_capacity(device->this_bdev); | ||
1491 | struct drbd_peer_request *peer_req; | 1507 | struct drbd_peer_request *peer_req; |
1492 | struct page *page; | 1508 | struct page *page; |
1493 | int dgs, ds, err; | 1509 | int dgs, ds, err; |
1494 | void *dig_in = mdev->tconn->int_dig_in; | 1510 | void *dig_in = peer_device->connection->int_dig_in; |
1495 | void *dig_vv = mdev->tconn->int_dig_vv; | 1511 | void *dig_vv = peer_device->connection->int_dig_vv; |
1496 | unsigned long *data; | 1512 | unsigned long *data; |
1497 | 1513 | ||
1498 | dgs = 0; | 1514 | dgs = 0; |
1499 | if (mdev->tconn->peer_integrity_tfm) { | 1515 | if (peer_device->connection->peer_integrity_tfm) { |
1500 | dgs = crypto_hash_digestsize(mdev->tconn->peer_integrity_tfm); | 1516 | dgs = crypto_hash_digestsize(peer_device->connection->peer_integrity_tfm); |
1501 | /* | 1517 | /* |
1502 | * FIXME: Receive the incoming digest into the receive buffer | 1518 | * FIXME: Receive the incoming digest into the receive buffer |
1503 | * here, together with its struct p_data? | 1519 | * here, together with its struct p_data? |
1504 | */ | 1520 | */ |
1505 | err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs); | 1521 | err = drbd_recv_all_warn(peer_device->connection, dig_in, dgs); |
1506 | if (err) | 1522 | if (err) |
1507 | return NULL; | 1523 | return NULL; |
1508 | data_size -= dgs; | 1524 | data_size -= dgs; |
@@ -1516,7 +1532,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, | |||
1516 | /* even though we trust out peer, | 1532 | /* even though we trust out peer, |
1517 | * we sometimes have to double check. */ | 1533 | * we sometimes have to double check. */ |
1518 | if (sector + (data_size>>9) > capacity) { | 1534 | if (sector + (data_size>>9) > capacity) { |
1519 | dev_err(DEV, "request from peer beyond end of local disk: " | 1535 | drbd_err(device, "request from peer beyond end of local disk: " |
1520 | "capacity: %llus < sector: %llus + size: %u\n", | 1536 | "capacity: %llus < sector: %llus + size: %u\n", |
1521 | (unsigned long long)capacity, | 1537 | (unsigned long long)capacity, |
1522 | (unsigned long long)sector, data_size); | 1538 | (unsigned long long)sector, data_size); |
@@ -1526,7 +1542,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, | |||
1526 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD | 1542 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
1527 | * "criss-cross" setup, that might cause write-out on some other DRBD, | 1543 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
1528 | * which in turn might block on the other node at this very place. */ | 1544 | * which in turn might block on the other node at this very place. */ |
1529 | peer_req = drbd_alloc_peer_req(mdev, id, sector, data_size, GFP_NOIO); | 1545 | peer_req = drbd_alloc_peer_req(peer_device, id, sector, data_size, GFP_NOIO); |
1530 | if (!peer_req) | 1546 | if (!peer_req) |
1531 | return NULL; | 1547 | return NULL; |
1532 | 1548 | ||
@@ -1538,36 +1554,36 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, | |||
1538 | page_chain_for_each(page) { | 1554 | page_chain_for_each(page) { |
1539 | unsigned len = min_t(int, ds, PAGE_SIZE); | 1555 | unsigned len = min_t(int, ds, PAGE_SIZE); |
1540 | data = kmap(page); | 1556 | data = kmap(page); |
1541 | err = drbd_recv_all_warn(mdev->tconn, data, len); | 1557 | err = drbd_recv_all_warn(peer_device->connection, data, len); |
1542 | if (drbd_insert_fault(mdev, DRBD_FAULT_RECEIVE)) { | 1558 | if (drbd_insert_fault(device, DRBD_FAULT_RECEIVE)) { |
1543 | dev_err(DEV, "Fault injection: Corrupting data on receive\n"); | 1559 | drbd_err(device, "Fault injection: Corrupting data on receive\n"); |
1544 | data[0] = data[0] ^ (unsigned long)-1; | 1560 | data[0] = data[0] ^ (unsigned long)-1; |
1545 | } | 1561 | } |
1546 | kunmap(page); | 1562 | kunmap(page); |
1547 | if (err) { | 1563 | if (err) { |
1548 | drbd_free_peer_req(mdev, peer_req); | 1564 | drbd_free_peer_req(device, peer_req); |
1549 | return NULL; | 1565 | return NULL; |
1550 | } | 1566 | } |
1551 | ds -= len; | 1567 | ds -= len; |
1552 | } | 1568 | } |
1553 | 1569 | ||
1554 | if (dgs) { | 1570 | if (dgs) { |
1555 | drbd_csum_ee(mdev, mdev->tconn->peer_integrity_tfm, peer_req, dig_vv); | 1571 | drbd_csum_ee(peer_device->connection->peer_integrity_tfm, peer_req, dig_vv); |
1556 | if (memcmp(dig_in, dig_vv, dgs)) { | 1572 | if (memcmp(dig_in, dig_vv, dgs)) { |
1557 | dev_err(DEV, "Digest integrity check FAILED: %llus +%u\n", | 1573 | drbd_err(device, "Digest integrity check FAILED: %llus +%u\n", |
1558 | (unsigned long long)sector, data_size); | 1574 | (unsigned long long)sector, data_size); |
1559 | drbd_free_peer_req(mdev, peer_req); | 1575 | drbd_free_peer_req(device, peer_req); |
1560 | return NULL; | 1576 | return NULL; |
1561 | } | 1577 | } |
1562 | } | 1578 | } |
1563 | mdev->recv_cnt += data_size>>9; | 1579 | device->recv_cnt += data_size>>9; |
1564 | return peer_req; | 1580 | return peer_req; |
1565 | } | 1581 | } |
1566 | 1582 | ||
1567 | /* drbd_drain_block() just takes a data block | 1583 | /* drbd_drain_block() just takes a data block |
1568 | * out of the socket input buffer, and discards it. | 1584 | * out of the socket input buffer, and discards it. |
1569 | */ | 1585 | */ |
1570 | static int drbd_drain_block(struct drbd_conf *mdev, int data_size) | 1586 | static int drbd_drain_block(struct drbd_peer_device *peer_device, int data_size) |
1571 | { | 1587 | { |
1572 | struct page *page; | 1588 | struct page *page; |
1573 | int err = 0; | 1589 | int err = 0; |
@@ -1576,36 +1592,36 @@ static int drbd_drain_block(struct drbd_conf *mdev, int data_size) | |||
1576 | if (!data_size) | 1592 | if (!data_size) |
1577 | return 0; | 1593 | return 0; |
1578 | 1594 | ||
1579 | page = drbd_alloc_pages(mdev, 1, 1); | 1595 | page = drbd_alloc_pages(peer_device, 1, 1); |
1580 | 1596 | ||
1581 | data = kmap(page); | 1597 | data = kmap(page); |
1582 | while (data_size) { | 1598 | while (data_size) { |
1583 | unsigned int len = min_t(int, data_size, PAGE_SIZE); | 1599 | unsigned int len = min_t(int, data_size, PAGE_SIZE); |
1584 | 1600 | ||
1585 | err = drbd_recv_all_warn(mdev->tconn, data, len); | 1601 | err = drbd_recv_all_warn(peer_device->connection, data, len); |
1586 | if (err) | 1602 | if (err) |
1587 | break; | 1603 | break; |
1588 | data_size -= len; | 1604 | data_size -= len; |
1589 | } | 1605 | } |
1590 | kunmap(page); | 1606 | kunmap(page); |
1591 | drbd_free_pages(mdev, page, 0); | 1607 | drbd_free_pages(peer_device->device, page, 0); |
1592 | return err; | 1608 | return err; |
1593 | } | 1609 | } |
1594 | 1610 | ||
1595 | static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, | 1611 | static int recv_dless_read(struct drbd_peer_device *peer_device, struct drbd_request *req, |
1596 | sector_t sector, int data_size) | 1612 | sector_t sector, int data_size) |
1597 | { | 1613 | { |
1598 | struct bio_vec bvec; | 1614 | struct bio_vec bvec; |
1599 | struct bvec_iter iter; | 1615 | struct bvec_iter iter; |
1600 | struct bio *bio; | 1616 | struct bio *bio; |
1601 | int dgs, err, expect; | 1617 | int dgs, err, expect; |
1602 | void *dig_in = mdev->tconn->int_dig_in; | 1618 | void *dig_in = peer_device->connection->int_dig_in; |
1603 | void *dig_vv = mdev->tconn->int_dig_vv; | 1619 | void *dig_vv = peer_device->connection->int_dig_vv; |
1604 | 1620 | ||
1605 | dgs = 0; | 1621 | dgs = 0; |
1606 | if (mdev->tconn->peer_integrity_tfm) { | 1622 | if (peer_device->connection->peer_integrity_tfm) { |
1607 | dgs = crypto_hash_digestsize(mdev->tconn->peer_integrity_tfm); | 1623 | dgs = crypto_hash_digestsize(peer_device->connection->peer_integrity_tfm); |
1608 | err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs); | 1624 | err = drbd_recv_all_warn(peer_device->connection, dig_in, dgs); |
1609 | if (err) | 1625 | if (err) |
1610 | return err; | 1626 | return err; |
1611 | data_size -= dgs; | 1627 | data_size -= dgs; |
@@ -1613,15 +1629,15 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, | |||
1613 | 1629 | ||
1614 | /* optimistically update recv_cnt. if receiving fails below, | 1630 | /* optimistically update recv_cnt. if receiving fails below, |
1615 | * we disconnect anyways, and counters will be reset. */ | 1631 | * we disconnect anyways, and counters will be reset. */ |
1616 | mdev->recv_cnt += data_size>>9; | 1632 | peer_device->device->recv_cnt += data_size>>9; |
1617 | 1633 | ||
1618 | bio = req->master_bio; | 1634 | bio = req->master_bio; |
1619 | D_ASSERT(sector == bio->bi_iter.bi_sector); | 1635 | D_ASSERT(peer_device->device, sector == bio->bi_iter.bi_sector); |
1620 | 1636 | ||
1621 | bio_for_each_segment(bvec, bio, iter) { | 1637 | bio_for_each_segment(bvec, bio, iter) { |
1622 | void *mapped = kmap(bvec.bv_page) + bvec.bv_offset; | 1638 | void *mapped = kmap(bvec.bv_page) + bvec.bv_offset; |
1623 | expect = min_t(int, data_size, bvec.bv_len); | 1639 | expect = min_t(int, data_size, bvec.bv_len); |
1624 | err = drbd_recv_all_warn(mdev->tconn, mapped, expect); | 1640 | err = drbd_recv_all_warn(peer_device->connection, mapped, expect); |
1625 | kunmap(bvec.bv_page); | 1641 | kunmap(bvec.bv_page); |
1626 | if (err) | 1642 | if (err) |
1627 | return err; | 1643 | return err; |
@@ -1629,14 +1645,14 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, | |||
1629 | } | 1645 | } |
1630 | 1646 | ||
1631 | if (dgs) { | 1647 | if (dgs) { |
1632 | drbd_csum_bio(mdev, mdev->tconn->peer_integrity_tfm, bio, dig_vv); | 1648 | drbd_csum_bio(peer_device->connection->peer_integrity_tfm, bio, dig_vv); |
1633 | if (memcmp(dig_in, dig_vv, dgs)) { | 1649 | if (memcmp(dig_in, dig_vv, dgs)) { |
1634 | dev_err(DEV, "Digest integrity check FAILED. Broken NICs?\n"); | 1650 | drbd_err(peer_device, "Digest integrity check FAILED. Broken NICs?\n"); |
1635 | return -EINVAL; | 1651 | return -EINVAL; |
1636 | } | 1652 | } |
1637 | } | 1653 | } |
1638 | 1654 | ||
1639 | D_ASSERT(data_size == 0); | 1655 | D_ASSERT(peer_device->device, data_size == 0); |
1640 | return 0; | 1656 | return 0; |
1641 | } | 1657 | } |
1642 | 1658 | ||
@@ -1648,64 +1664,67 @@ static int e_end_resync_block(struct drbd_work *w, int unused) | |||
1648 | { | 1664 | { |
1649 | struct drbd_peer_request *peer_req = | 1665 | struct drbd_peer_request *peer_req = |
1650 | container_of(w, struct drbd_peer_request, w); | 1666 | container_of(w, struct drbd_peer_request, w); |
1651 | struct drbd_conf *mdev = w->mdev; | 1667 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1668 | struct drbd_device *device = peer_device->device; | ||
1652 | sector_t sector = peer_req->i.sector; | 1669 | sector_t sector = peer_req->i.sector; |
1653 | int err; | 1670 | int err; |
1654 | 1671 | ||
1655 | D_ASSERT(drbd_interval_empty(&peer_req->i)); | 1672 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
1656 | 1673 | ||
1657 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { | 1674 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
1658 | drbd_set_in_sync(mdev, sector, peer_req->i.size); | 1675 | drbd_set_in_sync(device, sector, peer_req->i.size); |
1659 | err = drbd_send_ack(mdev, P_RS_WRITE_ACK, peer_req); | 1676 | err = drbd_send_ack(peer_device, P_RS_WRITE_ACK, peer_req); |
1660 | } else { | 1677 | } else { |
1661 | /* Record failure to sync */ | 1678 | /* Record failure to sync */ |
1662 | drbd_rs_failed_io(mdev, sector, peer_req->i.size); | 1679 | drbd_rs_failed_io(device, sector, peer_req->i.size); |
1663 | 1680 | ||
1664 | err = drbd_send_ack(mdev, P_NEG_ACK, peer_req); | 1681 | err = drbd_send_ack(peer_device, P_NEG_ACK, peer_req); |
1665 | } | 1682 | } |
1666 | dec_unacked(mdev); | 1683 | dec_unacked(device); |
1667 | 1684 | ||
1668 | return err; | 1685 | return err; |
1669 | } | 1686 | } |
1670 | 1687 | ||
1671 | static int recv_resync_read(struct drbd_conf *mdev, sector_t sector, int data_size) __releases(local) | 1688 | static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t sector, |
1689 | int data_size) __releases(local) | ||
1672 | { | 1690 | { |
1691 | struct drbd_device *device = peer_device->device; | ||
1673 | struct drbd_peer_request *peer_req; | 1692 | struct drbd_peer_request *peer_req; |
1674 | 1693 | ||
1675 | peer_req = read_in_block(mdev, ID_SYNCER, sector, data_size); | 1694 | peer_req = read_in_block(peer_device, ID_SYNCER, sector, data_size); |
1676 | if (!peer_req) | 1695 | if (!peer_req) |
1677 | goto fail; | 1696 | goto fail; |
1678 | 1697 | ||
1679 | dec_rs_pending(mdev); | 1698 | dec_rs_pending(device); |
1680 | 1699 | ||
1681 | inc_unacked(mdev); | 1700 | inc_unacked(device); |
1682 | /* corresponding dec_unacked() in e_end_resync_block() | 1701 | /* corresponding dec_unacked() in e_end_resync_block() |
1683 | * respective _drbd_clear_done_ee */ | 1702 | * respective _drbd_clear_done_ee */ |
1684 | 1703 | ||
1685 | peer_req->w.cb = e_end_resync_block; | 1704 | peer_req->w.cb = e_end_resync_block; |
1686 | 1705 | ||
1687 | spin_lock_irq(&mdev->tconn->req_lock); | 1706 | spin_lock_irq(&device->resource->req_lock); |
1688 | list_add(&peer_req->w.list, &mdev->sync_ee); | 1707 | list_add(&peer_req->w.list, &device->sync_ee); |
1689 | spin_unlock_irq(&mdev->tconn->req_lock); | 1708 | spin_unlock_irq(&device->resource->req_lock); |
1690 | 1709 | ||
1691 | atomic_add(data_size >> 9, &mdev->rs_sect_ev); | 1710 | atomic_add(data_size >> 9, &device->rs_sect_ev); |
1692 | if (drbd_submit_peer_request(mdev, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0) | 1711 | if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0) |
1693 | return 0; | 1712 | return 0; |
1694 | 1713 | ||
1695 | /* don't care for the reason here */ | 1714 | /* don't care for the reason here */ |
1696 | dev_err(DEV, "submit failed, triggering re-connect\n"); | 1715 | drbd_err(device, "submit failed, triggering re-connect\n"); |
1697 | spin_lock_irq(&mdev->tconn->req_lock); | 1716 | spin_lock_irq(&device->resource->req_lock); |
1698 | list_del(&peer_req->w.list); | 1717 | list_del(&peer_req->w.list); |
1699 | spin_unlock_irq(&mdev->tconn->req_lock); | 1718 | spin_unlock_irq(&device->resource->req_lock); |
1700 | 1719 | ||
1701 | drbd_free_peer_req(mdev, peer_req); | 1720 | drbd_free_peer_req(device, peer_req); |
1702 | fail: | 1721 | fail: |
1703 | put_ldev(mdev); | 1722 | put_ldev(device); |
1704 | return -EIO; | 1723 | return -EIO; |
1705 | } | 1724 | } |
1706 | 1725 | ||
1707 | static struct drbd_request * | 1726 | static struct drbd_request * |
1708 | find_request(struct drbd_conf *mdev, struct rb_root *root, u64 id, | 1727 | find_request(struct drbd_device *device, struct rb_root *root, u64 id, |
1709 | sector_t sector, bool missing_ok, const char *func) | 1728 | sector_t sector, bool missing_ok, const char *func) |
1710 | { | 1729 | { |
1711 | struct drbd_request *req; | 1730 | struct drbd_request *req; |
@@ -1715,36 +1734,38 @@ find_request(struct drbd_conf *mdev, struct rb_root *root, u64 id, | |||
1715 | if (drbd_contains_interval(root, sector, &req->i) && req->i.local) | 1734 | if (drbd_contains_interval(root, sector, &req->i) && req->i.local) |
1716 | return req; | 1735 | return req; |
1717 | if (!missing_ok) { | 1736 | if (!missing_ok) { |
1718 | dev_err(DEV, "%s: failed to find request 0x%lx, sector %llus\n", func, | 1737 | drbd_err(device, "%s: failed to find request 0x%lx, sector %llus\n", func, |
1719 | (unsigned long)id, (unsigned long long)sector); | 1738 | (unsigned long)id, (unsigned long long)sector); |
1720 | } | 1739 | } |
1721 | return NULL; | 1740 | return NULL; |
1722 | } | 1741 | } |
1723 | 1742 | ||
1724 | static int receive_DataReply(struct drbd_tconn *tconn, struct packet_info *pi) | 1743 | static int receive_DataReply(struct drbd_connection *connection, struct packet_info *pi) |
1725 | { | 1744 | { |
1726 | struct drbd_conf *mdev; | 1745 | struct drbd_peer_device *peer_device; |
1746 | struct drbd_device *device; | ||
1727 | struct drbd_request *req; | 1747 | struct drbd_request *req; |
1728 | sector_t sector; | 1748 | sector_t sector; |
1729 | int err; | 1749 | int err; |
1730 | struct p_data *p = pi->data; | 1750 | struct p_data *p = pi->data; |
1731 | 1751 | ||
1732 | mdev = vnr_to_mdev(tconn, pi->vnr); | 1752 | peer_device = conn_peer_device(connection, pi->vnr); |
1733 | if (!mdev) | 1753 | if (!peer_device) |
1734 | return -EIO; | 1754 | return -EIO; |
1755 | device = peer_device->device; | ||
1735 | 1756 | ||
1736 | sector = be64_to_cpu(p->sector); | 1757 | sector = be64_to_cpu(p->sector); |
1737 | 1758 | ||
1738 | spin_lock_irq(&mdev->tconn->req_lock); | 1759 | spin_lock_irq(&device->resource->req_lock); |
1739 | req = find_request(mdev, &mdev->read_requests, p->block_id, sector, false, __func__); | 1760 | req = find_request(device, &device->read_requests, p->block_id, sector, false, __func__); |
1740 | spin_unlock_irq(&mdev->tconn->req_lock); | 1761 | spin_unlock_irq(&device->resource->req_lock); |
1741 | if (unlikely(!req)) | 1762 | if (unlikely(!req)) |
1742 | return -EIO; | 1763 | return -EIO; |
1743 | 1764 | ||
1744 | /* hlist_del(&req->collision) is done in _req_may_be_done, to avoid | 1765 | /* hlist_del(&req->collision) is done in _req_may_be_done, to avoid |
1745 | * special casing it there for the various failure cases. | 1766 | * special casing it there for the various failure cases. |
1746 | * still no race with drbd_fail_pending_reads */ | 1767 | * still no race with drbd_fail_pending_reads */ |
1747 | err = recv_dless_read(mdev, req, sector, pi->size); | 1768 | err = recv_dless_read(peer_device, req, sector, pi->size); |
1748 | if (!err) | 1769 | if (!err) |
1749 | req_mod(req, DATA_RECEIVED); | 1770 | req_mod(req, DATA_RECEIVED); |
1750 | /* else: nothing. handled from drbd_disconnect... | 1771 | /* else: nothing. handled from drbd_disconnect... |
@@ -1754,46 +1775,48 @@ static int receive_DataReply(struct drbd_tconn *tconn, struct packet_info *pi) | |||
1754 | return err; | 1775 | return err; |
1755 | } | 1776 | } |
1756 | 1777 | ||
1757 | static int receive_RSDataReply(struct drbd_tconn *tconn, struct packet_info *pi) | 1778 | static int receive_RSDataReply(struct drbd_connection *connection, struct packet_info *pi) |
1758 | { | 1779 | { |
1759 | struct drbd_conf *mdev; | 1780 | struct drbd_peer_device *peer_device; |
1781 | struct drbd_device *device; | ||
1760 | sector_t sector; | 1782 | sector_t sector; |
1761 | int err; | 1783 | int err; |
1762 | struct p_data *p = pi->data; | 1784 | struct p_data *p = pi->data; |
1763 | 1785 | ||
1764 | mdev = vnr_to_mdev(tconn, pi->vnr); | 1786 | peer_device = conn_peer_device(connection, pi->vnr); |
1765 | if (!mdev) | 1787 | if (!peer_device) |
1766 | return -EIO; | 1788 | return -EIO; |
1789 | device = peer_device->device; | ||
1767 | 1790 | ||
1768 | sector = be64_to_cpu(p->sector); | 1791 | sector = be64_to_cpu(p->sector); |
1769 | D_ASSERT(p->block_id == ID_SYNCER); | 1792 | D_ASSERT(device, p->block_id == ID_SYNCER); |
1770 | 1793 | ||
1771 | if (get_ldev(mdev)) { | 1794 | if (get_ldev(device)) { |
1772 | /* data is submitted to disk within recv_resync_read. | 1795 | /* data is submitted to disk within recv_resync_read. |
1773 | * corresponding put_ldev done below on error, | 1796 | * corresponding put_ldev done below on error, |
1774 | * or in drbd_peer_request_endio. */ | 1797 | * or in drbd_peer_request_endio. */ |
1775 | err = recv_resync_read(mdev, sector, pi->size); | 1798 | err = recv_resync_read(peer_device, sector, pi->size); |
1776 | } else { | 1799 | } else { |
1777 | if (__ratelimit(&drbd_ratelimit_state)) | 1800 | if (__ratelimit(&drbd_ratelimit_state)) |
1778 | dev_err(DEV, "Can not write resync data to local disk.\n"); | 1801 | drbd_err(device, "Can not write resync data to local disk.\n"); |
1779 | 1802 | ||
1780 | err = drbd_drain_block(mdev, pi->size); | 1803 | err = drbd_drain_block(peer_device, pi->size); |
1781 | 1804 | ||
1782 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size); | 1805 | drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); |
1783 | } | 1806 | } |
1784 | 1807 | ||
1785 | atomic_add(pi->size >> 9, &mdev->rs_sect_in); | 1808 | atomic_add(pi->size >> 9, &device->rs_sect_in); |
1786 | 1809 | ||
1787 | return err; | 1810 | return err; |
1788 | } | 1811 | } |
1789 | 1812 | ||
1790 | static void restart_conflicting_writes(struct drbd_conf *mdev, | 1813 | static void restart_conflicting_writes(struct drbd_device *device, |
1791 | sector_t sector, int size) | 1814 | sector_t sector, int size) |
1792 | { | 1815 | { |
1793 | struct drbd_interval *i; | 1816 | struct drbd_interval *i; |
1794 | struct drbd_request *req; | 1817 | struct drbd_request *req; |
1795 | 1818 | ||
1796 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { | 1819 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
1797 | if (!i->local) | 1820 | if (!i->local) |
1798 | continue; | 1821 | continue; |
1799 | req = container_of(i, struct drbd_request, i); | 1822 | req = container_of(i, struct drbd_request, i); |
@@ -1813,52 +1836,53 @@ static int e_end_block(struct drbd_work *w, int cancel) | |||
1813 | { | 1836 | { |
1814 | struct drbd_peer_request *peer_req = | 1837 | struct drbd_peer_request *peer_req = |
1815 | container_of(w, struct drbd_peer_request, w); | 1838 | container_of(w, struct drbd_peer_request, w); |
1816 | struct drbd_conf *mdev = w->mdev; | 1839 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1840 | struct drbd_device *device = peer_device->device; | ||
1817 | sector_t sector = peer_req->i.sector; | 1841 | sector_t sector = peer_req->i.sector; |
1818 | int err = 0, pcmd; | 1842 | int err = 0, pcmd; |
1819 | 1843 | ||
1820 | if (peer_req->flags & EE_SEND_WRITE_ACK) { | 1844 | if (peer_req->flags & EE_SEND_WRITE_ACK) { |
1821 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { | 1845 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
1822 | pcmd = (mdev->state.conn >= C_SYNC_SOURCE && | 1846 | pcmd = (device->state.conn >= C_SYNC_SOURCE && |
1823 | mdev->state.conn <= C_PAUSED_SYNC_T && | 1847 | device->state.conn <= C_PAUSED_SYNC_T && |
1824 | peer_req->flags & EE_MAY_SET_IN_SYNC) ? | 1848 | peer_req->flags & EE_MAY_SET_IN_SYNC) ? |
1825 | P_RS_WRITE_ACK : P_WRITE_ACK; | 1849 | P_RS_WRITE_ACK : P_WRITE_ACK; |
1826 | err = drbd_send_ack(mdev, pcmd, peer_req); | 1850 | err = drbd_send_ack(peer_device, pcmd, peer_req); |
1827 | if (pcmd == P_RS_WRITE_ACK) | 1851 | if (pcmd == P_RS_WRITE_ACK) |
1828 | drbd_set_in_sync(mdev, sector, peer_req->i.size); | 1852 | drbd_set_in_sync(device, sector, peer_req->i.size); |
1829 | } else { | 1853 | } else { |
1830 | err = drbd_send_ack(mdev, P_NEG_ACK, peer_req); | 1854 | err = drbd_send_ack(peer_device, P_NEG_ACK, peer_req); |
1831 | /* we expect it to be marked out of sync anyways... | 1855 | /* we expect it to be marked out of sync anyways... |
1832 | * maybe assert this? */ | 1856 | * maybe assert this? */ |
1833 | } | 1857 | } |
1834 | dec_unacked(mdev); | 1858 | dec_unacked(device); |
1835 | } | 1859 | } |
1836 | /* we delete from the conflict detection hash _after_ we sent out the | 1860 | /* we delete from the conflict detection hash _after_ we sent out the |
1837 | * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */ | 1861 | * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */ |
1838 | if (peer_req->flags & EE_IN_INTERVAL_TREE) { | 1862 | if (peer_req->flags & EE_IN_INTERVAL_TREE) { |
1839 | spin_lock_irq(&mdev->tconn->req_lock); | 1863 | spin_lock_irq(&device->resource->req_lock); |
1840 | D_ASSERT(!drbd_interval_empty(&peer_req->i)); | 1864 | D_ASSERT(device, !drbd_interval_empty(&peer_req->i)); |
1841 | drbd_remove_epoch_entry_interval(mdev, peer_req); | 1865 | drbd_remove_epoch_entry_interval(device, peer_req); |
1842 | if (peer_req->flags & EE_RESTART_REQUESTS) | 1866 | if (peer_req->flags & EE_RESTART_REQUESTS) |
1843 | restart_conflicting_writes(mdev, sector, peer_req->i.size); | 1867 | restart_conflicting_writes(device, sector, peer_req->i.size); |
1844 | spin_unlock_irq(&mdev->tconn->req_lock); | 1868 | spin_unlock_irq(&device->resource->req_lock); |
1845 | } else | 1869 | } else |
1846 | D_ASSERT(drbd_interval_empty(&peer_req->i)); | 1870 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
1847 | 1871 | ||
1848 | drbd_may_finish_epoch(mdev->tconn, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)); | 1872 | drbd_may_finish_epoch(first_peer_device(device)->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)); |
1849 | 1873 | ||
1850 | return err; | 1874 | return err; |
1851 | } | 1875 | } |
1852 | 1876 | ||
1853 | static int e_send_ack(struct drbd_work *w, enum drbd_packet ack) | 1877 | static int e_send_ack(struct drbd_work *w, enum drbd_packet ack) |
1854 | { | 1878 | { |
1855 | struct drbd_conf *mdev = w->mdev; | ||
1856 | struct drbd_peer_request *peer_req = | 1879 | struct drbd_peer_request *peer_req = |
1857 | container_of(w, struct drbd_peer_request, w); | 1880 | container_of(w, struct drbd_peer_request, w); |
1881 | struct drbd_peer_device *peer_device = peer_req->peer_device; | ||
1858 | int err; | 1882 | int err; |
1859 | 1883 | ||
1860 | err = drbd_send_ack(mdev, ack, peer_req); | 1884 | err = drbd_send_ack(peer_device, ack, peer_req); |
1861 | dec_unacked(mdev); | 1885 | dec_unacked(peer_device->device); |
1862 | 1886 | ||
1863 | return err; | 1887 | return err; |
1864 | } | 1888 | } |
@@ -1870,9 +1894,11 @@ static int e_send_superseded(struct drbd_work *w, int unused) | |||
1870 | 1894 | ||
1871 | static int e_send_retry_write(struct drbd_work *w, int unused) | 1895 | static int e_send_retry_write(struct drbd_work *w, int unused) |
1872 | { | 1896 | { |
1873 | struct drbd_tconn *tconn = w->mdev->tconn; | 1897 | struct drbd_peer_request *peer_req = |
1898 | container_of(w, struct drbd_peer_request, w); | ||
1899 | struct drbd_connection *connection = peer_req->peer_device->connection; | ||
1874 | 1900 | ||
1875 | return e_send_ack(w, tconn->agreed_pro_version >= 100 ? | 1901 | return e_send_ack(w, connection->agreed_pro_version >= 100 ? |
1876 | P_RETRY_WRITE : P_SUPERSEDED); | 1902 | P_RETRY_WRITE : P_SUPERSEDED); |
1877 | } | 1903 | } |
1878 | 1904 | ||
@@ -1891,18 +1917,19 @@ static u32 seq_max(u32 a, u32 b) | |||
1891 | return seq_greater(a, b) ? a : b; | 1917 | return seq_greater(a, b) ? a : b; |
1892 | } | 1918 | } |
1893 | 1919 | ||
1894 | static void update_peer_seq(struct drbd_conf *mdev, unsigned int peer_seq) | 1920 | static void update_peer_seq(struct drbd_peer_device *peer_device, unsigned int peer_seq) |
1895 | { | 1921 | { |
1922 | struct drbd_device *device = peer_device->device; | ||
1896 | unsigned int newest_peer_seq; | 1923 | unsigned int newest_peer_seq; |
1897 | 1924 | ||
1898 | if (test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags)) { | 1925 | if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) { |
1899 | spin_lock(&mdev->peer_seq_lock); | 1926 | spin_lock(&device->peer_seq_lock); |
1900 | newest_peer_seq = seq_max(mdev->peer_seq, peer_seq); | 1927 | newest_peer_seq = seq_max(device->peer_seq, peer_seq); |
1901 | mdev->peer_seq = newest_peer_seq; | 1928 | device->peer_seq = newest_peer_seq; |
1902 | spin_unlock(&mdev->peer_seq_lock); | 1929 | spin_unlock(&device->peer_seq_lock); |
1903 | /* wake up only if we actually changed mdev->peer_seq */ | 1930 | /* wake up only if we actually changed device->peer_seq */ |
1904 | if (peer_seq == newest_peer_seq) | 1931 | if (peer_seq == newest_peer_seq) |
1905 | wake_up(&mdev->seq_wait); | 1932 | wake_up(&device->seq_wait); |
1906 | } | 1933 | } |
1907 | } | 1934 | } |
1908 | 1935 | ||
@@ -1912,20 +1939,20 @@ static inline int overlaps(sector_t s1, int l1, sector_t s2, int l2) | |||
1912 | } | 1939 | } |
1913 | 1940 | ||
1914 | /* maybe change sync_ee into interval trees as well? */ | 1941 | /* maybe change sync_ee into interval trees as well? */ |
1915 | static bool overlapping_resync_write(struct drbd_conf *mdev, struct drbd_peer_request *peer_req) | 1942 | static bool overlapping_resync_write(struct drbd_device *device, struct drbd_peer_request *peer_req) |
1916 | { | 1943 | { |
1917 | struct drbd_peer_request *rs_req; | 1944 | struct drbd_peer_request *rs_req; |
1918 | bool rv = 0; | 1945 | bool rv = 0; |
1919 | 1946 | ||
1920 | spin_lock_irq(&mdev->tconn->req_lock); | 1947 | spin_lock_irq(&device->resource->req_lock); |
1921 | list_for_each_entry(rs_req, &mdev->sync_ee, w.list) { | 1948 | list_for_each_entry(rs_req, &device->sync_ee, w.list) { |
1922 | if (overlaps(peer_req->i.sector, peer_req->i.size, | 1949 | if (overlaps(peer_req->i.sector, peer_req->i.size, |
1923 | rs_req->i.sector, rs_req->i.size)) { | 1950 | rs_req->i.sector, rs_req->i.size)) { |
1924 | rv = 1; | 1951 | rv = 1; |
1925 | break; | 1952 | break; |
1926 | } | 1953 | } |
1927 | } | 1954 | } |
1928 | spin_unlock_irq(&mdev->tconn->req_lock); | 1955 | spin_unlock_irq(&device->resource->req_lock); |
1929 | 1956 | ||
1930 | return rv; | 1957 | return rv; |
1931 | } | 1958 | } |
@@ -1939,9 +1966,9 @@ static bool overlapping_resync_write(struct drbd_conf *mdev, struct drbd_peer_re | |||
1939 | * | 1966 | * |
1940 | * Note: we don't care for Ack packets overtaking P_DATA packets. | 1967 | * Note: we don't care for Ack packets overtaking P_DATA packets. |
1941 | * | 1968 | * |
1942 | * In case packet_seq is larger than mdev->peer_seq number, there are | 1969 | * In case packet_seq is larger than device->peer_seq number, there are |
1943 | * outstanding packets on the msock. We wait for them to arrive. | 1970 | * outstanding packets on the msock. We wait for them to arrive. |
1944 | * In case we are the logically next packet, we update mdev->peer_seq | 1971 | * In case we are the logically next packet, we update device->peer_seq |
1945 | * ourselves. Correctly handles 32bit wrap around. | 1972 | * ourselves. Correctly handles 32bit wrap around. |
1946 | * | 1973 | * |
1947 | * Assume we have a 10 GBit connection, that is about 1<<30 byte per second, | 1974 | * Assume we have a 10 GBit connection, that is about 1<<30 byte per second, |
@@ -1951,19 +1978,20 @@ static bool overlapping_resync_write(struct drbd_conf *mdev, struct drbd_peer_re | |||
1951 | * | 1978 | * |
1952 | * returns 0 if we may process the packet, | 1979 | * returns 0 if we may process the packet, |
1953 | * -ERESTARTSYS if we were interrupted (by disconnect signal). */ | 1980 | * -ERESTARTSYS if we were interrupted (by disconnect signal). */ |
1954 | static int wait_for_and_update_peer_seq(struct drbd_conf *mdev, const u32 peer_seq) | 1981 | static int wait_for_and_update_peer_seq(struct drbd_peer_device *peer_device, const u32 peer_seq) |
1955 | { | 1982 | { |
1983 | struct drbd_device *device = peer_device->device; | ||
1956 | DEFINE_WAIT(wait); | 1984 | DEFINE_WAIT(wait); |
1957 | long timeout; | 1985 | long timeout; |
1958 | int ret = 0, tp; | 1986 | int ret = 0, tp; |
1959 | 1987 | ||
1960 | if (!test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags)) | 1988 | if (!test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) |
1961 | return 0; | 1989 | return 0; |
1962 | 1990 | ||
1963 | spin_lock(&mdev->peer_seq_lock); | 1991 | spin_lock(&device->peer_seq_lock); |
1964 | for (;;) { | 1992 | for (;;) { |
1965 | if (!seq_greater(peer_seq - 1, mdev->peer_seq)) { | 1993 | if (!seq_greater(peer_seq - 1, device->peer_seq)) { |
1966 | mdev->peer_seq = seq_max(mdev->peer_seq, peer_seq); | 1994 | device->peer_seq = seq_max(device->peer_seq, peer_seq); |
1967 | break; | 1995 | break; |
1968 | } | 1996 | } |
1969 | 1997 | ||
@@ -1973,35 +2001,35 @@ static int wait_for_and_update_peer_seq(struct drbd_conf *mdev, const u32 peer_s | |||
1973 | } | 2001 | } |
1974 | 2002 | ||
1975 | rcu_read_lock(); | 2003 | rcu_read_lock(); |
1976 | tp = rcu_dereference(mdev->tconn->net_conf)->two_primaries; | 2004 | tp = rcu_dereference(first_peer_device(device)->connection->net_conf)->two_primaries; |
1977 | rcu_read_unlock(); | 2005 | rcu_read_unlock(); |
1978 | 2006 | ||
1979 | if (!tp) | 2007 | if (!tp) |
1980 | break; | 2008 | break; |
1981 | 2009 | ||
1982 | /* Only need to wait if two_primaries is enabled */ | 2010 | /* Only need to wait if two_primaries is enabled */ |
1983 | prepare_to_wait(&mdev->seq_wait, &wait, TASK_INTERRUPTIBLE); | 2011 | prepare_to_wait(&device->seq_wait, &wait, TASK_INTERRUPTIBLE); |
1984 | spin_unlock(&mdev->peer_seq_lock); | 2012 | spin_unlock(&device->peer_seq_lock); |
1985 | rcu_read_lock(); | 2013 | rcu_read_lock(); |
1986 | timeout = rcu_dereference(mdev->tconn->net_conf)->ping_timeo*HZ/10; | 2014 | timeout = rcu_dereference(peer_device->connection->net_conf)->ping_timeo*HZ/10; |
1987 | rcu_read_unlock(); | 2015 | rcu_read_unlock(); |
1988 | timeout = schedule_timeout(timeout); | 2016 | timeout = schedule_timeout(timeout); |
1989 | spin_lock(&mdev->peer_seq_lock); | 2017 | spin_lock(&device->peer_seq_lock); |
1990 | if (!timeout) { | 2018 | if (!timeout) { |
1991 | ret = -ETIMEDOUT; | 2019 | ret = -ETIMEDOUT; |
1992 | dev_err(DEV, "Timed out waiting for missing ack packets; disconnecting\n"); | 2020 | drbd_err(device, "Timed out waiting for missing ack packets; disconnecting\n"); |
1993 | break; | 2021 | break; |
1994 | } | 2022 | } |
1995 | } | 2023 | } |
1996 | spin_unlock(&mdev->peer_seq_lock); | 2024 | spin_unlock(&device->peer_seq_lock); |
1997 | finish_wait(&mdev->seq_wait, &wait); | 2025 | finish_wait(&device->seq_wait, &wait); |
1998 | return ret; | 2026 | return ret; |
1999 | } | 2027 | } |
2000 | 2028 | ||
2001 | /* see also bio_flags_to_wire() | 2029 | /* see also bio_flags_to_wire() |
2002 | * DRBD_REQ_*, because we need to semantically map the flags to data packet | 2030 | * DRBD_REQ_*, because we need to semantically map the flags to data packet |
2003 | * flags and back. We may replicate to other kernel versions. */ | 2031 | * flags and back. We may replicate to other kernel versions. */ |
2004 | static unsigned long wire_flags_to_bio(struct drbd_conf *mdev, u32 dpf) | 2032 | static unsigned long wire_flags_to_bio(u32 dpf) |
2005 | { | 2033 | { |
2006 | return (dpf & DP_RW_SYNC ? REQ_SYNC : 0) | | 2034 | return (dpf & DP_RW_SYNC ? REQ_SYNC : 0) | |
2007 | (dpf & DP_FUA ? REQ_FUA : 0) | | 2035 | (dpf & DP_FUA ? REQ_FUA : 0) | |
@@ -2009,13 +2037,13 @@ static unsigned long wire_flags_to_bio(struct drbd_conf *mdev, u32 dpf) | |||
2009 | (dpf & DP_DISCARD ? REQ_DISCARD : 0); | 2037 | (dpf & DP_DISCARD ? REQ_DISCARD : 0); |
2010 | } | 2038 | } |
2011 | 2039 | ||
2012 | static void fail_postponed_requests(struct drbd_conf *mdev, sector_t sector, | 2040 | static void fail_postponed_requests(struct drbd_device *device, sector_t sector, |
2013 | unsigned int size) | 2041 | unsigned int size) |
2014 | { | 2042 | { |
2015 | struct drbd_interval *i; | 2043 | struct drbd_interval *i; |
2016 | 2044 | ||
2017 | repeat: | 2045 | repeat: |
2018 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { | 2046 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
2019 | struct drbd_request *req; | 2047 | struct drbd_request *req; |
2020 | struct bio_and_error m; | 2048 | struct bio_and_error m; |
2021 | 2049 | ||
@@ -2026,19 +2054,19 @@ static void fail_postponed_requests(struct drbd_conf *mdev, sector_t sector, | |||
2026 | continue; | 2054 | continue; |
2027 | req->rq_state &= ~RQ_POSTPONED; | 2055 | req->rq_state &= ~RQ_POSTPONED; |
2028 | __req_mod(req, NEG_ACKED, &m); | 2056 | __req_mod(req, NEG_ACKED, &m); |
2029 | spin_unlock_irq(&mdev->tconn->req_lock); | 2057 | spin_unlock_irq(&device->resource->req_lock); |
2030 | if (m.bio) | 2058 | if (m.bio) |
2031 | complete_master_bio(mdev, &m); | 2059 | complete_master_bio(device, &m); |
2032 | spin_lock_irq(&mdev->tconn->req_lock); | 2060 | spin_lock_irq(&device->resource->req_lock); |
2033 | goto repeat; | 2061 | goto repeat; |
2034 | } | 2062 | } |
2035 | } | 2063 | } |
2036 | 2064 | ||
2037 | static int handle_write_conflicts(struct drbd_conf *mdev, | 2065 | static int handle_write_conflicts(struct drbd_device *device, |
2038 | struct drbd_peer_request *peer_req) | 2066 | struct drbd_peer_request *peer_req) |
2039 | { | 2067 | { |
2040 | struct drbd_tconn *tconn = mdev->tconn; | 2068 | struct drbd_connection *connection = peer_req->peer_device->connection; |
2041 | bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &tconn->flags); | 2069 | bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &connection->flags); |
2042 | sector_t sector = peer_req->i.sector; | 2070 | sector_t sector = peer_req->i.sector; |
2043 | const unsigned int size = peer_req->i.size; | 2071 | const unsigned int size = peer_req->i.size; |
2044 | struct drbd_interval *i; | 2072 | struct drbd_interval *i; |
@@ -2049,10 +2077,10 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2049 | * Inserting the peer request into the write_requests tree will prevent | 2077 | * Inserting the peer request into the write_requests tree will prevent |
2050 | * new conflicting local requests from being added. | 2078 | * new conflicting local requests from being added. |
2051 | */ | 2079 | */ |
2052 | drbd_insert_interval(&mdev->write_requests, &peer_req->i); | 2080 | drbd_insert_interval(&device->write_requests, &peer_req->i); |
2053 | 2081 | ||
2054 | repeat: | 2082 | repeat: |
2055 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { | 2083 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
2056 | if (i == &peer_req->i) | 2084 | if (i == &peer_req->i) |
2057 | continue; | 2085 | continue; |
2058 | 2086 | ||
@@ -2062,7 +2090,7 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2062 | * should not happen in a two-node setup. Wait for the | 2090 | * should not happen in a two-node setup. Wait for the |
2063 | * earlier peer request to complete. | 2091 | * earlier peer request to complete. |
2064 | */ | 2092 | */ |
2065 | err = drbd_wait_misc(mdev, i); | 2093 | err = drbd_wait_misc(device, i); |
2066 | if (err) | 2094 | if (err) |
2067 | goto out; | 2095 | goto out; |
2068 | goto repeat; | 2096 | goto repeat; |
@@ -2080,18 +2108,18 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2080 | (i->size >> 9) >= sector + (size >> 9); | 2108 | (i->size >> 9) >= sector + (size >> 9); |
2081 | 2109 | ||
2082 | if (!equal) | 2110 | if (!equal) |
2083 | dev_alert(DEV, "Concurrent writes detected: " | 2111 | drbd_alert(device, "Concurrent writes detected: " |
2084 | "local=%llus +%u, remote=%llus +%u, " | 2112 | "local=%llus +%u, remote=%llus +%u, " |
2085 | "assuming %s came first\n", | 2113 | "assuming %s came first\n", |
2086 | (unsigned long long)i->sector, i->size, | 2114 | (unsigned long long)i->sector, i->size, |
2087 | (unsigned long long)sector, size, | 2115 | (unsigned long long)sector, size, |
2088 | superseded ? "local" : "remote"); | 2116 | superseded ? "local" : "remote"); |
2089 | 2117 | ||
2090 | inc_unacked(mdev); | 2118 | inc_unacked(device); |
2091 | peer_req->w.cb = superseded ? e_send_superseded : | 2119 | peer_req->w.cb = superseded ? e_send_superseded : |
2092 | e_send_retry_write; | 2120 | e_send_retry_write; |
2093 | list_add_tail(&peer_req->w.list, &mdev->done_ee); | 2121 | list_add_tail(&peer_req->w.list, &device->done_ee); |
2094 | wake_asender(mdev->tconn); | 2122 | wake_asender(connection); |
2095 | 2123 | ||
2096 | err = -ENOENT; | 2124 | err = -ENOENT; |
2097 | goto out; | 2125 | goto out; |
@@ -2100,7 +2128,7 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2100 | container_of(i, struct drbd_request, i); | 2128 | container_of(i, struct drbd_request, i); |
2101 | 2129 | ||
2102 | if (!equal) | 2130 | if (!equal) |
2103 | dev_alert(DEV, "Concurrent writes detected: " | 2131 | drbd_alert(device, "Concurrent writes detected: " |
2104 | "local=%llus +%u, remote=%llus +%u\n", | 2132 | "local=%llus +%u, remote=%llus +%u\n", |
2105 | (unsigned long long)i->sector, i->size, | 2133 | (unsigned long long)i->sector, i->size, |
2106 | (unsigned long long)sector, size); | 2134 | (unsigned long long)sector, size); |
@@ -2118,12 +2146,10 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2118 | * request to finish locally before submitting | 2146 | * request to finish locally before submitting |
2119 | * the conflicting peer request. | 2147 | * the conflicting peer request. |
2120 | */ | 2148 | */ |
2121 | err = drbd_wait_misc(mdev, &req->i); | 2149 | err = drbd_wait_misc(device, &req->i); |
2122 | if (err) { | 2150 | if (err) { |
2123 | _conn_request_state(mdev->tconn, | 2151 | _conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD); |
2124 | NS(conn, C_TIMEOUT), | 2152 | fail_postponed_requests(device, sector, size); |
2125 | CS_HARD); | ||
2126 | fail_postponed_requests(mdev, sector, size); | ||
2127 | goto out; | 2153 | goto out; |
2128 | } | 2154 | } |
2129 | goto repeat; | 2155 | goto repeat; |
@@ -2139,14 +2165,15 @@ static int handle_write_conflicts(struct drbd_conf *mdev, | |||
2139 | 2165 | ||
2140 | out: | 2166 | out: |
2141 | if (err) | 2167 | if (err) |
2142 | drbd_remove_epoch_entry_interval(mdev, peer_req); | 2168 | drbd_remove_epoch_entry_interval(device, peer_req); |
2143 | return err; | 2169 | return err; |
2144 | } | 2170 | } |
2145 | 2171 | ||
2146 | /* mirrored write */ | 2172 | /* mirrored write */ |
2147 | static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) | 2173 | static int receive_Data(struct drbd_connection *connection, struct packet_info *pi) |
2148 | { | 2174 | { |
2149 | struct drbd_conf *mdev; | 2175 | struct drbd_peer_device *peer_device; |
2176 | struct drbd_device *device; | ||
2150 | sector_t sector; | 2177 | sector_t sector; |
2151 | struct drbd_peer_request *peer_req; | 2178 | struct drbd_peer_request *peer_req; |
2152 | struct p_data *p = pi->data; | 2179 | struct p_data *p = pi->data; |
@@ -2155,17 +2182,18 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2155 | u32 dp_flags; | 2182 | u32 dp_flags; |
2156 | int err, tp; | 2183 | int err, tp; |
2157 | 2184 | ||
2158 | mdev = vnr_to_mdev(tconn, pi->vnr); | 2185 | peer_device = conn_peer_device(connection, pi->vnr); |
2159 | if (!mdev) | 2186 | if (!peer_device) |
2160 | return -EIO; | 2187 | return -EIO; |
2188 | device = peer_device->device; | ||
2161 | 2189 | ||
2162 | if (!get_ldev(mdev)) { | 2190 | if (!get_ldev(device)) { |
2163 | int err2; | 2191 | int err2; |
2164 | 2192 | ||
2165 | err = wait_for_and_update_peer_seq(mdev, peer_seq); | 2193 | err = wait_for_and_update_peer_seq(peer_device, peer_seq); |
2166 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size); | 2194 | drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); |
2167 | atomic_inc(&tconn->current_epoch->epoch_size); | 2195 | atomic_inc(&connection->current_epoch->epoch_size); |
2168 | err2 = drbd_drain_block(mdev, pi->size); | 2196 | err2 = drbd_drain_block(peer_device, pi->size); |
2169 | if (!err) | 2197 | if (!err) |
2170 | err = err2; | 2198 | err = err2; |
2171 | return err; | 2199 | return err; |
@@ -2178,61 +2206,61 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2178 | */ | 2206 | */ |
2179 | 2207 | ||
2180 | sector = be64_to_cpu(p->sector); | 2208 | sector = be64_to_cpu(p->sector); |
2181 | peer_req = read_in_block(mdev, p->block_id, sector, pi->size); | 2209 | peer_req = read_in_block(peer_device, p->block_id, sector, pi->size); |
2182 | if (!peer_req) { | 2210 | if (!peer_req) { |
2183 | put_ldev(mdev); | 2211 | put_ldev(device); |
2184 | return -EIO; | 2212 | return -EIO; |
2185 | } | 2213 | } |
2186 | 2214 | ||
2187 | peer_req->w.cb = e_end_block; | 2215 | peer_req->w.cb = e_end_block; |
2188 | 2216 | ||
2189 | dp_flags = be32_to_cpu(p->dp_flags); | 2217 | dp_flags = be32_to_cpu(p->dp_flags); |
2190 | rw |= wire_flags_to_bio(mdev, dp_flags); | 2218 | rw |= wire_flags_to_bio(dp_flags); |
2191 | if (peer_req->pages == NULL) { | 2219 | if (peer_req->pages == NULL) { |
2192 | D_ASSERT(peer_req->i.size == 0); | 2220 | D_ASSERT(device, peer_req->i.size == 0); |
2193 | D_ASSERT(dp_flags & DP_FLUSH); | 2221 | D_ASSERT(device, dp_flags & DP_FLUSH); |
2194 | } | 2222 | } |
2195 | 2223 | ||
2196 | if (dp_flags & DP_MAY_SET_IN_SYNC) | 2224 | if (dp_flags & DP_MAY_SET_IN_SYNC) |
2197 | peer_req->flags |= EE_MAY_SET_IN_SYNC; | 2225 | peer_req->flags |= EE_MAY_SET_IN_SYNC; |
2198 | 2226 | ||
2199 | spin_lock(&tconn->epoch_lock); | 2227 | spin_lock(&connection->epoch_lock); |
2200 | peer_req->epoch = tconn->current_epoch; | 2228 | peer_req->epoch = connection->current_epoch; |
2201 | atomic_inc(&peer_req->epoch->epoch_size); | 2229 | atomic_inc(&peer_req->epoch->epoch_size); |
2202 | atomic_inc(&peer_req->epoch->active); | 2230 | atomic_inc(&peer_req->epoch->active); |
2203 | spin_unlock(&tconn->epoch_lock); | 2231 | spin_unlock(&connection->epoch_lock); |
2204 | 2232 | ||
2205 | rcu_read_lock(); | 2233 | rcu_read_lock(); |
2206 | tp = rcu_dereference(mdev->tconn->net_conf)->two_primaries; | 2234 | tp = rcu_dereference(peer_device->connection->net_conf)->two_primaries; |
2207 | rcu_read_unlock(); | 2235 | rcu_read_unlock(); |
2208 | if (tp) { | 2236 | if (tp) { |
2209 | peer_req->flags |= EE_IN_INTERVAL_TREE; | 2237 | peer_req->flags |= EE_IN_INTERVAL_TREE; |
2210 | err = wait_for_and_update_peer_seq(mdev, peer_seq); | 2238 | err = wait_for_and_update_peer_seq(peer_device, peer_seq); |
2211 | if (err) | 2239 | if (err) |
2212 | goto out_interrupted; | 2240 | goto out_interrupted; |
2213 | spin_lock_irq(&mdev->tconn->req_lock); | 2241 | spin_lock_irq(&device->resource->req_lock); |
2214 | err = handle_write_conflicts(mdev, peer_req); | 2242 | err = handle_write_conflicts(device, peer_req); |
2215 | if (err) { | 2243 | if (err) { |
2216 | spin_unlock_irq(&mdev->tconn->req_lock); | 2244 | spin_unlock_irq(&device->resource->req_lock); |
2217 | if (err == -ENOENT) { | 2245 | if (err == -ENOENT) { |
2218 | put_ldev(mdev); | 2246 | put_ldev(device); |
2219 | return 0; | 2247 | return 0; |
2220 | } | 2248 | } |
2221 | goto out_interrupted; | 2249 | goto out_interrupted; |
2222 | } | 2250 | } |
2223 | } else { | 2251 | } else { |
2224 | update_peer_seq(mdev, peer_seq); | 2252 | update_peer_seq(peer_device, peer_seq); |
2225 | spin_lock_irq(&mdev->tconn->req_lock); | 2253 | spin_lock_irq(&device->resource->req_lock); |
2226 | } | 2254 | } |
2227 | list_add(&peer_req->w.list, &mdev->active_ee); | 2255 | list_add(&peer_req->w.list, &device->active_ee); |
2228 | spin_unlock_irq(&mdev->tconn->req_lock); | 2256 | spin_unlock_irq(&device->resource->req_lock); |
2229 | 2257 | ||
2230 | if (mdev->state.conn == C_SYNC_TARGET) | 2258 | if (device->state.conn == C_SYNC_TARGET) |
2231 | wait_event(mdev->ee_wait, !overlapping_resync_write(mdev, peer_req)); | 2259 | wait_event(device->ee_wait, !overlapping_resync_write(device, peer_req)); |
2232 | 2260 | ||
2233 | if (mdev->tconn->agreed_pro_version < 100) { | 2261 | if (peer_device->connection->agreed_pro_version < 100) { |
2234 | rcu_read_lock(); | 2262 | rcu_read_lock(); |
2235 | switch (rcu_dereference(mdev->tconn->net_conf)->wire_protocol) { | 2263 | switch (rcu_dereference(peer_device->connection->net_conf)->wire_protocol) { |
2236 | case DRBD_PROT_C: | 2264 | case DRBD_PROT_C: |
2237 | dp_flags |= DP_SEND_WRITE_ACK; | 2265 | dp_flags |= DP_SEND_WRITE_ACK; |
2238 | break; | 2266 | break; |
@@ -2245,7 +2273,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2245 | 2273 | ||
2246 | if (dp_flags & DP_SEND_WRITE_ACK) { | 2274 | if (dp_flags & DP_SEND_WRITE_ACK) { |
2247 | peer_req->flags |= EE_SEND_WRITE_ACK; | 2275 | peer_req->flags |= EE_SEND_WRITE_ACK; |
2248 | inc_unacked(mdev); | 2276 | inc_unacked(device); |
2249 | /* corresponding dec_unacked() in e_end_block() | 2277 | /* corresponding dec_unacked() in e_end_block() |
2250 | * respective _drbd_clear_done_ee */ | 2278 | * respective _drbd_clear_done_ee */ |
2251 | } | 2279 | } |
@@ -2253,34 +2281,34 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2253 | if (dp_flags & DP_SEND_RECEIVE_ACK) { | 2281 | if (dp_flags & DP_SEND_RECEIVE_ACK) { |
2254 | /* I really don't like it that the receiver thread | 2282 | /* I really don't like it that the receiver thread |
2255 | * sends on the msock, but anyways */ | 2283 | * sends on the msock, but anyways */ |
2256 | drbd_send_ack(mdev, P_RECV_ACK, peer_req); | 2284 | drbd_send_ack(first_peer_device(device), P_RECV_ACK, peer_req); |
2257 | } | 2285 | } |
2258 | 2286 | ||
2259 | if (mdev->state.pdsk < D_INCONSISTENT) { | 2287 | if (device->state.pdsk < D_INCONSISTENT) { |
2260 | /* In case we have the only disk of the cluster, */ | 2288 | /* In case we have the only disk of the cluster, */ |
2261 | drbd_set_out_of_sync(mdev, peer_req->i.sector, peer_req->i.size); | 2289 | drbd_set_out_of_sync(device, peer_req->i.sector, peer_req->i.size); |
2262 | peer_req->flags |= EE_CALL_AL_COMPLETE_IO; | 2290 | peer_req->flags |= EE_CALL_AL_COMPLETE_IO; |
2263 | peer_req->flags &= ~EE_MAY_SET_IN_SYNC; | 2291 | peer_req->flags &= ~EE_MAY_SET_IN_SYNC; |
2264 | drbd_al_begin_io(mdev, &peer_req->i, true); | 2292 | drbd_al_begin_io(device, &peer_req->i, true); |
2265 | } | 2293 | } |
2266 | 2294 | ||
2267 | err = drbd_submit_peer_request(mdev, peer_req, rw, DRBD_FAULT_DT_WR); | 2295 | err = drbd_submit_peer_request(device, peer_req, rw, DRBD_FAULT_DT_WR); |
2268 | if (!err) | 2296 | if (!err) |
2269 | return 0; | 2297 | return 0; |
2270 | 2298 | ||
2271 | /* don't care for the reason here */ | 2299 | /* don't care for the reason here */ |
2272 | dev_err(DEV, "submit failed, triggering re-connect\n"); | 2300 | drbd_err(device, "submit failed, triggering re-connect\n"); |
2273 | spin_lock_irq(&mdev->tconn->req_lock); | 2301 | spin_lock_irq(&device->resource->req_lock); |
2274 | list_del(&peer_req->w.list); | 2302 | list_del(&peer_req->w.list); |
2275 | drbd_remove_epoch_entry_interval(mdev, peer_req); | 2303 | drbd_remove_epoch_entry_interval(device, peer_req); |
2276 | spin_unlock_irq(&mdev->tconn->req_lock); | 2304 | spin_unlock_irq(&device->resource->req_lock); |
2277 | if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) | 2305 | if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) |
2278 | drbd_al_complete_io(mdev, &peer_req->i); | 2306 | drbd_al_complete_io(device, &peer_req->i); |
2279 | 2307 | ||
2280 | out_interrupted: | 2308 | out_interrupted: |
2281 | drbd_may_finish_epoch(tconn, peer_req->epoch, EV_PUT + EV_CLEANUP); | 2309 | drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT + EV_CLEANUP); |
2282 | put_ldev(mdev); | 2310 | put_ldev(device); |
2283 | drbd_free_peer_req(mdev, peer_req); | 2311 | drbd_free_peer_req(device, peer_req); |
2284 | return err; | 2312 | return err; |
2285 | } | 2313 | } |
2286 | 2314 | ||
@@ -2295,9 +2323,9 @@ out_interrupted: | |||
2295 | * The current sync rate used here uses only the most recent two step marks, | 2323 | * The current sync rate used here uses only the most recent two step marks, |
2296 | * to have a short time average so we can react faster. | 2324 | * to have a short time average so we can react faster. |
2297 | */ | 2325 | */ |
2298 | int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector) | 2326 | int drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector) |
2299 | { | 2327 | { |
2300 | struct gendisk *disk = mdev->ldev->backing_bdev->bd_contains->bd_disk; | 2328 | struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk; |
2301 | unsigned long db, dt, dbdt; | 2329 | unsigned long db, dt, dbdt; |
2302 | struct lc_element *tmp; | 2330 | struct lc_element *tmp; |
2303 | int curr_events; | 2331 | int curr_events; |
@@ -2305,48 +2333,48 @@ int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector) | |||
2305 | unsigned int c_min_rate; | 2333 | unsigned int c_min_rate; |
2306 | 2334 | ||
2307 | rcu_read_lock(); | 2335 | rcu_read_lock(); |
2308 | c_min_rate = rcu_dereference(mdev->ldev->disk_conf)->c_min_rate; | 2336 | c_min_rate = rcu_dereference(device->ldev->disk_conf)->c_min_rate; |
2309 | rcu_read_unlock(); | 2337 | rcu_read_unlock(); |
2310 | 2338 | ||
2311 | /* feature disabled? */ | 2339 | /* feature disabled? */ |
2312 | if (c_min_rate == 0) | 2340 | if (c_min_rate == 0) |
2313 | return 0; | 2341 | return 0; |
2314 | 2342 | ||
2315 | spin_lock_irq(&mdev->al_lock); | 2343 | spin_lock_irq(&device->al_lock); |
2316 | tmp = lc_find(mdev->resync, BM_SECT_TO_EXT(sector)); | 2344 | tmp = lc_find(device->resync, BM_SECT_TO_EXT(sector)); |
2317 | if (tmp) { | 2345 | if (tmp) { |
2318 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); | 2346 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
2319 | if (test_bit(BME_PRIORITY, &bm_ext->flags)) { | 2347 | if (test_bit(BME_PRIORITY, &bm_ext->flags)) { |
2320 | spin_unlock_irq(&mdev->al_lock); | 2348 | spin_unlock_irq(&device->al_lock); |
2321 | return 0; | 2349 | return 0; |
2322 | } | 2350 | } |
2323 | /* Do not slow down if app IO is already waiting for this extent */ | 2351 | /* Do not slow down if app IO is already waiting for this extent */ |
2324 | } | 2352 | } |
2325 | spin_unlock_irq(&mdev->al_lock); | 2353 | spin_unlock_irq(&device->al_lock); |
2326 | 2354 | ||
2327 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + | 2355 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
2328 | (int)part_stat_read(&disk->part0, sectors[1]) - | 2356 | (int)part_stat_read(&disk->part0, sectors[1]) - |
2329 | atomic_read(&mdev->rs_sect_ev); | 2357 | atomic_read(&device->rs_sect_ev); |
2330 | 2358 | ||
2331 | if (!mdev->rs_last_events || curr_events - mdev->rs_last_events > 64) { | 2359 | if (!device->rs_last_events || curr_events - device->rs_last_events > 64) { |
2332 | unsigned long rs_left; | 2360 | unsigned long rs_left; |
2333 | int i; | 2361 | int i; |
2334 | 2362 | ||
2335 | mdev->rs_last_events = curr_events; | 2363 | device->rs_last_events = curr_events; |
2336 | 2364 | ||
2337 | /* sync speed average over the last 2*DRBD_SYNC_MARK_STEP, | 2365 | /* sync speed average over the last 2*DRBD_SYNC_MARK_STEP, |
2338 | * approx. */ | 2366 | * approx. */ |
2339 | i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; | 2367 | i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
2340 | 2368 | ||
2341 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) | 2369 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
2342 | rs_left = mdev->ov_left; | 2370 | rs_left = device->ov_left; |
2343 | else | 2371 | else |
2344 | rs_left = drbd_bm_total_weight(mdev) - mdev->rs_failed; | 2372 | rs_left = drbd_bm_total_weight(device) - device->rs_failed; |
2345 | 2373 | ||
2346 | dt = ((long)jiffies - (long)mdev->rs_mark_time[i]) / HZ; | 2374 | dt = ((long)jiffies - (long)device->rs_mark_time[i]) / HZ; |
2347 | if (!dt) | 2375 | if (!dt) |
2348 | dt++; | 2376 | dt++; |
2349 | db = mdev->rs_mark_left[i] - rs_left; | 2377 | db = device->rs_mark_left[i] - rs_left; |
2350 | dbdt = Bit2KB(db/dt); | 2378 | dbdt = Bit2KB(db/dt); |
2351 | 2379 | ||
2352 | if (dbdt > c_min_rate) | 2380 | if (dbdt > c_min_rate) |
@@ -2356,9 +2384,10 @@ int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector) | |||
2356 | } | 2384 | } |
2357 | 2385 | ||
2358 | 2386 | ||
2359 | static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | 2387 | static int receive_DataRequest(struct drbd_connection *connection, struct packet_info *pi) |
2360 | { | 2388 | { |
2361 | struct drbd_conf *mdev; | 2389 | struct drbd_peer_device *peer_device; |
2390 | struct drbd_device *device; | ||
2362 | sector_t sector; | 2391 | sector_t sector; |
2363 | sector_t capacity; | 2392 | sector_t capacity; |
2364 | struct drbd_peer_request *peer_req; | 2393 | struct drbd_peer_request *peer_req; |
@@ -2367,58 +2396,59 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2367 | unsigned int fault_type; | 2396 | unsigned int fault_type; |
2368 | struct p_block_req *p = pi->data; | 2397 | struct p_block_req *p = pi->data; |
2369 | 2398 | ||
2370 | mdev = vnr_to_mdev(tconn, pi->vnr); | 2399 | peer_device = conn_peer_device(connection, pi->vnr); |
2371 | if (!mdev) | 2400 | if (!peer_device) |
2372 | return -EIO; | 2401 | return -EIO; |
2373 | capacity = drbd_get_capacity(mdev->this_bdev); | 2402 | device = peer_device->device; |
2403 | capacity = drbd_get_capacity(device->this_bdev); | ||
2374 | 2404 | ||
2375 | sector = be64_to_cpu(p->sector); | 2405 | sector = be64_to_cpu(p->sector); |
2376 | size = be32_to_cpu(p->blksize); | 2406 | size = be32_to_cpu(p->blksize); |
2377 | 2407 | ||
2378 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { | 2408 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
2379 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, | 2409 | drbd_err(device, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
2380 | (unsigned long long)sector, size); | 2410 | (unsigned long long)sector, size); |
2381 | return -EINVAL; | 2411 | return -EINVAL; |
2382 | } | 2412 | } |
2383 | if (sector + (size>>9) > capacity) { | 2413 | if (sector + (size>>9) > capacity) { |
2384 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, | 2414 | drbd_err(device, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
2385 | (unsigned long long)sector, size); | 2415 | (unsigned long long)sector, size); |
2386 | return -EINVAL; | 2416 | return -EINVAL; |
2387 | } | 2417 | } |
2388 | 2418 | ||
2389 | if (!get_ldev_if_state(mdev, D_UP_TO_DATE)) { | 2419 | if (!get_ldev_if_state(device, D_UP_TO_DATE)) { |
2390 | verb = 1; | 2420 | verb = 1; |
2391 | switch (pi->cmd) { | 2421 | switch (pi->cmd) { |
2392 | case P_DATA_REQUEST: | 2422 | case P_DATA_REQUEST: |
2393 | drbd_send_ack_rp(mdev, P_NEG_DREPLY, p); | 2423 | drbd_send_ack_rp(peer_device, P_NEG_DREPLY, p); |
2394 | break; | 2424 | break; |
2395 | case P_RS_DATA_REQUEST: | 2425 | case P_RS_DATA_REQUEST: |
2396 | case P_CSUM_RS_REQUEST: | 2426 | case P_CSUM_RS_REQUEST: |
2397 | case P_OV_REQUEST: | 2427 | case P_OV_REQUEST: |
2398 | drbd_send_ack_rp(mdev, P_NEG_RS_DREPLY , p); | 2428 | drbd_send_ack_rp(peer_device, P_NEG_RS_DREPLY , p); |
2399 | break; | 2429 | break; |
2400 | case P_OV_REPLY: | 2430 | case P_OV_REPLY: |
2401 | verb = 0; | 2431 | verb = 0; |
2402 | dec_rs_pending(mdev); | 2432 | dec_rs_pending(device); |
2403 | drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, ID_IN_SYNC); | 2433 | drbd_send_ack_ex(peer_device, P_OV_RESULT, sector, size, ID_IN_SYNC); |
2404 | break; | 2434 | break; |
2405 | default: | 2435 | default: |
2406 | BUG(); | 2436 | BUG(); |
2407 | } | 2437 | } |
2408 | if (verb && __ratelimit(&drbd_ratelimit_state)) | 2438 | if (verb && __ratelimit(&drbd_ratelimit_state)) |
2409 | dev_err(DEV, "Can not satisfy peer's read request, " | 2439 | drbd_err(device, "Can not satisfy peer's read request, " |
2410 | "no local data.\n"); | 2440 | "no local data.\n"); |
2411 | 2441 | ||
2412 | /* drain possibly payload */ | 2442 | /* drain possibly payload */ |
2413 | return drbd_drain_block(mdev, pi->size); | 2443 | return drbd_drain_block(peer_device, pi->size); |
2414 | } | 2444 | } |
2415 | 2445 | ||
2416 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD | 2446 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
2417 | * "criss-cross" setup, that might cause write-out on some other DRBD, | 2447 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
2418 | * which in turn might block on the other node at this very place. */ | 2448 | * which in turn might block on the other node at this very place. */ |
2419 | peer_req = drbd_alloc_peer_req(mdev, p->block_id, sector, size, GFP_NOIO); | 2449 | peer_req = drbd_alloc_peer_req(peer_device, p->block_id, sector, size, GFP_NOIO); |
2420 | if (!peer_req) { | 2450 | if (!peer_req) { |
2421 | put_ldev(mdev); | 2451 | put_ldev(device); |
2422 | return -ENOMEM; | 2452 | return -ENOMEM; |
2423 | } | 2453 | } |
2424 | 2454 | ||
@@ -2433,7 +2463,7 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2433 | peer_req->w.cb = w_e_end_rsdata_req; | 2463 | peer_req->w.cb = w_e_end_rsdata_req; |
2434 | fault_type = DRBD_FAULT_RS_RD; | 2464 | fault_type = DRBD_FAULT_RS_RD; |
2435 | /* used in the sector offset progress display */ | 2465 | /* used in the sector offset progress display */ |
2436 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); | 2466 | device->bm_resync_fo = BM_SECT_TO_BIT(sector); |
2437 | break; | 2467 | break; |
2438 | 2468 | ||
2439 | case P_OV_REPLY: | 2469 | case P_OV_REPLY: |
@@ -2449,19 +2479,19 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2449 | peer_req->digest = di; | 2479 | peer_req->digest = di; |
2450 | peer_req->flags |= EE_HAS_DIGEST; | 2480 | peer_req->flags |= EE_HAS_DIGEST; |
2451 | 2481 | ||
2452 | if (drbd_recv_all(mdev->tconn, di->digest, pi->size)) | 2482 | if (drbd_recv_all(peer_device->connection, di->digest, pi->size)) |
2453 | goto out_free_e; | 2483 | goto out_free_e; |
2454 | 2484 | ||
2455 | if (pi->cmd == P_CSUM_RS_REQUEST) { | 2485 | if (pi->cmd == P_CSUM_RS_REQUEST) { |
2456 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); | 2486 | D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); |
2457 | peer_req->w.cb = w_e_end_csum_rs_req; | 2487 | peer_req->w.cb = w_e_end_csum_rs_req; |
2458 | /* used in the sector offset progress display */ | 2488 | /* used in the sector offset progress display */ |
2459 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); | 2489 | device->bm_resync_fo = BM_SECT_TO_BIT(sector); |
2460 | } else if (pi->cmd == P_OV_REPLY) { | 2490 | } else if (pi->cmd == P_OV_REPLY) { |
2461 | /* track progress, we may need to throttle */ | 2491 | /* track progress, we may need to throttle */ |
2462 | atomic_add(size >> 9, &mdev->rs_sect_in); | 2492 | atomic_add(size >> 9, &device->rs_sect_in); |
2463 | peer_req->w.cb = w_e_end_ov_reply; | 2493 | peer_req->w.cb = w_e_end_ov_reply; |
2464 | dec_rs_pending(mdev); | 2494 | dec_rs_pending(device); |
2465 | /* drbd_rs_begin_io done when we sent this request, | 2495 | /* drbd_rs_begin_io done when we sent this request, |
2466 | * but accounting still needs to be done. */ | 2496 | * but accounting still needs to be done. */ |
2467 | goto submit_for_resync; | 2497 | goto submit_for_resync; |
@@ -2469,19 +2499,19 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2469 | break; | 2499 | break; |
2470 | 2500 | ||
2471 | case P_OV_REQUEST: | 2501 | case P_OV_REQUEST: |
2472 | if (mdev->ov_start_sector == ~(sector_t)0 && | 2502 | if (device->ov_start_sector == ~(sector_t)0 && |
2473 | mdev->tconn->agreed_pro_version >= 90) { | 2503 | peer_device->connection->agreed_pro_version >= 90) { |
2474 | unsigned long now = jiffies; | 2504 | unsigned long now = jiffies; |
2475 | int i; | 2505 | int i; |
2476 | mdev->ov_start_sector = sector; | 2506 | device->ov_start_sector = sector; |
2477 | mdev->ov_position = sector; | 2507 | device->ov_position = sector; |
2478 | mdev->ov_left = drbd_bm_bits(mdev) - BM_SECT_TO_BIT(sector); | 2508 | device->ov_left = drbd_bm_bits(device) - BM_SECT_TO_BIT(sector); |
2479 | mdev->rs_total = mdev->ov_left; | 2509 | device->rs_total = device->ov_left; |
2480 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { | 2510 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
2481 | mdev->rs_mark_left[i] = mdev->ov_left; | 2511 | device->rs_mark_left[i] = device->ov_left; |
2482 | mdev->rs_mark_time[i] = now; | 2512 | device->rs_mark_time[i] = now; |
2483 | } | 2513 | } |
2484 | dev_info(DEV, "Online Verify start sector: %llu\n", | 2514 | drbd_info(device, "Online Verify start sector: %llu\n", |
2485 | (unsigned long long)sector); | 2515 | (unsigned long long)sector); |
2486 | } | 2516 | } |
2487 | peer_req->w.cb = w_e_end_ov_req; | 2517 | peer_req->w.cb = w_e_end_ov_req; |
@@ -2514,57 +2544,61 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) | |||
2514 | * we would also throttle its application reads. | 2544 | * we would also throttle its application reads. |
2515 | * In that case, throttling is done on the SyncTarget only. | 2545 | * In that case, throttling is done on the SyncTarget only. |
2516 | */ | 2546 | */ |
2517 | if (mdev->state.peer != R_PRIMARY && drbd_rs_should_slow_down(mdev, sector)) | 2547 | if (device->state.peer != R_PRIMARY && drbd_rs_should_slow_down(device, sector)) |
2518 | schedule_timeout_uninterruptible(HZ/10); | 2548 | schedule_timeout_uninterruptible(HZ/10); |
2519 | if (drbd_rs_begin_io(mdev, sector)) | 2549 | if (drbd_rs_begin_io(device, sector)) |
2520 | goto out_free_e; | 2550 | goto out_free_e; |
2521 | 2551 | ||
2522 | submit_for_resync: | 2552 | submit_for_resync: |
2523 | atomic_add(size >> 9, &mdev->rs_sect_ev); | 2553 | atomic_add(size >> 9, &device->rs_sect_ev); |
2524 | 2554 | ||
2525 | submit: | 2555 | submit: |
2526 | inc_unacked(mdev); | 2556 | inc_unacked(device); |
2527 | spin_lock_irq(&mdev->tconn->req_lock); | 2557 | spin_lock_irq(&device->resource->req_lock); |
2528 | list_add_tail(&peer_req->w.list, &mdev->read_ee); | 2558 | list_add_tail(&peer_req->w.list, &device->read_ee); |
2529 | spin_unlock_irq(&mdev->tconn->req_lock); | 2559 | spin_unlock_irq(&device->resource->req_lock); |
2530 | 2560 | ||
2531 | if (drbd_submit_peer_request(mdev, peer_req, READ, fault_type) == 0) | 2561 | if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0) |
2532 | return 0; | 2562 | return 0; |
2533 | 2563 | ||
2534 | /* don't care for the reason here */ | 2564 | /* don't care for the reason here */ |
2535 | dev_err(DEV, "submit failed, triggering re-connect\n"); | 2565 | drbd_err(device, "submit failed, triggering re-connect\n"); |
2536 | spin_lock_irq(&mdev->tconn->req_lock); | 2566 | spin_lock_irq(&device->resource->req_lock); |
2537 | list_del(&peer_req->w.list); | 2567 | list_del(&peer_req->w.list); |
2538 | spin_unlock_irq(&mdev->tconn->req_lock); | 2568 | spin_unlock_irq(&device->resource->req_lock); |
2539 | /* no drbd_rs_complete_io(), we are dropping the connection anyways */ | 2569 | /* no drbd_rs_complete_io(), we are dropping the connection anyways */ |
2540 | 2570 | ||
2541 | out_free_e: | 2571 | out_free_e: |
2542 | put_ldev(mdev); | 2572 | put_ldev(device); |
2543 | drbd_free_peer_req(mdev, peer_req); | 2573 | drbd_free_peer_req(device, peer_req); |
2544 | return -EIO; | 2574 | return -EIO; |
2545 | } | 2575 | } |
2546 | 2576 | ||
2547 | static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) | 2577 | /** |
2578 | * drbd_asb_recover_0p - Recover after split-brain with no remaining primaries | ||
2579 | */ | ||
2580 | static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold(local) | ||
2548 | { | 2581 | { |
2582 | struct drbd_device *device = peer_device->device; | ||
2549 | int self, peer, rv = -100; | 2583 | int self, peer, rv = -100; |
2550 | unsigned long ch_self, ch_peer; | 2584 | unsigned long ch_self, ch_peer; |
2551 | enum drbd_after_sb_p after_sb_0p; | 2585 | enum drbd_after_sb_p after_sb_0p; |
2552 | 2586 | ||
2553 | self = mdev->ldev->md.uuid[UI_BITMAP] & 1; | 2587 | self = device->ldev->md.uuid[UI_BITMAP] & 1; |
2554 | peer = mdev->p_uuid[UI_BITMAP] & 1; | 2588 | peer = device->p_uuid[UI_BITMAP] & 1; |
2555 | 2589 | ||
2556 | ch_peer = mdev->p_uuid[UI_SIZE]; | 2590 | ch_peer = device->p_uuid[UI_SIZE]; |
2557 | ch_self = mdev->comm_bm_set; | 2591 | ch_self = device->comm_bm_set; |
2558 | 2592 | ||
2559 | rcu_read_lock(); | 2593 | rcu_read_lock(); |
2560 | after_sb_0p = rcu_dereference(mdev->tconn->net_conf)->after_sb_0p; | 2594 | after_sb_0p = rcu_dereference(peer_device->connection->net_conf)->after_sb_0p; |
2561 | rcu_read_unlock(); | 2595 | rcu_read_unlock(); |
2562 | switch (after_sb_0p) { | 2596 | switch (after_sb_0p) { |
2563 | case ASB_CONSENSUS: | 2597 | case ASB_CONSENSUS: |
2564 | case ASB_DISCARD_SECONDARY: | 2598 | case ASB_DISCARD_SECONDARY: |
2565 | case ASB_CALL_HELPER: | 2599 | case ASB_CALL_HELPER: |
2566 | case ASB_VIOLENTLY: | 2600 | case ASB_VIOLENTLY: |
2567 | dev_err(DEV, "Configuration error.\n"); | 2601 | drbd_err(device, "Configuration error.\n"); |
2568 | break; | 2602 | break; |
2569 | case ASB_DISCONNECT: | 2603 | case ASB_DISCONNECT: |
2570 | break; | 2604 | break; |
@@ -2588,11 +2622,11 @@ static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) | |||
2588 | break; | 2622 | break; |
2589 | } | 2623 | } |
2590 | /* Else fall through to one of the other strategies... */ | 2624 | /* Else fall through to one of the other strategies... */ |
2591 | dev_warn(DEV, "Discard younger/older primary did not find a decision\n" | 2625 | drbd_warn(device, "Discard younger/older primary did not find a decision\n" |
2592 | "Using discard-least-changes instead\n"); | 2626 | "Using discard-least-changes instead\n"); |
2593 | case ASB_DISCARD_ZERO_CHG: | 2627 | case ASB_DISCARD_ZERO_CHG: |
2594 | if (ch_peer == 0 && ch_self == 0) { | 2628 | if (ch_peer == 0 && ch_self == 0) { |
2595 | rv = test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags) | 2629 | rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) |
2596 | ? -1 : 1; | 2630 | ? -1 : 1; |
2597 | break; | 2631 | break; |
2598 | } else { | 2632 | } else { |
@@ -2608,7 +2642,7 @@ static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) | |||
2608 | rv = 1; | 2642 | rv = 1; |
2609 | else /* ( ch_self == ch_peer ) */ | 2643 | else /* ( ch_self == ch_peer ) */ |
2610 | /* Well, then use something else. */ | 2644 | /* Well, then use something else. */ |
2611 | rv = test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags) | 2645 | rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) |
2612 | ? -1 : 1; | 2646 | ? -1 : 1; |
2613 | break; | 2647 | break; |
2614 | case ASB_DISCARD_LOCAL: | 2648 | case ASB_DISCARD_LOCAL: |
@@ -2621,13 +2655,17 @@ static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) | |||
2621 | return rv; | 2655 | return rv; |
2622 | } | 2656 | } |
2623 | 2657 | ||
2624 | static int drbd_asb_recover_1p(struct drbd_conf *mdev) __must_hold(local) | 2658 | /** |
2659 | * drbd_asb_recover_1p - Recover after split-brain with one remaining primary | ||
2660 | */ | ||
2661 | static int drbd_asb_recover_1p(struct drbd_peer_device *peer_device) __must_hold(local) | ||
2625 | { | 2662 | { |
2663 | struct drbd_device *device = peer_device->device; | ||
2626 | int hg, rv = -100; | 2664 | int hg, rv = -100; |
2627 | enum drbd_after_sb_p after_sb_1p; | 2665 | enum drbd_after_sb_p after_sb_1p; |
2628 | 2666 | ||
2629 | rcu_read_lock(); | 2667 | rcu_read_lock(); |
2630 | after_sb_1p = rcu_dereference(mdev->tconn->net_conf)->after_sb_1p; | 2668 | after_sb_1p = rcu_dereference(peer_device->connection->net_conf)->after_sb_1p; |
2631 | rcu_read_unlock(); | 2669 | rcu_read_unlock(); |
2632 | switch (after_sb_1p) { | 2670 | switch (after_sb_1p) { |
2633 | case ASB_DISCARD_YOUNGER_PRI: | 2671 | case ASB_DISCARD_YOUNGER_PRI: |
@@ -2636,35 +2674,35 @@ static int drbd_asb_recover_1p(struct drbd_conf *mdev) __must_hold(local) | |||
2636 | case ASB_DISCARD_LOCAL: | 2674 | case ASB_DISCARD_LOCAL: |
2637 | case ASB_DISCARD_REMOTE: | 2675 | case ASB_DISCARD_REMOTE: |
2638 | case ASB_DISCARD_ZERO_CHG: | 2676 | case ASB_DISCARD_ZERO_CHG: |
2639 | dev_err(DEV, "Configuration error.\n"); | 2677 | drbd_err(device, "Configuration error.\n"); |
2640 | break; | 2678 | break; |
2641 | case ASB_DISCONNECT: | 2679 | case ASB_DISCONNECT: |
2642 | break; | 2680 | break; |
2643 | case ASB_CONSENSUS: | 2681 | case ASB_CONSENSUS: |
2644 | hg = drbd_asb_recover_0p(mdev); | 2682 | hg = drbd_asb_recover_0p(peer_device); |
2645 | if (hg == -1 && mdev->state.role == R_SECONDARY) | 2683 | if (hg == -1 && device->state.role == R_SECONDARY) |
2646 | rv = hg; | 2684 | rv = hg; |
2647 | if (hg == 1 && mdev->state.role == R_PRIMARY) | 2685 | if (hg == 1 && device->state.role == R_PRIMARY) |
2648 | rv = hg; | 2686 | rv = hg; |
2649 | break; | 2687 | break; |
2650 | case ASB_VIOLENTLY: | 2688 | case ASB_VIOLENTLY: |
2651 | rv = drbd_asb_recover_0p(mdev); | 2689 | rv = drbd_asb_recover_0p(peer_device); |
2652 | break; | 2690 | break; |
2653 | case ASB_DISCARD_SECONDARY: | 2691 | case ASB_DISCARD_SECONDARY: |
2654 | return mdev->state.role == R_PRIMARY ? 1 : -1; | 2692 | return device->state.role == R_PRIMARY ? 1 : -1; |
2655 | case ASB_CALL_HELPER: | 2693 | case ASB_CALL_HELPER: |
2656 | hg = drbd_asb_recover_0p(mdev); | 2694 | hg = drbd_asb_recover_0p(peer_device); |
2657 | if (hg == -1 && mdev->state.role == R_PRIMARY) { | 2695 | if (hg == -1 && device->state.role == R_PRIMARY) { |
2658 | enum drbd_state_rv rv2; | 2696 | enum drbd_state_rv rv2; |
2659 | 2697 | ||
2660 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, | 2698 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
2661 | * we might be here in C_WF_REPORT_PARAMS which is transient. | 2699 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
2662 | * we do not need to wait for the after state change work either. */ | 2700 | * we do not need to wait for the after state change work either. */ |
2663 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); | 2701 | rv2 = drbd_change_state(device, CS_VERBOSE, NS(role, R_SECONDARY)); |
2664 | if (rv2 != SS_SUCCESS) { | 2702 | if (rv2 != SS_SUCCESS) { |
2665 | drbd_khelper(mdev, "pri-lost-after-sb"); | 2703 | drbd_khelper(device, "pri-lost-after-sb"); |
2666 | } else { | 2704 | } else { |
2667 | dev_warn(DEV, "Successfully gave up primary role.\n"); | 2705 | drbd_warn(device, "Successfully gave up primary role.\n"); |
2668 | rv = hg; | 2706 | rv = hg; |
2669 | } | 2707 | } |
2670 | } else | 2708 | } else |
@@ -2674,13 +2712,17 @@ static int drbd_asb_recover_1p(struct drbd_conf *mdev) __must_hold(local) | |||
2674 | return rv; | 2712 | return rv; |
2675 | } | 2713 | } |
2676 | 2714 | ||
2677 | static int drbd_asb_recover_2p(struct drbd_conf *mdev) __must_hold(local) | 2715 | /** |
2716 | * drbd_asb_recover_2p - Recover after split-brain with two remaining primaries | ||
2717 | */ | ||
2718 | static int drbd_asb_recover_2p(struct drbd_peer_device *peer_device) __must_hold(local) | ||
2678 | { | 2719 | { |
2720 | struct drbd_device *device = peer_device->device; | ||
2679 | int hg, rv = -100; | 2721 | int hg, rv = -100; |
2680 | enum drbd_after_sb_p after_sb_2p; | 2722 | enum drbd_after_sb_p after_sb_2p; |
2681 | 2723 | ||
2682 | rcu_read_lock(); | 2724 | rcu_read_lock(); |
2683 | after_sb_2p = rcu_dereference(mdev->tconn->net_conf)->after_sb_2p; | 2725 | after_sb_2p = rcu_dereference(peer_device->connection->net_conf)->after_sb_2p; |
2684 | rcu_read_unlock(); | 2726 | rcu_read_unlock(); |
2685 | switch (after_sb_2p) { | 2727 | switch (after_sb_2p) { |
2686 | case ASB_DISCARD_YOUNGER_PRI: | 2728 | case ASB_DISCARD_YOUNGER_PRI: |
@@ -2691,26 +2733,26 @@ static int drbd_asb_recover_2p(struct drbd_conf *mdev) __must_hold(local) | |||
2691 | case ASB_CONSENSUS: | 2733 | case ASB_CONSENSUS: |
2692 | case ASB_DISCARD_SECONDARY: | 2734 | case ASB_DISCARD_SECONDARY: |
2693 | case ASB_DISCARD_ZERO_CHG: | 2735 | case ASB_DISCARD_ZERO_CHG: |
2694 | dev_err(DEV, "Configuration error.\n"); | 2736 | drbd_err(device, "Configuration error.\n"); |
2695 | break; | 2737 | break; |
2696 | case ASB_VIOLENTLY: | 2738 | case ASB_VIOLENTLY: |
2697 | rv = drbd_asb_recover_0p(mdev); | 2739 | rv = drbd_asb_recover_0p(peer_device); |
2698 | break; | 2740 | break; |
2699 | case ASB_DISCONNECT: | 2741 | case ASB_DISCONNECT: |
2700 | break; | 2742 | break; |
2701 | case ASB_CALL_HELPER: | 2743 | case ASB_CALL_HELPER: |
2702 | hg = drbd_asb_recover_0p(mdev); | 2744 | hg = drbd_asb_recover_0p(peer_device); |
2703 | if (hg == -1) { | 2745 | if (hg == -1) { |
2704 | enum drbd_state_rv rv2; | 2746 | enum drbd_state_rv rv2; |
2705 | 2747 | ||
2706 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, | 2748 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
2707 | * we might be here in C_WF_REPORT_PARAMS which is transient. | 2749 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
2708 | * we do not need to wait for the after state change work either. */ | 2750 | * we do not need to wait for the after state change work either. */ |
2709 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); | 2751 | rv2 = drbd_change_state(device, CS_VERBOSE, NS(role, R_SECONDARY)); |
2710 | if (rv2 != SS_SUCCESS) { | 2752 | if (rv2 != SS_SUCCESS) { |
2711 | drbd_khelper(mdev, "pri-lost-after-sb"); | 2753 | drbd_khelper(device, "pri-lost-after-sb"); |
2712 | } else { | 2754 | } else { |
2713 | dev_warn(DEV, "Successfully gave up primary role.\n"); | 2755 | drbd_warn(device, "Successfully gave up primary role.\n"); |
2714 | rv = hg; | 2756 | rv = hg; |
2715 | } | 2757 | } |
2716 | } else | 2758 | } else |
@@ -2720,14 +2762,14 @@ static int drbd_asb_recover_2p(struct drbd_conf *mdev) __must_hold(local) | |||
2720 | return rv; | 2762 | return rv; |
2721 | } | 2763 | } |
2722 | 2764 | ||
2723 | static void drbd_uuid_dump(struct drbd_conf *mdev, char *text, u64 *uuid, | 2765 | static void drbd_uuid_dump(struct drbd_device *device, char *text, u64 *uuid, |
2724 | u64 bits, u64 flags) | 2766 | u64 bits, u64 flags) |
2725 | { | 2767 | { |
2726 | if (!uuid) { | 2768 | if (!uuid) { |
2727 | dev_info(DEV, "%s uuid info vanished while I was looking!\n", text); | 2769 | drbd_info(device, "%s uuid info vanished while I was looking!\n", text); |
2728 | return; | 2770 | return; |
2729 | } | 2771 | } |
2730 | dev_info(DEV, "%s %016llX:%016llX:%016llX:%016llX bits:%llu flags:%llX\n", | 2772 | drbd_info(device, "%s %016llX:%016llX:%016llX:%016llX bits:%llu flags:%llX\n", |
2731 | text, | 2773 | text, |
2732 | (unsigned long long)uuid[UI_CURRENT], | 2774 | (unsigned long long)uuid[UI_CURRENT], |
2733 | (unsigned long long)uuid[UI_BITMAP], | 2775 | (unsigned long long)uuid[UI_BITMAP], |
@@ -2749,13 +2791,13 @@ static void drbd_uuid_dump(struct drbd_conf *mdev, char *text, u64 *uuid, | |||
2749 | -1091 requires proto 91 | 2791 | -1091 requires proto 91 |
2750 | -1096 requires proto 96 | 2792 | -1096 requires proto 96 |
2751 | */ | 2793 | */ |
2752 | static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(local) | 2794 | static int drbd_uuid_compare(struct drbd_device *device, int *rule_nr) __must_hold(local) |
2753 | { | 2795 | { |
2754 | u64 self, peer; | 2796 | u64 self, peer; |
2755 | int i, j; | 2797 | int i, j; |
2756 | 2798 | ||
2757 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); | 2799 | self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
2758 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); | 2800 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
2759 | 2801 | ||
2760 | *rule_nr = 10; | 2802 | *rule_nr = 10; |
2761 | if (self == UUID_JUST_CREATED && peer == UUID_JUST_CREATED) | 2803 | if (self == UUID_JUST_CREATED && peer == UUID_JUST_CREATED) |
@@ -2774,46 +2816,46 @@ static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(l | |||
2774 | if (self == peer) { | 2816 | if (self == peer) { |
2775 | int rct, dc; /* roles at crash time */ | 2817 | int rct, dc; /* roles at crash time */ |
2776 | 2818 | ||
2777 | if (mdev->p_uuid[UI_BITMAP] == (u64)0 && mdev->ldev->md.uuid[UI_BITMAP] != (u64)0) { | 2819 | if (device->p_uuid[UI_BITMAP] == (u64)0 && device->ldev->md.uuid[UI_BITMAP] != (u64)0) { |
2778 | 2820 | ||
2779 | if (mdev->tconn->agreed_pro_version < 91) | 2821 | if (first_peer_device(device)->connection->agreed_pro_version < 91) |
2780 | return -1091; | 2822 | return -1091; |
2781 | 2823 | ||
2782 | if ((mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) && | 2824 | if ((device->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) && |
2783 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1))) { | 2825 | (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1))) { |
2784 | dev_info(DEV, "was SyncSource, missed the resync finished event, corrected myself:\n"); | 2826 | drbd_info(device, "was SyncSource, missed the resync finished event, corrected myself:\n"); |
2785 | drbd_uuid_move_history(mdev); | 2827 | drbd_uuid_move_history(device); |
2786 | mdev->ldev->md.uuid[UI_HISTORY_START] = mdev->ldev->md.uuid[UI_BITMAP]; | 2828 | device->ldev->md.uuid[UI_HISTORY_START] = device->ldev->md.uuid[UI_BITMAP]; |
2787 | mdev->ldev->md.uuid[UI_BITMAP] = 0; | 2829 | device->ldev->md.uuid[UI_BITMAP] = 0; |
2788 | 2830 | ||
2789 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, | 2831 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, |
2790 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); | 2832 | device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); |
2791 | *rule_nr = 34; | 2833 | *rule_nr = 34; |
2792 | } else { | 2834 | } else { |
2793 | dev_info(DEV, "was SyncSource (peer failed to write sync_uuid)\n"); | 2835 | drbd_info(device, "was SyncSource (peer failed to write sync_uuid)\n"); |
2794 | *rule_nr = 36; | 2836 | *rule_nr = 36; |
2795 | } | 2837 | } |
2796 | 2838 | ||
2797 | return 1; | 2839 | return 1; |
2798 | } | 2840 | } |
2799 | 2841 | ||
2800 | if (mdev->ldev->md.uuid[UI_BITMAP] == (u64)0 && mdev->p_uuid[UI_BITMAP] != (u64)0) { | 2842 | if (device->ldev->md.uuid[UI_BITMAP] == (u64)0 && device->p_uuid[UI_BITMAP] != (u64)0) { |
2801 | 2843 | ||
2802 | if (mdev->tconn->agreed_pro_version < 91) | 2844 | if (first_peer_device(device)->connection->agreed_pro_version < 91) |
2803 | return -1091; | 2845 | return -1091; |
2804 | 2846 | ||
2805 | if ((mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_BITMAP] & ~((u64)1)) && | 2847 | if ((device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_BITMAP] & ~((u64)1)) && |
2806 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1))) { | 2848 | (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1))) { |
2807 | dev_info(DEV, "was SyncTarget, peer missed the resync finished event, corrected peer:\n"); | 2849 | drbd_info(device, "was SyncTarget, peer missed the resync finished event, corrected peer:\n"); |
2808 | 2850 | ||
2809 | mdev->p_uuid[UI_HISTORY_START + 1] = mdev->p_uuid[UI_HISTORY_START]; | 2851 | device->p_uuid[UI_HISTORY_START + 1] = device->p_uuid[UI_HISTORY_START]; |
2810 | mdev->p_uuid[UI_HISTORY_START] = mdev->p_uuid[UI_BITMAP]; | 2852 | device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_BITMAP]; |
2811 | mdev->p_uuid[UI_BITMAP] = 0UL; | 2853 | device->p_uuid[UI_BITMAP] = 0UL; |
2812 | 2854 | ||
2813 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); | 2855 | drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
2814 | *rule_nr = 35; | 2856 | *rule_nr = 35; |
2815 | } else { | 2857 | } else { |
2816 | dev_info(DEV, "was SyncTarget (failed to write sync_uuid)\n"); | 2858 | drbd_info(device, "was SyncTarget (failed to write sync_uuid)\n"); |
2817 | *rule_nr = 37; | 2859 | *rule_nr = 37; |
2818 | } | 2860 | } |
2819 | 2861 | ||
@@ -2821,8 +2863,8 @@ static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(l | |||
2821 | } | 2863 | } |
2822 | 2864 | ||
2823 | /* Common power [off|failure] */ | 2865 | /* Common power [off|failure] */ |
2824 | rct = (test_bit(CRASHED_PRIMARY, &mdev->flags) ? 1 : 0) + | 2866 | rct = (test_bit(CRASHED_PRIMARY, &device->flags) ? 1 : 0) + |
2825 | (mdev->p_uuid[UI_FLAGS] & 2); | 2867 | (device->p_uuid[UI_FLAGS] & 2); |
2826 | /* lowest bit is set when we were primary, | 2868 | /* lowest bit is set when we were primary, |
2827 | * next bit (weight 2) is set when peer was primary */ | 2869 | * next bit (weight 2) is set when peer was primary */ |
2828 | *rule_nr = 40; | 2870 | *rule_nr = 40; |
@@ -2832,72 +2874,72 @@ static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(l | |||
2832 | case 1: /* self_pri && !peer_pri */ return 1; | 2874 | case 1: /* self_pri && !peer_pri */ return 1; |
2833 | case 2: /* !self_pri && peer_pri */ return -1; | 2875 | case 2: /* !self_pri && peer_pri */ return -1; |
2834 | case 3: /* self_pri && peer_pri */ | 2876 | case 3: /* self_pri && peer_pri */ |
2835 | dc = test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags); | 2877 | dc = test_bit(RESOLVE_CONFLICTS, &first_peer_device(device)->connection->flags); |
2836 | return dc ? -1 : 1; | 2878 | return dc ? -1 : 1; |
2837 | } | 2879 | } |
2838 | } | 2880 | } |
2839 | 2881 | ||
2840 | *rule_nr = 50; | 2882 | *rule_nr = 50; |
2841 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); | 2883 | peer = device->p_uuid[UI_BITMAP] & ~((u64)1); |
2842 | if (self == peer) | 2884 | if (self == peer) |
2843 | return -1; | 2885 | return -1; |
2844 | 2886 | ||
2845 | *rule_nr = 51; | 2887 | *rule_nr = 51; |
2846 | peer = mdev->p_uuid[UI_HISTORY_START] & ~((u64)1); | 2888 | peer = device->p_uuid[UI_HISTORY_START] & ~((u64)1); |
2847 | if (self == peer) { | 2889 | if (self == peer) { |
2848 | if (mdev->tconn->agreed_pro_version < 96 ? | 2890 | if (first_peer_device(device)->connection->agreed_pro_version < 96 ? |
2849 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == | 2891 | (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == |
2850 | (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : | 2892 | (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : |
2851 | peer + UUID_NEW_BM_OFFSET == (mdev->p_uuid[UI_BITMAP] & ~((u64)1))) { | 2893 | peer + UUID_NEW_BM_OFFSET == (device->p_uuid[UI_BITMAP] & ~((u64)1))) { |
2852 | /* The last P_SYNC_UUID did not get though. Undo the last start of | 2894 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
2853 | resync as sync source modifications of the peer's UUIDs. */ | 2895 | resync as sync source modifications of the peer's UUIDs. */ |
2854 | 2896 | ||
2855 | if (mdev->tconn->agreed_pro_version < 91) | 2897 | if (first_peer_device(device)->connection->agreed_pro_version < 91) |
2856 | return -1091; | 2898 | return -1091; |
2857 | 2899 | ||
2858 | mdev->p_uuid[UI_BITMAP] = mdev->p_uuid[UI_HISTORY_START]; | 2900 | device->p_uuid[UI_BITMAP] = device->p_uuid[UI_HISTORY_START]; |
2859 | mdev->p_uuid[UI_HISTORY_START] = mdev->p_uuid[UI_HISTORY_START + 1]; | 2901 | device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_HISTORY_START + 1]; |
2860 | 2902 | ||
2861 | dev_info(DEV, "Lost last syncUUID packet, corrected:\n"); | 2903 | drbd_info(device, "Lost last syncUUID packet, corrected:\n"); |
2862 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); | 2904 | drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
2863 | 2905 | ||
2864 | return -1; | 2906 | return -1; |
2865 | } | 2907 | } |
2866 | } | 2908 | } |
2867 | 2909 | ||
2868 | *rule_nr = 60; | 2910 | *rule_nr = 60; |
2869 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); | 2911 | self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
2870 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { | 2912 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
2871 | peer = mdev->p_uuid[i] & ~((u64)1); | 2913 | peer = device->p_uuid[i] & ~((u64)1); |
2872 | if (self == peer) | 2914 | if (self == peer) |
2873 | return -2; | 2915 | return -2; |
2874 | } | 2916 | } |
2875 | 2917 | ||
2876 | *rule_nr = 70; | 2918 | *rule_nr = 70; |
2877 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); | 2919 | self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
2878 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); | 2920 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
2879 | if (self == peer) | 2921 | if (self == peer) |
2880 | return 1; | 2922 | return 1; |
2881 | 2923 | ||
2882 | *rule_nr = 71; | 2924 | *rule_nr = 71; |
2883 | self = mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); | 2925 | self = device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); |
2884 | if (self == peer) { | 2926 | if (self == peer) { |
2885 | if (mdev->tconn->agreed_pro_version < 96 ? | 2927 | if (first_peer_device(device)->connection->agreed_pro_version < 96 ? |
2886 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == | 2928 | (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == |
2887 | (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) : | 2929 | (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) : |
2888 | self + UUID_NEW_BM_OFFSET == (mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) { | 2930 | self + UUID_NEW_BM_OFFSET == (device->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) { |
2889 | /* The last P_SYNC_UUID did not get though. Undo the last start of | 2931 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
2890 | resync as sync source modifications of our UUIDs. */ | 2932 | resync as sync source modifications of our UUIDs. */ |
2891 | 2933 | ||
2892 | if (mdev->tconn->agreed_pro_version < 91) | 2934 | if (first_peer_device(device)->connection->agreed_pro_version < 91) |
2893 | return -1091; | 2935 | return -1091; |
2894 | 2936 | ||
2895 | __drbd_uuid_set(mdev, UI_BITMAP, mdev->ldev->md.uuid[UI_HISTORY_START]); | 2937 | __drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_HISTORY_START]); |
2896 | __drbd_uuid_set(mdev, UI_HISTORY_START, mdev->ldev->md.uuid[UI_HISTORY_START + 1]); | 2938 | __drbd_uuid_set(device, UI_HISTORY_START, device->ldev->md.uuid[UI_HISTORY_START + 1]); |
2897 | 2939 | ||
2898 | dev_info(DEV, "Last syncUUID did not get through, corrected:\n"); | 2940 | drbd_info(device, "Last syncUUID did not get through, corrected:\n"); |
2899 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, | 2941 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, |
2900 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); | 2942 | device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); |
2901 | 2943 | ||
2902 | return 1; | 2944 | return 1; |
2903 | } | 2945 | } |
@@ -2905,24 +2947,24 @@ static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(l | |||
2905 | 2947 | ||
2906 | 2948 | ||
2907 | *rule_nr = 80; | 2949 | *rule_nr = 80; |
2908 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); | 2950 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
2909 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { | 2951 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
2910 | self = mdev->ldev->md.uuid[i] & ~((u64)1); | 2952 | self = device->ldev->md.uuid[i] & ~((u64)1); |
2911 | if (self == peer) | 2953 | if (self == peer) |
2912 | return 2; | 2954 | return 2; |
2913 | } | 2955 | } |
2914 | 2956 | ||
2915 | *rule_nr = 90; | 2957 | *rule_nr = 90; |
2916 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); | 2958 | self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
2917 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); | 2959 | peer = device->p_uuid[UI_BITMAP] & ~((u64)1); |
2918 | if (self == peer && self != ((u64)0)) | 2960 | if (self == peer && self != ((u64)0)) |
2919 | return 100; | 2961 | return 100; |
2920 | 2962 | ||
2921 | *rule_nr = 100; | 2963 | *rule_nr = 100; |
2922 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { | 2964 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
2923 | self = mdev->ldev->md.uuid[i] & ~((u64)1); | 2965 | self = device->ldev->md.uuid[i] & ~((u64)1); |
2924 | for (j = UI_HISTORY_START; j <= UI_HISTORY_END; j++) { | 2966 | for (j = UI_HISTORY_START; j <= UI_HISTORY_END; j++) { |
2925 | peer = mdev->p_uuid[j] & ~((u64)1); | 2967 | peer = device->p_uuid[j] & ~((u64)1); |
2926 | if (self == peer) | 2968 | if (self == peer) |
2927 | return -100; | 2969 | return -100; |
2928 | } | 2970 | } |
@@ -2934,36 +2976,38 @@ static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(l | |||
2934 | /* drbd_sync_handshake() returns the new conn state on success, or | 2976 | /* drbd_sync_handshake() returns the new conn state on success, or |
2935 | CONN_MASK (-1) on failure. | 2977 | CONN_MASK (-1) on failure. |
2936 | */ | 2978 | */ |
2937 | static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_role peer_role, | 2979 | static enum drbd_conns drbd_sync_handshake(struct drbd_peer_device *peer_device, |
2980 | enum drbd_role peer_role, | ||
2938 | enum drbd_disk_state peer_disk) __must_hold(local) | 2981 | enum drbd_disk_state peer_disk) __must_hold(local) |
2939 | { | 2982 | { |
2983 | struct drbd_device *device = peer_device->device; | ||
2940 | enum drbd_conns rv = C_MASK; | 2984 | enum drbd_conns rv = C_MASK; |
2941 | enum drbd_disk_state mydisk; | 2985 | enum drbd_disk_state mydisk; |
2942 | struct net_conf *nc; | 2986 | struct net_conf *nc; |
2943 | int hg, rule_nr, rr_conflict, tentative; | 2987 | int hg, rule_nr, rr_conflict, tentative; |
2944 | 2988 | ||
2945 | mydisk = mdev->state.disk; | 2989 | mydisk = device->state.disk; |
2946 | if (mydisk == D_NEGOTIATING) | 2990 | if (mydisk == D_NEGOTIATING) |
2947 | mydisk = mdev->new_state_tmp.disk; | 2991 | mydisk = device->new_state_tmp.disk; |
2948 | 2992 | ||
2949 | dev_info(DEV, "drbd_sync_handshake:\n"); | 2993 | drbd_info(device, "drbd_sync_handshake:\n"); |
2950 | 2994 | ||
2951 | spin_lock_irq(&mdev->ldev->md.uuid_lock); | 2995 | spin_lock_irq(&device->ldev->md.uuid_lock); |
2952 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, mdev->comm_bm_set, 0); | 2996 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, device->comm_bm_set, 0); |
2953 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, | 2997 | drbd_uuid_dump(device, "peer", device->p_uuid, |
2954 | mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); | 2998 | device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
2955 | 2999 | ||
2956 | hg = drbd_uuid_compare(mdev, &rule_nr); | 3000 | hg = drbd_uuid_compare(device, &rule_nr); |
2957 | spin_unlock_irq(&mdev->ldev->md.uuid_lock); | 3001 | spin_unlock_irq(&device->ldev->md.uuid_lock); |
2958 | 3002 | ||
2959 | dev_info(DEV, "uuid_compare()=%d by rule %d\n", hg, rule_nr); | 3003 | drbd_info(device, "uuid_compare()=%d by rule %d\n", hg, rule_nr); |
2960 | 3004 | ||
2961 | if (hg == -1000) { | 3005 | if (hg == -1000) { |
2962 | dev_alert(DEV, "Unrelated data, aborting!\n"); | 3006 | drbd_alert(device, "Unrelated data, aborting!\n"); |
2963 | return C_MASK; | 3007 | return C_MASK; |
2964 | } | 3008 | } |
2965 | if (hg < -1000) { | 3009 | if (hg < -1000) { |
2966 | dev_alert(DEV, "To resolve this both sides have to support at least protocol %d\n", -hg - 1000); | 3010 | drbd_alert(device, "To resolve this both sides have to support at least protocol %d\n", -hg - 1000); |
2967 | return C_MASK; | 3011 | return C_MASK; |
2968 | } | 3012 | } |
2969 | 3013 | ||
@@ -2973,38 +3017,38 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_rol | |||
2973 | hg = mydisk > D_INCONSISTENT ? 1 : -1; | 3017 | hg = mydisk > D_INCONSISTENT ? 1 : -1; |
2974 | if (f) | 3018 | if (f) |
2975 | hg = hg*2; | 3019 | hg = hg*2; |
2976 | dev_info(DEV, "Becoming sync %s due to disk states.\n", | 3020 | drbd_info(device, "Becoming sync %s due to disk states.\n", |
2977 | hg > 0 ? "source" : "target"); | 3021 | hg > 0 ? "source" : "target"); |
2978 | } | 3022 | } |
2979 | 3023 | ||
2980 | if (abs(hg) == 100) | 3024 | if (abs(hg) == 100) |
2981 | drbd_khelper(mdev, "initial-split-brain"); | 3025 | drbd_khelper(device, "initial-split-brain"); |
2982 | 3026 | ||
2983 | rcu_read_lock(); | 3027 | rcu_read_lock(); |
2984 | nc = rcu_dereference(mdev->tconn->net_conf); | 3028 | nc = rcu_dereference(peer_device->connection->net_conf); |
2985 | 3029 | ||
2986 | if (hg == 100 || (hg == -100 && nc->always_asbp)) { | 3030 | if (hg == 100 || (hg == -100 && nc->always_asbp)) { |
2987 | int pcount = (mdev->state.role == R_PRIMARY) | 3031 | int pcount = (device->state.role == R_PRIMARY) |
2988 | + (peer_role == R_PRIMARY); | 3032 | + (peer_role == R_PRIMARY); |
2989 | int forced = (hg == -100); | 3033 | int forced = (hg == -100); |
2990 | 3034 | ||
2991 | switch (pcount) { | 3035 | switch (pcount) { |
2992 | case 0: | 3036 | case 0: |
2993 | hg = drbd_asb_recover_0p(mdev); | 3037 | hg = drbd_asb_recover_0p(peer_device); |
2994 | break; | 3038 | break; |
2995 | case 1: | 3039 | case 1: |
2996 | hg = drbd_asb_recover_1p(mdev); | 3040 | hg = drbd_asb_recover_1p(peer_device); |
2997 | break; | 3041 | break; |
2998 | case 2: | 3042 | case 2: |
2999 | hg = drbd_asb_recover_2p(mdev); | 3043 | hg = drbd_asb_recover_2p(peer_device); |
3000 | break; | 3044 | break; |
3001 | } | 3045 | } |
3002 | if (abs(hg) < 100) { | 3046 | if (abs(hg) < 100) { |
3003 | dev_warn(DEV, "Split-Brain detected, %d primaries, " | 3047 | drbd_warn(device, "Split-Brain detected, %d primaries, " |
3004 | "automatically solved. Sync from %s node\n", | 3048 | "automatically solved. Sync from %s node\n", |
3005 | pcount, (hg < 0) ? "peer" : "this"); | 3049 | pcount, (hg < 0) ? "peer" : "this"); |
3006 | if (forced) { | 3050 | if (forced) { |
3007 | dev_warn(DEV, "Doing a full sync, since" | 3051 | drbd_warn(device, "Doing a full sync, since" |
3008 | " UUIDs where ambiguous.\n"); | 3052 | " UUIDs where ambiguous.\n"); |
3009 | hg = hg*2; | 3053 | hg = hg*2; |
3010 | } | 3054 | } |
@@ -3012,13 +3056,13 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_rol | |||
3012 | } | 3056 | } |
3013 | 3057 | ||
3014 | if (hg == -100) { | 3058 | if (hg == -100) { |
3015 | if (test_bit(DISCARD_MY_DATA, &mdev->flags) && !(mdev->p_uuid[UI_FLAGS]&1)) | 3059 | if (test_bit(DISCARD_MY_DATA, &device->flags) && !(device->p_uuid[UI_FLAGS]&1)) |
3016 | hg = -1; | 3060 | hg = -1; |
3017 | if (!test_bit(DISCARD_MY_DATA, &mdev->flags) && (mdev->p_uuid[UI_FLAGS]&1)) | 3061 | if (!test_bit(DISCARD_MY_DATA, &device->flags) && (device->p_uuid[UI_FLAGS]&1)) |
3018 | hg = 1; | 3062 | hg = 1; |
3019 | 3063 | ||
3020 | if (abs(hg) < 100) | 3064 | if (abs(hg) < 100) |
3021 | dev_warn(DEV, "Split-Brain detected, manually solved. " | 3065 | drbd_warn(device, "Split-Brain detected, manually solved. " |
3022 | "Sync from %s node\n", | 3066 | "Sync from %s node\n", |
3023 | (hg < 0) ? "peer" : "this"); | 3067 | (hg < 0) ? "peer" : "this"); |
3024 | } | 3068 | } |
@@ -3031,44 +3075,44 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_rol | |||
3031 | * after an attempted attach on a diskless node. | 3075 | * after an attempted attach on a diskless node. |
3032 | * We just refuse to attach -- well, we drop the "connection" | 3076 | * We just refuse to attach -- well, we drop the "connection" |
3033 | * to that disk, in a way... */ | 3077 | * to that disk, in a way... */ |
3034 | dev_alert(DEV, "Split-Brain detected but unresolved, dropping connection!\n"); | 3078 | drbd_alert(device, "Split-Brain detected but unresolved, dropping connection!\n"); |
3035 | drbd_khelper(mdev, "split-brain"); | 3079 | drbd_khelper(device, "split-brain"); |
3036 | return C_MASK; | 3080 | return C_MASK; |
3037 | } | 3081 | } |
3038 | 3082 | ||
3039 | if (hg > 0 && mydisk <= D_INCONSISTENT) { | 3083 | if (hg > 0 && mydisk <= D_INCONSISTENT) { |
3040 | dev_err(DEV, "I shall become SyncSource, but I am inconsistent!\n"); | 3084 | drbd_err(device, "I shall become SyncSource, but I am inconsistent!\n"); |
3041 | return C_MASK; | 3085 | return C_MASK; |
3042 | } | 3086 | } |
3043 | 3087 | ||
3044 | if (hg < 0 && /* by intention we do not use mydisk here. */ | 3088 | if (hg < 0 && /* by intention we do not use mydisk here. */ |
3045 | mdev->state.role == R_PRIMARY && mdev->state.disk >= D_CONSISTENT) { | 3089 | device->state.role == R_PRIMARY && device->state.disk >= D_CONSISTENT) { |
3046 | switch (rr_conflict) { | 3090 | switch (rr_conflict) { |
3047 | case ASB_CALL_HELPER: | 3091 | case ASB_CALL_HELPER: |
3048 | drbd_khelper(mdev, "pri-lost"); | 3092 | drbd_khelper(device, "pri-lost"); |
3049 | /* fall through */ | 3093 | /* fall through */ |
3050 | case ASB_DISCONNECT: | 3094 | case ASB_DISCONNECT: |
3051 | dev_err(DEV, "I shall become SyncTarget, but I am primary!\n"); | 3095 | drbd_err(device, "I shall become SyncTarget, but I am primary!\n"); |
3052 | return C_MASK; | 3096 | return C_MASK; |
3053 | case ASB_VIOLENTLY: | 3097 | case ASB_VIOLENTLY: |
3054 | dev_warn(DEV, "Becoming SyncTarget, violating the stable-data" | 3098 | drbd_warn(device, "Becoming SyncTarget, violating the stable-data" |
3055 | "assumption\n"); | 3099 | "assumption\n"); |
3056 | } | 3100 | } |
3057 | } | 3101 | } |
3058 | 3102 | ||
3059 | if (tentative || test_bit(CONN_DRY_RUN, &mdev->tconn->flags)) { | 3103 | if (tentative || test_bit(CONN_DRY_RUN, &peer_device->connection->flags)) { |
3060 | if (hg == 0) | 3104 | if (hg == 0) |
3061 | dev_info(DEV, "dry-run connect: No resync, would become Connected immediately.\n"); | 3105 | drbd_info(device, "dry-run connect: No resync, would become Connected immediately.\n"); |
3062 | else | 3106 | else |
3063 | dev_info(DEV, "dry-run connect: Would become %s, doing a %s resync.", | 3107 | drbd_info(device, "dry-run connect: Would become %s, doing a %s resync.", |
3064 | drbd_conn_str(hg > 0 ? C_SYNC_SOURCE : C_SYNC_TARGET), | 3108 | drbd_conn_str(hg > 0 ? C_SYNC_SOURCE : C_SYNC_TARGET), |
3065 | abs(hg) >= 2 ? "full" : "bit-map based"); | 3109 | abs(hg) >= 2 ? "full" : "bit-map based"); |
3066 | return C_MASK; | 3110 | return C_MASK; |
3067 | } | 3111 | } |
3068 | 3112 | ||
3069 | if (abs(hg) >= 2) { | 3113 | if (abs(hg) >= 2) { |
3070 | dev_info(DEV, "Writing the whole bitmap, full sync required after drbd_sync_handshake.\n"); | 3114 | drbd_info(device, "Writing the whole bitmap, full sync required after drbd_sync_handshake.\n"); |
3071 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, "set_n_write from sync_handshake", | 3115 | if (drbd_bitmap_io(device, &drbd_bmio_set_n_write, "set_n_write from sync_handshake", |
3072 | BM_LOCKED_SET_ALLOWED)) | 3116 | BM_LOCKED_SET_ALLOWED)) |
3073 | return C_MASK; | 3117 | return C_MASK; |
3074 | } | 3118 | } |
@@ -3079,9 +3123,9 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_rol | |||
3079 | rv = C_WF_BITMAP_T; | 3123 | rv = C_WF_BITMAP_T; |
3080 | } else { | 3124 | } else { |
3081 | rv = C_CONNECTED; | 3125 | rv = C_CONNECTED; |
3082 | if (drbd_bm_total_weight(mdev)) { | 3126 | if (drbd_bm_total_weight(device)) { |
3083 | dev_info(DEV, "No resync, but %lu bits in bitmap!\n", | 3127 | drbd_info(device, "No resync, but %lu bits in bitmap!\n", |
3084 | drbd_bm_total_weight(mdev)); | 3128 | drbd_bm_total_weight(device)); |
3085 | } | 3129 | } |
3086 | } | 3130 | } |
3087 | 3131 | ||
@@ -3102,7 +3146,7 @@ static enum drbd_after_sb_p convert_after_sb(enum drbd_after_sb_p peer) | |||
3102 | return peer; | 3146 | return peer; |
3103 | } | 3147 | } |
3104 | 3148 | ||
3105 | static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) | 3149 | static int receive_protocol(struct drbd_connection *connection, struct packet_info *pi) |
3106 | { | 3150 | { |
3107 | struct p_protocol *p = pi->data; | 3151 | struct p_protocol *p = pi->data; |
3108 | enum drbd_after_sb_p p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; | 3152 | enum drbd_after_sb_p p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; |
@@ -3120,58 +3164,58 @@ static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3120 | cf = be32_to_cpu(p->conn_flags); | 3164 | cf = be32_to_cpu(p->conn_flags); |
3121 | p_discard_my_data = cf & CF_DISCARD_MY_DATA; | 3165 | p_discard_my_data = cf & CF_DISCARD_MY_DATA; |
3122 | 3166 | ||
3123 | if (tconn->agreed_pro_version >= 87) { | 3167 | if (connection->agreed_pro_version >= 87) { |
3124 | int err; | 3168 | int err; |
3125 | 3169 | ||
3126 | if (pi->size > sizeof(integrity_alg)) | 3170 | if (pi->size > sizeof(integrity_alg)) |
3127 | return -EIO; | 3171 | return -EIO; |
3128 | err = drbd_recv_all(tconn, integrity_alg, pi->size); | 3172 | err = drbd_recv_all(connection, integrity_alg, pi->size); |
3129 | if (err) | 3173 | if (err) |
3130 | return err; | 3174 | return err; |
3131 | integrity_alg[SHARED_SECRET_MAX - 1] = 0; | 3175 | integrity_alg[SHARED_SECRET_MAX - 1] = 0; |
3132 | } | 3176 | } |
3133 | 3177 | ||
3134 | if (pi->cmd != P_PROTOCOL_UPDATE) { | 3178 | if (pi->cmd != P_PROTOCOL_UPDATE) { |
3135 | clear_bit(CONN_DRY_RUN, &tconn->flags); | 3179 | clear_bit(CONN_DRY_RUN, &connection->flags); |
3136 | 3180 | ||
3137 | if (cf & CF_DRY_RUN) | 3181 | if (cf & CF_DRY_RUN) |
3138 | set_bit(CONN_DRY_RUN, &tconn->flags); | 3182 | set_bit(CONN_DRY_RUN, &connection->flags); |
3139 | 3183 | ||
3140 | rcu_read_lock(); | 3184 | rcu_read_lock(); |
3141 | nc = rcu_dereference(tconn->net_conf); | 3185 | nc = rcu_dereference(connection->net_conf); |
3142 | 3186 | ||
3143 | if (p_proto != nc->wire_protocol) { | 3187 | if (p_proto != nc->wire_protocol) { |
3144 | conn_err(tconn, "incompatible %s settings\n", "protocol"); | 3188 | drbd_err(connection, "incompatible %s settings\n", "protocol"); |
3145 | goto disconnect_rcu_unlock; | 3189 | goto disconnect_rcu_unlock; |
3146 | } | 3190 | } |
3147 | 3191 | ||
3148 | if (convert_after_sb(p_after_sb_0p) != nc->after_sb_0p) { | 3192 | if (convert_after_sb(p_after_sb_0p) != nc->after_sb_0p) { |
3149 | conn_err(tconn, "incompatible %s settings\n", "after-sb-0pri"); | 3193 | drbd_err(connection, "incompatible %s settings\n", "after-sb-0pri"); |
3150 | goto disconnect_rcu_unlock; | 3194 | goto disconnect_rcu_unlock; |
3151 | } | 3195 | } |
3152 | 3196 | ||
3153 | if (convert_after_sb(p_after_sb_1p) != nc->after_sb_1p) { | 3197 | if (convert_after_sb(p_after_sb_1p) != nc->after_sb_1p) { |
3154 | conn_err(tconn, "incompatible %s settings\n", "after-sb-1pri"); | 3198 | drbd_err(connection, "incompatible %s settings\n", "after-sb-1pri"); |
3155 | goto disconnect_rcu_unlock; | 3199 | goto disconnect_rcu_unlock; |
3156 | } | 3200 | } |
3157 | 3201 | ||
3158 | if (convert_after_sb(p_after_sb_2p) != nc->after_sb_2p) { | 3202 | if (convert_after_sb(p_after_sb_2p) != nc->after_sb_2p) { |
3159 | conn_err(tconn, "incompatible %s settings\n", "after-sb-2pri"); | 3203 | drbd_err(connection, "incompatible %s settings\n", "after-sb-2pri"); |
3160 | goto disconnect_rcu_unlock; | 3204 | goto disconnect_rcu_unlock; |
3161 | } | 3205 | } |
3162 | 3206 | ||
3163 | if (p_discard_my_data && nc->discard_my_data) { | 3207 | if (p_discard_my_data && nc->discard_my_data) { |
3164 | conn_err(tconn, "incompatible %s settings\n", "discard-my-data"); | 3208 | drbd_err(connection, "incompatible %s settings\n", "discard-my-data"); |
3165 | goto disconnect_rcu_unlock; | 3209 | goto disconnect_rcu_unlock; |
3166 | } | 3210 | } |
3167 | 3211 | ||
3168 | if (p_two_primaries != nc->two_primaries) { | 3212 | if (p_two_primaries != nc->two_primaries) { |
3169 | conn_err(tconn, "incompatible %s settings\n", "allow-two-primaries"); | 3213 | drbd_err(connection, "incompatible %s settings\n", "allow-two-primaries"); |
3170 | goto disconnect_rcu_unlock; | 3214 | goto disconnect_rcu_unlock; |
3171 | } | 3215 | } |
3172 | 3216 | ||
3173 | if (strcmp(integrity_alg, nc->integrity_alg)) { | 3217 | if (strcmp(integrity_alg, nc->integrity_alg)) { |
3174 | conn_err(tconn, "incompatible %s settings\n", "data-integrity-alg"); | 3218 | drbd_err(connection, "incompatible %s settings\n", "data-integrity-alg"); |
3175 | goto disconnect_rcu_unlock; | 3219 | goto disconnect_rcu_unlock; |
3176 | } | 3220 | } |
3177 | 3221 | ||
@@ -3192,7 +3236,7 @@ static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3192 | 3236 | ||
3193 | peer_integrity_tfm = crypto_alloc_hash(integrity_alg, 0, CRYPTO_ALG_ASYNC); | 3237 | peer_integrity_tfm = crypto_alloc_hash(integrity_alg, 0, CRYPTO_ALG_ASYNC); |
3194 | if (!peer_integrity_tfm) { | 3238 | if (!peer_integrity_tfm) { |
3195 | conn_err(tconn, "peer data-integrity-alg %s not supported\n", | 3239 | drbd_err(connection, "peer data-integrity-alg %s not supported\n", |
3196 | integrity_alg); | 3240 | integrity_alg); |
3197 | goto disconnect; | 3241 | goto disconnect; |
3198 | } | 3242 | } |
@@ -3201,20 +3245,20 @@ static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3201 | int_dig_in = kmalloc(hash_size, GFP_KERNEL); | 3245 | int_dig_in = kmalloc(hash_size, GFP_KERNEL); |
3202 | int_dig_vv = kmalloc(hash_size, GFP_KERNEL); | 3246 | int_dig_vv = kmalloc(hash_size, GFP_KERNEL); |
3203 | if (!(int_dig_in && int_dig_vv)) { | 3247 | if (!(int_dig_in && int_dig_vv)) { |
3204 | conn_err(tconn, "Allocation of buffers for data integrity checking failed\n"); | 3248 | drbd_err(connection, "Allocation of buffers for data integrity checking failed\n"); |
3205 | goto disconnect; | 3249 | goto disconnect; |
3206 | } | 3250 | } |
3207 | } | 3251 | } |
3208 | 3252 | ||
3209 | new_net_conf = kmalloc(sizeof(struct net_conf), GFP_KERNEL); | 3253 | new_net_conf = kmalloc(sizeof(struct net_conf), GFP_KERNEL); |
3210 | if (!new_net_conf) { | 3254 | if (!new_net_conf) { |
3211 | conn_err(tconn, "Allocation of new net_conf failed\n"); | 3255 | drbd_err(connection, "Allocation of new net_conf failed\n"); |
3212 | goto disconnect; | 3256 | goto disconnect; |
3213 | } | 3257 | } |
3214 | 3258 | ||
3215 | mutex_lock(&tconn->data.mutex); | 3259 | mutex_lock(&connection->data.mutex); |
3216 | mutex_lock(&tconn->conf_update); | 3260 | mutex_lock(&connection->resource->conf_update); |
3217 | old_net_conf = tconn->net_conf; | 3261 | old_net_conf = connection->net_conf; |
3218 | *new_net_conf = *old_net_conf; | 3262 | *new_net_conf = *old_net_conf; |
3219 | 3263 | ||
3220 | new_net_conf->wire_protocol = p_proto; | 3264 | new_net_conf->wire_protocol = p_proto; |
@@ -3223,19 +3267,19 @@ static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3223 | new_net_conf->after_sb_2p = convert_after_sb(p_after_sb_2p); | 3267 | new_net_conf->after_sb_2p = convert_after_sb(p_after_sb_2p); |
3224 | new_net_conf->two_primaries = p_two_primaries; | 3268 | new_net_conf->two_primaries = p_two_primaries; |
3225 | 3269 | ||
3226 | rcu_assign_pointer(tconn->net_conf, new_net_conf); | 3270 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
3227 | mutex_unlock(&tconn->conf_update); | 3271 | mutex_unlock(&connection->resource->conf_update); |
3228 | mutex_unlock(&tconn->data.mutex); | 3272 | mutex_unlock(&connection->data.mutex); |
3229 | 3273 | ||
3230 | crypto_free_hash(tconn->peer_integrity_tfm); | 3274 | crypto_free_hash(connection->peer_integrity_tfm); |
3231 | kfree(tconn->int_dig_in); | 3275 | kfree(connection->int_dig_in); |
3232 | kfree(tconn->int_dig_vv); | 3276 | kfree(connection->int_dig_vv); |
3233 | tconn->peer_integrity_tfm = peer_integrity_tfm; | 3277 | connection->peer_integrity_tfm = peer_integrity_tfm; |
3234 | tconn->int_dig_in = int_dig_in; | 3278 | connection->int_dig_in = int_dig_in; |
3235 | tconn->int_dig_vv = int_dig_vv; | 3279 | connection->int_dig_vv = int_dig_vv; |
3236 | 3280 | ||
3237 | if (strcmp(old_net_conf->integrity_alg, integrity_alg)) | 3281 | if (strcmp(old_net_conf->integrity_alg, integrity_alg)) |
3238 | conn_info(tconn, "peer data-integrity-alg: %s\n", | 3282 | drbd_info(connection, "peer data-integrity-alg: %s\n", |
3239 | integrity_alg[0] ? integrity_alg : "(none)"); | 3283 | integrity_alg[0] ? integrity_alg : "(none)"); |
3240 | 3284 | ||
3241 | synchronize_rcu(); | 3285 | synchronize_rcu(); |
@@ -3248,7 +3292,7 @@ disconnect: | |||
3248 | crypto_free_hash(peer_integrity_tfm); | 3292 | crypto_free_hash(peer_integrity_tfm); |
3249 | kfree(int_dig_in); | 3293 | kfree(int_dig_in); |
3250 | kfree(int_dig_vv); | 3294 | kfree(int_dig_vv); |
3251 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 3295 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3252 | return -EIO; | 3296 | return -EIO; |
3253 | } | 3297 | } |
3254 | 3298 | ||
@@ -3257,7 +3301,8 @@ disconnect: | |||
3257 | * return: NULL (alg name was "") | 3301 | * return: NULL (alg name was "") |
3258 | * ERR_PTR(error) if something goes wrong | 3302 | * ERR_PTR(error) if something goes wrong |
3259 | * or the crypto hash ptr, if it worked out ok. */ | 3303 | * or the crypto hash ptr, if it worked out ok. */ |
3260 | struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_conf *mdev, | 3304 | static |
3305 | struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_device *device, | ||
3261 | const char *alg, const char *name) | 3306 | const char *alg, const char *name) |
3262 | { | 3307 | { |
3263 | struct crypto_hash *tfm; | 3308 | struct crypto_hash *tfm; |
@@ -3267,21 +3312,21 @@ struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_conf *mdev, | |||
3267 | 3312 | ||
3268 | tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); | 3313 | tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); |
3269 | if (IS_ERR(tfm)) { | 3314 | if (IS_ERR(tfm)) { |
3270 | dev_err(DEV, "Can not allocate \"%s\" as %s (reason: %ld)\n", | 3315 | drbd_err(device, "Can not allocate \"%s\" as %s (reason: %ld)\n", |
3271 | alg, name, PTR_ERR(tfm)); | 3316 | alg, name, PTR_ERR(tfm)); |
3272 | return tfm; | 3317 | return tfm; |
3273 | } | 3318 | } |
3274 | return tfm; | 3319 | return tfm; |
3275 | } | 3320 | } |
3276 | 3321 | ||
3277 | static int ignore_remaining_packet(struct drbd_tconn *tconn, struct packet_info *pi) | 3322 | static int ignore_remaining_packet(struct drbd_connection *connection, struct packet_info *pi) |
3278 | { | 3323 | { |
3279 | void *buffer = tconn->data.rbuf; | 3324 | void *buffer = connection->data.rbuf; |
3280 | int size = pi->size; | 3325 | int size = pi->size; |
3281 | 3326 | ||
3282 | while (size) { | 3327 | while (size) { |
3283 | int s = min_t(int, size, DRBD_SOCKET_BUFFER_SIZE); | 3328 | int s = min_t(int, size, DRBD_SOCKET_BUFFER_SIZE); |
3284 | s = drbd_recv(tconn, buffer, s); | 3329 | s = drbd_recv(connection, buffer, s); |
3285 | if (s <= 0) { | 3330 | if (s <= 0) { |
3286 | if (s < 0) | 3331 | if (s < 0) |
3287 | return s; | 3332 | return s; |
@@ -3305,30 +3350,32 @@ static int ignore_remaining_packet(struct drbd_tconn *tconn, struct packet_info | |||
3305 | * | 3350 | * |
3306 | * (We can also end up here if drbd is misconfigured.) | 3351 | * (We can also end up here if drbd is misconfigured.) |
3307 | */ | 3352 | */ |
3308 | static int config_unknown_volume(struct drbd_tconn *tconn, struct packet_info *pi) | 3353 | static int config_unknown_volume(struct drbd_connection *connection, struct packet_info *pi) |
3309 | { | 3354 | { |
3310 | conn_warn(tconn, "%s packet received for volume %u, which is not configured locally\n", | 3355 | drbd_warn(connection, "%s packet received for volume %u, which is not configured locally\n", |
3311 | cmdname(pi->cmd), pi->vnr); | 3356 | cmdname(pi->cmd), pi->vnr); |
3312 | return ignore_remaining_packet(tconn, pi); | 3357 | return ignore_remaining_packet(connection, pi); |
3313 | } | 3358 | } |
3314 | 3359 | ||
3315 | static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | 3360 | static int receive_SyncParam(struct drbd_connection *connection, struct packet_info *pi) |
3316 | { | 3361 | { |
3317 | struct drbd_conf *mdev; | 3362 | struct drbd_peer_device *peer_device; |
3363 | struct drbd_device *device; | ||
3318 | struct p_rs_param_95 *p; | 3364 | struct p_rs_param_95 *p; |
3319 | unsigned int header_size, data_size, exp_max_sz; | 3365 | unsigned int header_size, data_size, exp_max_sz; |
3320 | struct crypto_hash *verify_tfm = NULL; | 3366 | struct crypto_hash *verify_tfm = NULL; |
3321 | struct crypto_hash *csums_tfm = NULL; | 3367 | struct crypto_hash *csums_tfm = NULL; |
3322 | struct net_conf *old_net_conf, *new_net_conf = NULL; | 3368 | struct net_conf *old_net_conf, *new_net_conf = NULL; |
3323 | struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL; | 3369 | struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL; |
3324 | const int apv = tconn->agreed_pro_version; | 3370 | const int apv = connection->agreed_pro_version; |
3325 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; | 3371 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; |
3326 | int fifo_size = 0; | 3372 | int fifo_size = 0; |
3327 | int err; | 3373 | int err; |
3328 | 3374 | ||
3329 | mdev = vnr_to_mdev(tconn, pi->vnr); | 3375 | peer_device = conn_peer_device(connection, pi->vnr); |
3330 | if (!mdev) | 3376 | if (!peer_device) |
3331 | return config_unknown_volume(tconn, pi); | 3377 | return config_unknown_volume(connection, pi); |
3378 | device = peer_device->device; | ||
3332 | 3379 | ||
3333 | exp_max_sz = apv <= 87 ? sizeof(struct p_rs_param) | 3380 | exp_max_sz = apv <= 87 ? sizeof(struct p_rs_param) |
3334 | : apv == 88 ? sizeof(struct p_rs_param) | 3381 | : apv == 88 ? sizeof(struct p_rs_param) |
@@ -3337,7 +3384,7 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3337 | : /* apv >= 95 */ sizeof(struct p_rs_param_95); | 3384 | : /* apv >= 95 */ sizeof(struct p_rs_param_95); |
3338 | 3385 | ||
3339 | if (pi->size > exp_max_sz) { | 3386 | if (pi->size > exp_max_sz) { |
3340 | dev_err(DEV, "SyncParam packet too long: received %u, expected <= %u bytes\n", | 3387 | drbd_err(device, "SyncParam packet too long: received %u, expected <= %u bytes\n", |
3341 | pi->size, exp_max_sz); | 3388 | pi->size, exp_max_sz); |
3342 | return -EIO; | 3389 | return -EIO; |
3343 | } | 3390 | } |
@@ -3348,33 +3395,33 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3348 | } else if (apv <= 94) { | 3395 | } else if (apv <= 94) { |
3349 | header_size = sizeof(struct p_rs_param_89); | 3396 | header_size = sizeof(struct p_rs_param_89); |
3350 | data_size = pi->size - header_size; | 3397 | data_size = pi->size - header_size; |
3351 | D_ASSERT(data_size == 0); | 3398 | D_ASSERT(device, data_size == 0); |
3352 | } else { | 3399 | } else { |
3353 | header_size = sizeof(struct p_rs_param_95); | 3400 | header_size = sizeof(struct p_rs_param_95); |
3354 | data_size = pi->size - header_size; | 3401 | data_size = pi->size - header_size; |
3355 | D_ASSERT(data_size == 0); | 3402 | D_ASSERT(device, data_size == 0); |
3356 | } | 3403 | } |
3357 | 3404 | ||
3358 | /* initialize verify_alg and csums_alg */ | 3405 | /* initialize verify_alg and csums_alg */ |
3359 | p = pi->data; | 3406 | p = pi->data; |
3360 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); | 3407 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); |
3361 | 3408 | ||
3362 | err = drbd_recv_all(mdev->tconn, p, header_size); | 3409 | err = drbd_recv_all(peer_device->connection, p, header_size); |
3363 | if (err) | 3410 | if (err) |
3364 | return err; | 3411 | return err; |
3365 | 3412 | ||
3366 | mutex_lock(&mdev->tconn->conf_update); | 3413 | mutex_lock(&connection->resource->conf_update); |
3367 | old_net_conf = mdev->tconn->net_conf; | 3414 | old_net_conf = peer_device->connection->net_conf; |
3368 | if (get_ldev(mdev)) { | 3415 | if (get_ldev(device)) { |
3369 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); | 3416 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
3370 | if (!new_disk_conf) { | 3417 | if (!new_disk_conf) { |
3371 | put_ldev(mdev); | 3418 | put_ldev(device); |
3372 | mutex_unlock(&mdev->tconn->conf_update); | 3419 | mutex_unlock(&connection->resource->conf_update); |
3373 | dev_err(DEV, "Allocation of new disk_conf failed\n"); | 3420 | drbd_err(device, "Allocation of new disk_conf failed\n"); |
3374 | return -ENOMEM; | 3421 | return -ENOMEM; |
3375 | } | 3422 | } |
3376 | 3423 | ||
3377 | old_disk_conf = mdev->ldev->disk_conf; | 3424 | old_disk_conf = device->ldev->disk_conf; |
3378 | *new_disk_conf = *old_disk_conf; | 3425 | *new_disk_conf = *old_disk_conf; |
3379 | 3426 | ||
3380 | new_disk_conf->resync_rate = be32_to_cpu(p->resync_rate); | 3427 | new_disk_conf->resync_rate = be32_to_cpu(p->resync_rate); |
@@ -3383,37 +3430,37 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3383 | if (apv >= 88) { | 3430 | if (apv >= 88) { |
3384 | if (apv == 88) { | 3431 | if (apv == 88) { |
3385 | if (data_size > SHARED_SECRET_MAX || data_size == 0) { | 3432 | if (data_size > SHARED_SECRET_MAX || data_size == 0) { |
3386 | dev_err(DEV, "verify-alg of wrong size, " | 3433 | drbd_err(device, "verify-alg of wrong size, " |
3387 | "peer wants %u, accepting only up to %u byte\n", | 3434 | "peer wants %u, accepting only up to %u byte\n", |
3388 | data_size, SHARED_SECRET_MAX); | 3435 | data_size, SHARED_SECRET_MAX); |
3389 | err = -EIO; | 3436 | err = -EIO; |
3390 | goto reconnect; | 3437 | goto reconnect; |
3391 | } | 3438 | } |
3392 | 3439 | ||
3393 | err = drbd_recv_all(mdev->tconn, p->verify_alg, data_size); | 3440 | err = drbd_recv_all(peer_device->connection, p->verify_alg, data_size); |
3394 | if (err) | 3441 | if (err) |
3395 | goto reconnect; | 3442 | goto reconnect; |
3396 | /* we expect NUL terminated string */ | 3443 | /* we expect NUL terminated string */ |
3397 | /* but just in case someone tries to be evil */ | 3444 | /* but just in case someone tries to be evil */ |
3398 | D_ASSERT(p->verify_alg[data_size-1] == 0); | 3445 | D_ASSERT(device, p->verify_alg[data_size-1] == 0); |
3399 | p->verify_alg[data_size-1] = 0; | 3446 | p->verify_alg[data_size-1] = 0; |
3400 | 3447 | ||
3401 | } else /* apv >= 89 */ { | 3448 | } else /* apv >= 89 */ { |
3402 | /* we still expect NUL terminated strings */ | 3449 | /* we still expect NUL terminated strings */ |
3403 | /* but just in case someone tries to be evil */ | 3450 | /* but just in case someone tries to be evil */ |
3404 | D_ASSERT(p->verify_alg[SHARED_SECRET_MAX-1] == 0); | 3451 | D_ASSERT(device, p->verify_alg[SHARED_SECRET_MAX-1] == 0); |
3405 | D_ASSERT(p->csums_alg[SHARED_SECRET_MAX-1] == 0); | 3452 | D_ASSERT(device, p->csums_alg[SHARED_SECRET_MAX-1] == 0); |
3406 | p->verify_alg[SHARED_SECRET_MAX-1] = 0; | 3453 | p->verify_alg[SHARED_SECRET_MAX-1] = 0; |
3407 | p->csums_alg[SHARED_SECRET_MAX-1] = 0; | 3454 | p->csums_alg[SHARED_SECRET_MAX-1] = 0; |
3408 | } | 3455 | } |
3409 | 3456 | ||
3410 | if (strcmp(old_net_conf->verify_alg, p->verify_alg)) { | 3457 | if (strcmp(old_net_conf->verify_alg, p->verify_alg)) { |
3411 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { | 3458 | if (device->state.conn == C_WF_REPORT_PARAMS) { |
3412 | dev_err(DEV, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", | 3459 | drbd_err(device, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", |
3413 | old_net_conf->verify_alg, p->verify_alg); | 3460 | old_net_conf->verify_alg, p->verify_alg); |
3414 | goto disconnect; | 3461 | goto disconnect; |
3415 | } | 3462 | } |
3416 | verify_tfm = drbd_crypto_alloc_digest_safe(mdev, | 3463 | verify_tfm = drbd_crypto_alloc_digest_safe(device, |
3417 | p->verify_alg, "verify-alg"); | 3464 | p->verify_alg, "verify-alg"); |
3418 | if (IS_ERR(verify_tfm)) { | 3465 | if (IS_ERR(verify_tfm)) { |
3419 | verify_tfm = NULL; | 3466 | verify_tfm = NULL; |
@@ -3422,12 +3469,12 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3422 | } | 3469 | } |
3423 | 3470 | ||
3424 | if (apv >= 89 && strcmp(old_net_conf->csums_alg, p->csums_alg)) { | 3471 | if (apv >= 89 && strcmp(old_net_conf->csums_alg, p->csums_alg)) { |
3425 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { | 3472 | if (device->state.conn == C_WF_REPORT_PARAMS) { |
3426 | dev_err(DEV, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", | 3473 | drbd_err(device, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", |
3427 | old_net_conf->csums_alg, p->csums_alg); | 3474 | old_net_conf->csums_alg, p->csums_alg); |
3428 | goto disconnect; | 3475 | goto disconnect; |
3429 | } | 3476 | } |
3430 | csums_tfm = drbd_crypto_alloc_digest_safe(mdev, | 3477 | csums_tfm = drbd_crypto_alloc_digest_safe(device, |
3431 | p->csums_alg, "csums-alg"); | 3478 | p->csums_alg, "csums-alg"); |
3432 | if (IS_ERR(csums_tfm)) { | 3479 | if (IS_ERR(csums_tfm)) { |
3433 | csums_tfm = NULL; | 3480 | csums_tfm = NULL; |
@@ -3442,11 +3489,11 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3442 | new_disk_conf->c_max_rate = be32_to_cpu(p->c_max_rate); | 3489 | new_disk_conf->c_max_rate = be32_to_cpu(p->c_max_rate); |
3443 | 3490 | ||
3444 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; | 3491 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
3445 | if (fifo_size != mdev->rs_plan_s->size) { | 3492 | if (fifo_size != device->rs_plan_s->size) { |
3446 | new_plan = fifo_alloc(fifo_size); | 3493 | new_plan = fifo_alloc(fifo_size); |
3447 | if (!new_plan) { | 3494 | if (!new_plan) { |
3448 | dev_err(DEV, "kmalloc of fifo_buffer failed"); | 3495 | drbd_err(device, "kmalloc of fifo_buffer failed"); |
3449 | put_ldev(mdev); | 3496 | put_ldev(device); |
3450 | goto disconnect; | 3497 | goto disconnect; |
3451 | } | 3498 | } |
3452 | } | 3499 | } |
@@ -3455,7 +3502,7 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3455 | if (verify_tfm || csums_tfm) { | 3502 | if (verify_tfm || csums_tfm) { |
3456 | new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); | 3503 | new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
3457 | if (!new_net_conf) { | 3504 | if (!new_net_conf) { |
3458 | dev_err(DEV, "Allocation of new net_conf failed\n"); | 3505 | drbd_err(device, "Allocation of new net_conf failed\n"); |
3459 | goto disconnect; | 3506 | goto disconnect; |
3460 | } | 3507 | } |
3461 | 3508 | ||
@@ -3464,32 +3511,32 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3464 | if (verify_tfm) { | 3511 | if (verify_tfm) { |
3465 | strcpy(new_net_conf->verify_alg, p->verify_alg); | 3512 | strcpy(new_net_conf->verify_alg, p->verify_alg); |
3466 | new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; | 3513 | new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; |
3467 | crypto_free_hash(mdev->tconn->verify_tfm); | 3514 | crypto_free_hash(peer_device->connection->verify_tfm); |
3468 | mdev->tconn->verify_tfm = verify_tfm; | 3515 | peer_device->connection->verify_tfm = verify_tfm; |
3469 | dev_info(DEV, "using verify-alg: \"%s\"\n", p->verify_alg); | 3516 | drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg); |
3470 | } | 3517 | } |
3471 | if (csums_tfm) { | 3518 | if (csums_tfm) { |
3472 | strcpy(new_net_conf->csums_alg, p->csums_alg); | 3519 | strcpy(new_net_conf->csums_alg, p->csums_alg); |
3473 | new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; | 3520 | new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; |
3474 | crypto_free_hash(mdev->tconn->csums_tfm); | 3521 | crypto_free_hash(peer_device->connection->csums_tfm); |
3475 | mdev->tconn->csums_tfm = csums_tfm; | 3522 | peer_device->connection->csums_tfm = csums_tfm; |
3476 | dev_info(DEV, "using csums-alg: \"%s\"\n", p->csums_alg); | 3523 | drbd_info(device, "using csums-alg: \"%s\"\n", p->csums_alg); |
3477 | } | 3524 | } |
3478 | rcu_assign_pointer(tconn->net_conf, new_net_conf); | 3525 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
3479 | } | 3526 | } |
3480 | } | 3527 | } |
3481 | 3528 | ||
3482 | if (new_disk_conf) { | 3529 | if (new_disk_conf) { |
3483 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); | 3530 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
3484 | put_ldev(mdev); | 3531 | put_ldev(device); |
3485 | } | 3532 | } |
3486 | 3533 | ||
3487 | if (new_plan) { | 3534 | if (new_plan) { |
3488 | old_plan = mdev->rs_plan_s; | 3535 | old_plan = device->rs_plan_s; |
3489 | rcu_assign_pointer(mdev->rs_plan_s, new_plan); | 3536 | rcu_assign_pointer(device->rs_plan_s, new_plan); |
3490 | } | 3537 | } |
3491 | 3538 | ||
3492 | mutex_unlock(&mdev->tconn->conf_update); | 3539 | mutex_unlock(&connection->resource->conf_update); |
3493 | synchronize_rcu(); | 3540 | synchronize_rcu(); |
3494 | if (new_net_conf) | 3541 | if (new_net_conf) |
3495 | kfree(old_net_conf); | 3542 | kfree(old_net_conf); |
@@ -3500,30 +3547,30 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3500 | 3547 | ||
3501 | reconnect: | 3548 | reconnect: |
3502 | if (new_disk_conf) { | 3549 | if (new_disk_conf) { |
3503 | put_ldev(mdev); | 3550 | put_ldev(device); |
3504 | kfree(new_disk_conf); | 3551 | kfree(new_disk_conf); |
3505 | } | 3552 | } |
3506 | mutex_unlock(&mdev->tconn->conf_update); | 3553 | mutex_unlock(&connection->resource->conf_update); |
3507 | return -EIO; | 3554 | return -EIO; |
3508 | 3555 | ||
3509 | disconnect: | 3556 | disconnect: |
3510 | kfree(new_plan); | 3557 | kfree(new_plan); |
3511 | if (new_disk_conf) { | 3558 | if (new_disk_conf) { |
3512 | put_ldev(mdev); | 3559 | put_ldev(device); |
3513 | kfree(new_disk_conf); | 3560 | kfree(new_disk_conf); |
3514 | } | 3561 | } |
3515 | mutex_unlock(&mdev->tconn->conf_update); | 3562 | mutex_unlock(&connection->resource->conf_update); |
3516 | /* just for completeness: actually not needed, | 3563 | /* just for completeness: actually not needed, |
3517 | * as this is not reached if csums_tfm was ok. */ | 3564 | * as this is not reached if csums_tfm was ok. */ |
3518 | crypto_free_hash(csums_tfm); | 3565 | crypto_free_hash(csums_tfm); |
3519 | /* but free the verify_tfm again, if csums_tfm did not work out */ | 3566 | /* but free the verify_tfm again, if csums_tfm did not work out */ |
3520 | crypto_free_hash(verify_tfm); | 3567 | crypto_free_hash(verify_tfm); |
3521 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 3568 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3522 | return -EIO; | 3569 | return -EIO; |
3523 | } | 3570 | } |
3524 | 3571 | ||
3525 | /* warn if the arguments differ by more than 12.5% */ | 3572 | /* warn if the arguments differ by more than 12.5% */ |
3526 | static void warn_if_differ_considerably(struct drbd_conf *mdev, | 3573 | static void warn_if_differ_considerably(struct drbd_device *device, |
3527 | const char *s, sector_t a, sector_t b) | 3574 | const char *s, sector_t a, sector_t b) |
3528 | { | 3575 | { |
3529 | sector_t d; | 3576 | sector_t d; |
@@ -3531,54 +3578,56 @@ static void warn_if_differ_considerably(struct drbd_conf *mdev, | |||
3531 | return; | 3578 | return; |
3532 | d = (a > b) ? (a - b) : (b - a); | 3579 | d = (a > b) ? (a - b) : (b - a); |
3533 | if (d > (a>>3) || d > (b>>3)) | 3580 | if (d > (a>>3) || d > (b>>3)) |
3534 | dev_warn(DEV, "Considerable difference in %s: %llus vs. %llus\n", s, | 3581 | drbd_warn(device, "Considerable difference in %s: %llus vs. %llus\n", s, |
3535 | (unsigned long long)a, (unsigned long long)b); | 3582 | (unsigned long long)a, (unsigned long long)b); |
3536 | } | 3583 | } |
3537 | 3584 | ||
3538 | static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) | 3585 | static int receive_sizes(struct drbd_connection *connection, struct packet_info *pi) |
3539 | { | 3586 | { |
3540 | struct drbd_conf *mdev; | 3587 | struct drbd_peer_device *peer_device; |
3588 | struct drbd_device *device; | ||
3541 | struct p_sizes *p = pi->data; | 3589 | struct p_sizes *p = pi->data; |
3542 | enum determine_dev_size dd = DS_UNCHANGED; | 3590 | enum determine_dev_size dd = DS_UNCHANGED; |
3543 | sector_t p_size, p_usize, my_usize; | 3591 | sector_t p_size, p_usize, my_usize; |
3544 | int ldsc = 0; /* local disk size changed */ | 3592 | int ldsc = 0; /* local disk size changed */ |
3545 | enum dds_flags ddsf; | 3593 | enum dds_flags ddsf; |
3546 | 3594 | ||
3547 | mdev = vnr_to_mdev(tconn, pi->vnr); | 3595 | peer_device = conn_peer_device(connection, pi->vnr); |
3548 | if (!mdev) | 3596 | if (!peer_device) |
3549 | return config_unknown_volume(tconn, pi); | 3597 | return config_unknown_volume(connection, pi); |
3598 | device = peer_device->device; | ||
3550 | 3599 | ||
3551 | p_size = be64_to_cpu(p->d_size); | 3600 | p_size = be64_to_cpu(p->d_size); |
3552 | p_usize = be64_to_cpu(p->u_size); | 3601 | p_usize = be64_to_cpu(p->u_size); |
3553 | 3602 | ||
3554 | /* just store the peer's disk size for now. | 3603 | /* just store the peer's disk size for now. |
3555 | * we still need to figure out whether we accept that. */ | 3604 | * we still need to figure out whether we accept that. */ |
3556 | mdev->p_size = p_size; | 3605 | device->p_size = p_size; |
3557 | 3606 | ||
3558 | if (get_ldev(mdev)) { | 3607 | if (get_ldev(device)) { |
3559 | rcu_read_lock(); | 3608 | rcu_read_lock(); |
3560 | my_usize = rcu_dereference(mdev->ldev->disk_conf)->disk_size; | 3609 | my_usize = rcu_dereference(device->ldev->disk_conf)->disk_size; |
3561 | rcu_read_unlock(); | 3610 | rcu_read_unlock(); |
3562 | 3611 | ||
3563 | warn_if_differ_considerably(mdev, "lower level device sizes", | 3612 | warn_if_differ_considerably(device, "lower level device sizes", |
3564 | p_size, drbd_get_max_capacity(mdev->ldev)); | 3613 | p_size, drbd_get_max_capacity(device->ldev)); |
3565 | warn_if_differ_considerably(mdev, "user requested size", | 3614 | warn_if_differ_considerably(device, "user requested size", |
3566 | p_usize, my_usize); | 3615 | p_usize, my_usize); |
3567 | 3616 | ||
3568 | /* if this is the first connect, or an otherwise expected | 3617 | /* if this is the first connect, or an otherwise expected |
3569 | * param exchange, choose the minimum */ | 3618 | * param exchange, choose the minimum */ |
3570 | if (mdev->state.conn == C_WF_REPORT_PARAMS) | 3619 | if (device->state.conn == C_WF_REPORT_PARAMS) |
3571 | p_usize = min_not_zero(my_usize, p_usize); | 3620 | p_usize = min_not_zero(my_usize, p_usize); |
3572 | 3621 | ||
3573 | /* Never shrink a device with usable data during connect. | 3622 | /* Never shrink a device with usable data during connect. |
3574 | But allow online shrinking if we are connected. */ | 3623 | But allow online shrinking if we are connected. */ |
3575 | if (drbd_new_dev_size(mdev, mdev->ldev, p_usize, 0) < | 3624 | if (drbd_new_dev_size(device, device->ldev, p_usize, 0) < |
3576 | drbd_get_capacity(mdev->this_bdev) && | 3625 | drbd_get_capacity(device->this_bdev) && |
3577 | mdev->state.disk >= D_OUTDATED && | 3626 | device->state.disk >= D_OUTDATED && |
3578 | mdev->state.conn < C_CONNECTED) { | 3627 | device->state.conn < C_CONNECTED) { |
3579 | dev_err(DEV, "The peer's disk size is too small!\n"); | 3628 | drbd_err(device, "The peer's disk size is too small!\n"); |
3580 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 3629 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3581 | put_ldev(mdev); | 3630 | put_ldev(device); |
3582 | return -EIO; | 3631 | return -EIO; |
3583 | } | 3632 | } |
3584 | 3633 | ||
@@ -3587,145 +3636,147 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3587 | 3636 | ||
3588 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); | 3637 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
3589 | if (!new_disk_conf) { | 3638 | if (!new_disk_conf) { |
3590 | dev_err(DEV, "Allocation of new disk_conf failed\n"); | 3639 | drbd_err(device, "Allocation of new disk_conf failed\n"); |
3591 | put_ldev(mdev); | 3640 | put_ldev(device); |
3592 | return -ENOMEM; | 3641 | return -ENOMEM; |
3593 | } | 3642 | } |
3594 | 3643 | ||
3595 | mutex_lock(&mdev->tconn->conf_update); | 3644 | mutex_lock(&connection->resource->conf_update); |
3596 | old_disk_conf = mdev->ldev->disk_conf; | 3645 | old_disk_conf = device->ldev->disk_conf; |
3597 | *new_disk_conf = *old_disk_conf; | 3646 | *new_disk_conf = *old_disk_conf; |
3598 | new_disk_conf->disk_size = p_usize; | 3647 | new_disk_conf->disk_size = p_usize; |
3599 | 3648 | ||
3600 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); | 3649 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
3601 | mutex_unlock(&mdev->tconn->conf_update); | 3650 | mutex_unlock(&connection->resource->conf_update); |
3602 | synchronize_rcu(); | 3651 | synchronize_rcu(); |
3603 | kfree(old_disk_conf); | 3652 | kfree(old_disk_conf); |
3604 | 3653 | ||
3605 | dev_info(DEV, "Peer sets u_size to %lu sectors\n", | 3654 | drbd_info(device, "Peer sets u_size to %lu sectors\n", |
3606 | (unsigned long)my_usize); | 3655 | (unsigned long)my_usize); |
3607 | } | 3656 | } |
3608 | 3657 | ||
3609 | put_ldev(mdev); | 3658 | put_ldev(device); |
3610 | } | 3659 | } |
3611 | 3660 | ||
3612 | ddsf = be16_to_cpu(p->dds_flags); | 3661 | ddsf = be16_to_cpu(p->dds_flags); |
3613 | if (get_ldev(mdev)) { | 3662 | if (get_ldev(device)) { |
3614 | dd = drbd_determine_dev_size(mdev, ddsf, NULL); | 3663 | dd = drbd_determine_dev_size(device, ddsf, NULL); |
3615 | put_ldev(mdev); | 3664 | put_ldev(device); |
3616 | if (dd == DS_ERROR) | 3665 | if (dd == DS_ERROR) |
3617 | return -EIO; | 3666 | return -EIO; |
3618 | drbd_md_sync(mdev); | 3667 | drbd_md_sync(device); |
3619 | } else { | 3668 | } else { |
3620 | /* I am diskless, need to accept the peer's size. */ | 3669 | /* I am diskless, need to accept the peer's size. */ |
3621 | drbd_set_my_capacity(mdev, p_size); | 3670 | drbd_set_my_capacity(device, p_size); |
3622 | } | 3671 | } |
3623 | 3672 | ||
3624 | mdev->peer_max_bio_size = be32_to_cpu(p->max_bio_size); | 3673 | device->peer_max_bio_size = be32_to_cpu(p->max_bio_size); |
3625 | drbd_reconsider_max_bio_size(mdev); | 3674 | drbd_reconsider_max_bio_size(device); |
3626 | 3675 | ||
3627 | if (get_ldev(mdev)) { | 3676 | if (get_ldev(device)) { |
3628 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) { | 3677 | if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev)) { |
3629 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); | 3678 | device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev); |
3630 | ldsc = 1; | 3679 | ldsc = 1; |
3631 | } | 3680 | } |
3632 | 3681 | ||
3633 | put_ldev(mdev); | 3682 | put_ldev(device); |
3634 | } | 3683 | } |
3635 | 3684 | ||
3636 | if (mdev->state.conn > C_WF_REPORT_PARAMS) { | 3685 | if (device->state.conn > C_WF_REPORT_PARAMS) { |
3637 | if (be64_to_cpu(p->c_size) != | 3686 | if (be64_to_cpu(p->c_size) != |
3638 | drbd_get_capacity(mdev->this_bdev) || ldsc) { | 3687 | drbd_get_capacity(device->this_bdev) || ldsc) { |
3639 | /* we have different sizes, probably peer | 3688 | /* we have different sizes, probably peer |
3640 | * needs to know my new size... */ | 3689 | * needs to know my new size... */ |
3641 | drbd_send_sizes(mdev, 0, ddsf); | 3690 | drbd_send_sizes(peer_device, 0, ddsf); |
3642 | } | 3691 | } |
3643 | if (test_and_clear_bit(RESIZE_PENDING, &mdev->flags) || | 3692 | if (test_and_clear_bit(RESIZE_PENDING, &device->flags) || |
3644 | (dd == DS_GREW && mdev->state.conn == C_CONNECTED)) { | 3693 | (dd == DS_GREW && device->state.conn == C_CONNECTED)) { |
3645 | if (mdev->state.pdsk >= D_INCONSISTENT && | 3694 | if (device->state.pdsk >= D_INCONSISTENT && |
3646 | mdev->state.disk >= D_INCONSISTENT) { | 3695 | device->state.disk >= D_INCONSISTENT) { |
3647 | if (ddsf & DDSF_NO_RESYNC) | 3696 | if (ddsf & DDSF_NO_RESYNC) |
3648 | dev_info(DEV, "Resync of new storage suppressed with --assume-clean\n"); | 3697 | drbd_info(device, "Resync of new storage suppressed with --assume-clean\n"); |
3649 | else | 3698 | else |
3650 | resync_after_online_grow(mdev); | 3699 | resync_after_online_grow(device); |
3651 | } else | 3700 | } else |
3652 | set_bit(RESYNC_AFTER_NEG, &mdev->flags); | 3701 | set_bit(RESYNC_AFTER_NEG, &device->flags); |
3653 | } | 3702 | } |
3654 | } | 3703 | } |
3655 | 3704 | ||
3656 | return 0; | 3705 | return 0; |
3657 | } | 3706 | } |
3658 | 3707 | ||
3659 | static int receive_uuids(struct drbd_tconn *tconn, struct packet_info *pi) | 3708 | static int receive_uuids(struct drbd_connection *connection, struct packet_info *pi) |
3660 | { | 3709 | { |
3661 | struct drbd_conf *mdev; | 3710 | struct drbd_peer_device *peer_device; |
3711 | struct drbd_device *device; | ||
3662 | struct p_uuids *p = pi->data; | 3712 | struct p_uuids *p = pi->data; |
3663 | u64 *p_uuid; | 3713 | u64 *p_uuid; |
3664 | int i, updated_uuids = 0; | 3714 | int i, updated_uuids = 0; |
3665 | 3715 | ||
3666 | mdev = vnr_to_mdev(tconn, pi->vnr); | 3716 | peer_device = conn_peer_device(connection, pi->vnr); |
3667 | if (!mdev) | 3717 | if (!peer_device) |
3668 | return config_unknown_volume(tconn, pi); | 3718 | return config_unknown_volume(connection, pi); |
3719 | device = peer_device->device; | ||
3669 | 3720 | ||
3670 | p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO); | 3721 | p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO); |
3671 | if (!p_uuid) { | 3722 | if (!p_uuid) { |
3672 | dev_err(DEV, "kmalloc of p_uuid failed\n"); | 3723 | drbd_err(device, "kmalloc of p_uuid failed\n"); |
3673 | return false; | 3724 | return false; |
3674 | } | 3725 | } |
3675 | 3726 | ||
3676 | for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++) | 3727 | for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++) |
3677 | p_uuid[i] = be64_to_cpu(p->uuid[i]); | 3728 | p_uuid[i] = be64_to_cpu(p->uuid[i]); |
3678 | 3729 | ||
3679 | kfree(mdev->p_uuid); | 3730 | kfree(device->p_uuid); |
3680 | mdev->p_uuid = p_uuid; | 3731 | device->p_uuid = p_uuid; |
3681 | 3732 | ||
3682 | if (mdev->state.conn < C_CONNECTED && | 3733 | if (device->state.conn < C_CONNECTED && |
3683 | mdev->state.disk < D_INCONSISTENT && | 3734 | device->state.disk < D_INCONSISTENT && |
3684 | mdev->state.role == R_PRIMARY && | 3735 | device->state.role == R_PRIMARY && |
3685 | (mdev->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { | 3736 | (device->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { |
3686 | dev_err(DEV, "Can only connect to data with current UUID=%016llX\n", | 3737 | drbd_err(device, "Can only connect to data with current UUID=%016llX\n", |
3687 | (unsigned long long)mdev->ed_uuid); | 3738 | (unsigned long long)device->ed_uuid); |
3688 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 3739 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3689 | return -EIO; | 3740 | return -EIO; |
3690 | } | 3741 | } |
3691 | 3742 | ||
3692 | if (get_ldev(mdev)) { | 3743 | if (get_ldev(device)) { |
3693 | int skip_initial_sync = | 3744 | int skip_initial_sync = |
3694 | mdev->state.conn == C_CONNECTED && | 3745 | device->state.conn == C_CONNECTED && |
3695 | mdev->tconn->agreed_pro_version >= 90 && | 3746 | peer_device->connection->agreed_pro_version >= 90 && |
3696 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && | 3747 | device->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && |
3697 | (p_uuid[UI_FLAGS] & 8); | 3748 | (p_uuid[UI_FLAGS] & 8); |
3698 | if (skip_initial_sync) { | 3749 | if (skip_initial_sync) { |
3699 | dev_info(DEV, "Accepted new current UUID, preparing to skip initial sync\n"); | 3750 | drbd_info(device, "Accepted new current UUID, preparing to skip initial sync\n"); |
3700 | drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, | 3751 | drbd_bitmap_io(device, &drbd_bmio_clear_n_write, |
3701 | "clear_n_write from receive_uuids", | 3752 | "clear_n_write from receive_uuids", |
3702 | BM_LOCKED_TEST_ALLOWED); | 3753 | BM_LOCKED_TEST_ALLOWED); |
3703 | _drbd_uuid_set(mdev, UI_CURRENT, p_uuid[UI_CURRENT]); | 3754 | _drbd_uuid_set(device, UI_CURRENT, p_uuid[UI_CURRENT]); |
3704 | _drbd_uuid_set(mdev, UI_BITMAP, 0); | 3755 | _drbd_uuid_set(device, UI_BITMAP, 0); |
3705 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), | 3756 | _drbd_set_state(_NS2(device, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
3706 | CS_VERBOSE, NULL); | 3757 | CS_VERBOSE, NULL); |
3707 | drbd_md_sync(mdev); | 3758 | drbd_md_sync(device); |
3708 | updated_uuids = 1; | 3759 | updated_uuids = 1; |
3709 | } | 3760 | } |
3710 | put_ldev(mdev); | 3761 | put_ldev(device); |
3711 | } else if (mdev->state.disk < D_INCONSISTENT && | 3762 | } else if (device->state.disk < D_INCONSISTENT && |
3712 | mdev->state.role == R_PRIMARY) { | 3763 | device->state.role == R_PRIMARY) { |
3713 | /* I am a diskless primary, the peer just created a new current UUID | 3764 | /* I am a diskless primary, the peer just created a new current UUID |
3714 | for me. */ | 3765 | for me. */ |
3715 | updated_uuids = drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); | 3766 | updated_uuids = drbd_set_ed_uuid(device, p_uuid[UI_CURRENT]); |
3716 | } | 3767 | } |
3717 | 3768 | ||
3718 | /* Before we test for the disk state, we should wait until an eventually | 3769 | /* Before we test for the disk state, we should wait until an eventually |
3719 | ongoing cluster wide state change is finished. That is important if | 3770 | ongoing cluster wide state change is finished. That is important if |
3720 | we are primary and are detaching from our disk. We need to see the | 3771 | we are primary and are detaching from our disk. We need to see the |
3721 | new disk state... */ | 3772 | new disk state... */ |
3722 | mutex_lock(mdev->state_mutex); | 3773 | mutex_lock(device->state_mutex); |
3723 | mutex_unlock(mdev->state_mutex); | 3774 | mutex_unlock(device->state_mutex); |
3724 | if (mdev->state.conn >= C_CONNECTED && mdev->state.disk < D_INCONSISTENT) | 3775 | if (device->state.conn >= C_CONNECTED && device->state.disk < D_INCONSISTENT) |
3725 | updated_uuids |= drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); | 3776 | updated_uuids |= drbd_set_ed_uuid(device, p_uuid[UI_CURRENT]); |
3726 | 3777 | ||
3727 | if (updated_uuids) | 3778 | if (updated_uuids) |
3728 | drbd_print_uuids(mdev, "receiver updated UUIDs to"); | 3779 | drbd_print_uuids(device, "receiver updated UUIDs to"); |
3729 | 3780 | ||
3730 | return 0; | 3781 | return 0; |
3731 | } | 3782 | } |
@@ -3761,38 +3812,40 @@ static union drbd_state convert_state(union drbd_state ps) | |||
3761 | return ms; | 3812 | return ms; |
3762 | } | 3813 | } |
3763 | 3814 | ||
3764 | static int receive_req_state(struct drbd_tconn *tconn, struct packet_info *pi) | 3815 | static int receive_req_state(struct drbd_connection *connection, struct packet_info *pi) |
3765 | { | 3816 | { |
3766 | struct drbd_conf *mdev; | 3817 | struct drbd_peer_device *peer_device; |
3818 | struct drbd_device *device; | ||
3767 | struct p_req_state *p = pi->data; | 3819 | struct p_req_state *p = pi->data; |
3768 | union drbd_state mask, val; | 3820 | union drbd_state mask, val; |
3769 | enum drbd_state_rv rv; | 3821 | enum drbd_state_rv rv; |
3770 | 3822 | ||
3771 | mdev = vnr_to_mdev(tconn, pi->vnr); | 3823 | peer_device = conn_peer_device(connection, pi->vnr); |
3772 | if (!mdev) | 3824 | if (!peer_device) |
3773 | return -EIO; | 3825 | return -EIO; |
3826 | device = peer_device->device; | ||
3774 | 3827 | ||
3775 | mask.i = be32_to_cpu(p->mask); | 3828 | mask.i = be32_to_cpu(p->mask); |
3776 | val.i = be32_to_cpu(p->val); | 3829 | val.i = be32_to_cpu(p->val); |
3777 | 3830 | ||
3778 | if (test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags) && | 3831 | if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) && |
3779 | mutex_is_locked(mdev->state_mutex)) { | 3832 | mutex_is_locked(device->state_mutex)) { |
3780 | drbd_send_sr_reply(mdev, SS_CONCURRENT_ST_CHG); | 3833 | drbd_send_sr_reply(peer_device, SS_CONCURRENT_ST_CHG); |
3781 | return 0; | 3834 | return 0; |
3782 | } | 3835 | } |
3783 | 3836 | ||
3784 | mask = convert_state(mask); | 3837 | mask = convert_state(mask); |
3785 | val = convert_state(val); | 3838 | val = convert_state(val); |
3786 | 3839 | ||
3787 | rv = drbd_change_state(mdev, CS_VERBOSE, mask, val); | 3840 | rv = drbd_change_state(device, CS_VERBOSE, mask, val); |
3788 | drbd_send_sr_reply(mdev, rv); | 3841 | drbd_send_sr_reply(peer_device, rv); |
3789 | 3842 | ||
3790 | drbd_md_sync(mdev); | 3843 | drbd_md_sync(device); |
3791 | 3844 | ||
3792 | return 0; | 3845 | return 0; |
3793 | } | 3846 | } |
3794 | 3847 | ||
3795 | static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info *pi) | 3848 | static int receive_req_conn_state(struct drbd_connection *connection, struct packet_info *pi) |
3796 | { | 3849 | { |
3797 | struct p_req_state *p = pi->data; | 3850 | struct p_req_state *p = pi->data; |
3798 | union drbd_state mask, val; | 3851 | union drbd_state mask, val; |
@@ -3801,46 +3854,48 @@ static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info * | |||
3801 | mask.i = be32_to_cpu(p->mask); | 3854 | mask.i = be32_to_cpu(p->mask); |
3802 | val.i = be32_to_cpu(p->val); | 3855 | val.i = be32_to_cpu(p->val); |
3803 | 3856 | ||
3804 | if (test_bit(RESOLVE_CONFLICTS, &tconn->flags) && | 3857 | if (test_bit(RESOLVE_CONFLICTS, &connection->flags) && |
3805 | mutex_is_locked(&tconn->cstate_mutex)) { | 3858 | mutex_is_locked(&connection->cstate_mutex)) { |
3806 | conn_send_sr_reply(tconn, SS_CONCURRENT_ST_CHG); | 3859 | conn_send_sr_reply(connection, SS_CONCURRENT_ST_CHG); |
3807 | return 0; | 3860 | return 0; |
3808 | } | 3861 | } |
3809 | 3862 | ||
3810 | mask = convert_state(mask); | 3863 | mask = convert_state(mask); |
3811 | val = convert_state(val); | 3864 | val = convert_state(val); |
3812 | 3865 | ||
3813 | rv = conn_request_state(tconn, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL); | 3866 | rv = conn_request_state(connection, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL); |
3814 | conn_send_sr_reply(tconn, rv); | 3867 | conn_send_sr_reply(connection, rv); |
3815 | 3868 | ||
3816 | return 0; | 3869 | return 0; |
3817 | } | 3870 | } |
3818 | 3871 | ||
3819 | static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | 3872 | static int receive_state(struct drbd_connection *connection, struct packet_info *pi) |
3820 | { | 3873 | { |
3821 | struct drbd_conf *mdev; | 3874 | struct drbd_peer_device *peer_device; |
3875 | struct drbd_device *device; | ||
3822 | struct p_state *p = pi->data; | 3876 | struct p_state *p = pi->data; |
3823 | union drbd_state os, ns, peer_state; | 3877 | union drbd_state os, ns, peer_state; |
3824 | enum drbd_disk_state real_peer_disk; | 3878 | enum drbd_disk_state real_peer_disk; |
3825 | enum chg_state_flags cs_flags; | 3879 | enum chg_state_flags cs_flags; |
3826 | int rv; | 3880 | int rv; |
3827 | 3881 | ||
3828 | mdev = vnr_to_mdev(tconn, pi->vnr); | 3882 | peer_device = conn_peer_device(connection, pi->vnr); |
3829 | if (!mdev) | 3883 | if (!peer_device) |
3830 | return config_unknown_volume(tconn, pi); | 3884 | return config_unknown_volume(connection, pi); |
3885 | device = peer_device->device; | ||
3831 | 3886 | ||
3832 | peer_state.i = be32_to_cpu(p->state); | 3887 | peer_state.i = be32_to_cpu(p->state); |
3833 | 3888 | ||
3834 | real_peer_disk = peer_state.disk; | 3889 | real_peer_disk = peer_state.disk; |
3835 | if (peer_state.disk == D_NEGOTIATING) { | 3890 | if (peer_state.disk == D_NEGOTIATING) { |
3836 | real_peer_disk = mdev->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; | 3891 | real_peer_disk = device->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; |
3837 | dev_info(DEV, "real peer disk state = %s\n", drbd_disk_str(real_peer_disk)); | 3892 | drbd_info(device, "real peer disk state = %s\n", drbd_disk_str(real_peer_disk)); |
3838 | } | 3893 | } |
3839 | 3894 | ||
3840 | spin_lock_irq(&mdev->tconn->req_lock); | 3895 | spin_lock_irq(&device->resource->req_lock); |
3841 | retry: | 3896 | retry: |
3842 | os = ns = drbd_read_state(mdev); | 3897 | os = ns = drbd_read_state(device); |
3843 | spin_unlock_irq(&mdev->tconn->req_lock); | 3898 | spin_unlock_irq(&device->resource->req_lock); |
3844 | 3899 | ||
3845 | /* If some other part of the code (asender thread, timeout) | 3900 | /* If some other part of the code (asender thread, timeout) |
3846 | * already decided to close the connection again, | 3901 | * already decided to close the connection again, |
@@ -3872,8 +3927,8 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3872 | * Maybe we should finish it up, too? */ | 3927 | * Maybe we should finish it up, too? */ |
3873 | else if (os.conn >= C_SYNC_SOURCE && | 3928 | else if (os.conn >= C_SYNC_SOURCE && |
3874 | peer_state.conn == C_CONNECTED) { | 3929 | peer_state.conn == C_CONNECTED) { |
3875 | if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) | 3930 | if (drbd_bm_total_weight(device) <= device->rs_failed) |
3876 | drbd_resync_finished(mdev); | 3931 | drbd_resync_finished(device); |
3877 | return 0; | 3932 | return 0; |
3878 | } | 3933 | } |
3879 | } | 3934 | } |
@@ -3881,8 +3936,8 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3881 | /* explicit verify finished notification, stop sector reached. */ | 3936 | /* explicit verify finished notification, stop sector reached. */ |
3882 | if (os.conn == C_VERIFY_T && os.disk == D_UP_TO_DATE && | 3937 | if (os.conn == C_VERIFY_T && os.disk == D_UP_TO_DATE && |
3883 | peer_state.conn == C_CONNECTED && real_peer_disk == D_UP_TO_DATE) { | 3938 | peer_state.conn == C_CONNECTED && real_peer_disk == D_UP_TO_DATE) { |
3884 | ov_out_of_sync_print(mdev); | 3939 | ov_out_of_sync_print(device); |
3885 | drbd_resync_finished(mdev); | 3940 | drbd_resync_finished(device); |
3886 | return 0; | 3941 | return 0; |
3887 | } | 3942 | } |
3888 | 3943 | ||
@@ -3901,8 +3956,8 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3901 | if (peer_state.conn == C_AHEAD) | 3956 | if (peer_state.conn == C_AHEAD) |
3902 | ns.conn = C_BEHIND; | 3957 | ns.conn = C_BEHIND; |
3903 | 3958 | ||
3904 | if (mdev->p_uuid && peer_state.disk >= D_NEGOTIATING && | 3959 | if (device->p_uuid && peer_state.disk >= D_NEGOTIATING && |
3905 | get_ldev_if_state(mdev, D_NEGOTIATING)) { | 3960 | get_ldev_if_state(device, D_NEGOTIATING)) { |
3906 | int cr; /* consider resync */ | 3961 | int cr; /* consider resync */ |
3907 | 3962 | ||
3908 | /* if we established a new connection */ | 3963 | /* if we established a new connection */ |
@@ -3914,7 +3969,7 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3914 | os.disk == D_NEGOTIATING)); | 3969 | os.disk == D_NEGOTIATING)); |
3915 | /* if we have both been inconsistent, and the peer has been | 3970 | /* if we have both been inconsistent, and the peer has been |
3916 | * forced to be UpToDate with --overwrite-data */ | 3971 | * forced to be UpToDate with --overwrite-data */ |
3917 | cr |= test_bit(CONSIDER_RESYNC, &mdev->flags); | 3972 | cr |= test_bit(CONSIDER_RESYNC, &device->flags); |
3918 | /* if we had been plain connected, and the admin requested to | 3973 | /* if we had been plain connected, and the admin requested to |
3919 | * start a sync by "invalidate" or "invalidate-remote" */ | 3974 | * start a sync by "invalidate" or "invalidate-remote" */ |
3920 | cr |= (os.conn == C_CONNECTED && | 3975 | cr |= (os.conn == C_CONNECTED && |
@@ -3922,55 +3977,55 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3922 | peer_state.conn <= C_WF_BITMAP_T)); | 3977 | peer_state.conn <= C_WF_BITMAP_T)); |
3923 | 3978 | ||
3924 | if (cr) | 3979 | if (cr) |
3925 | ns.conn = drbd_sync_handshake(mdev, peer_state.role, real_peer_disk); | 3980 | ns.conn = drbd_sync_handshake(peer_device, peer_state.role, real_peer_disk); |
3926 | 3981 | ||
3927 | put_ldev(mdev); | 3982 | put_ldev(device); |
3928 | if (ns.conn == C_MASK) { | 3983 | if (ns.conn == C_MASK) { |
3929 | ns.conn = C_CONNECTED; | 3984 | ns.conn = C_CONNECTED; |
3930 | if (mdev->state.disk == D_NEGOTIATING) { | 3985 | if (device->state.disk == D_NEGOTIATING) { |
3931 | drbd_force_state(mdev, NS(disk, D_FAILED)); | 3986 | drbd_force_state(device, NS(disk, D_FAILED)); |
3932 | } else if (peer_state.disk == D_NEGOTIATING) { | 3987 | } else if (peer_state.disk == D_NEGOTIATING) { |
3933 | dev_err(DEV, "Disk attach process on the peer node was aborted.\n"); | 3988 | drbd_err(device, "Disk attach process on the peer node was aborted.\n"); |
3934 | peer_state.disk = D_DISKLESS; | 3989 | peer_state.disk = D_DISKLESS; |
3935 | real_peer_disk = D_DISKLESS; | 3990 | real_peer_disk = D_DISKLESS; |
3936 | } else { | 3991 | } else { |
3937 | if (test_and_clear_bit(CONN_DRY_RUN, &mdev->tconn->flags)) | 3992 | if (test_and_clear_bit(CONN_DRY_RUN, &peer_device->connection->flags)) |
3938 | return -EIO; | 3993 | return -EIO; |
3939 | D_ASSERT(os.conn == C_WF_REPORT_PARAMS); | 3994 | D_ASSERT(device, os.conn == C_WF_REPORT_PARAMS); |
3940 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 3995 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3941 | return -EIO; | 3996 | return -EIO; |
3942 | } | 3997 | } |
3943 | } | 3998 | } |
3944 | } | 3999 | } |
3945 | 4000 | ||
3946 | spin_lock_irq(&mdev->tconn->req_lock); | 4001 | spin_lock_irq(&device->resource->req_lock); |
3947 | if (os.i != drbd_read_state(mdev).i) | 4002 | if (os.i != drbd_read_state(device).i) |
3948 | goto retry; | 4003 | goto retry; |
3949 | clear_bit(CONSIDER_RESYNC, &mdev->flags); | 4004 | clear_bit(CONSIDER_RESYNC, &device->flags); |
3950 | ns.peer = peer_state.role; | 4005 | ns.peer = peer_state.role; |
3951 | ns.pdsk = real_peer_disk; | 4006 | ns.pdsk = real_peer_disk; |
3952 | ns.peer_isp = (peer_state.aftr_isp | peer_state.user_isp); | 4007 | ns.peer_isp = (peer_state.aftr_isp | peer_state.user_isp); |
3953 | if ((ns.conn == C_CONNECTED || ns.conn == C_WF_BITMAP_S) && ns.disk == D_NEGOTIATING) | 4008 | if ((ns.conn == C_CONNECTED || ns.conn == C_WF_BITMAP_S) && ns.disk == D_NEGOTIATING) |
3954 | ns.disk = mdev->new_state_tmp.disk; | 4009 | ns.disk = device->new_state_tmp.disk; |
3955 | cs_flags = CS_VERBOSE + (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED ? 0 : CS_HARD); | 4010 | cs_flags = CS_VERBOSE + (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED ? 0 : CS_HARD); |
3956 | if (ns.pdsk == D_CONSISTENT && drbd_suspended(mdev) && ns.conn == C_CONNECTED && os.conn < C_CONNECTED && | 4011 | if (ns.pdsk == D_CONSISTENT && drbd_suspended(device) && ns.conn == C_CONNECTED && os.conn < C_CONNECTED && |
3957 | test_bit(NEW_CUR_UUID, &mdev->flags)) { | 4012 | test_bit(NEW_CUR_UUID, &device->flags)) { |
3958 | /* Do not allow tl_restart(RESEND) for a rebooted peer. We can only allow this | 4013 | /* Do not allow tl_restart(RESEND) for a rebooted peer. We can only allow this |
3959 | for temporal network outages! */ | 4014 | for temporal network outages! */ |
3960 | spin_unlock_irq(&mdev->tconn->req_lock); | 4015 | spin_unlock_irq(&device->resource->req_lock); |
3961 | dev_err(DEV, "Aborting Connect, can not thaw IO with an only Consistent peer\n"); | 4016 | drbd_err(device, "Aborting Connect, can not thaw IO with an only Consistent peer\n"); |
3962 | tl_clear(mdev->tconn); | 4017 | tl_clear(peer_device->connection); |
3963 | drbd_uuid_new_current(mdev); | 4018 | drbd_uuid_new_current(device); |
3964 | clear_bit(NEW_CUR_UUID, &mdev->flags); | 4019 | clear_bit(NEW_CUR_UUID, &device->flags); |
3965 | conn_request_state(mdev->tconn, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); | 4020 | conn_request_state(peer_device->connection, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); |
3966 | return -EIO; | 4021 | return -EIO; |
3967 | } | 4022 | } |
3968 | rv = _drbd_set_state(mdev, ns, cs_flags, NULL); | 4023 | rv = _drbd_set_state(device, ns, cs_flags, NULL); |
3969 | ns = drbd_read_state(mdev); | 4024 | ns = drbd_read_state(device); |
3970 | spin_unlock_irq(&mdev->tconn->req_lock); | 4025 | spin_unlock_irq(&device->resource->req_lock); |
3971 | 4026 | ||
3972 | if (rv < SS_SUCCESS) { | 4027 | if (rv < SS_SUCCESS) { |
3973 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 4028 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
3974 | return -EIO; | 4029 | return -EIO; |
3975 | } | 4030 | } |
3976 | 4031 | ||
@@ -3980,47 +4035,49 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) | |||
3980 | /* we want resync, peer has not yet decided to sync... */ | 4035 | /* we want resync, peer has not yet decided to sync... */ |
3981 | /* Nowadays only used when forcing a node into primary role and | 4036 | /* Nowadays only used when forcing a node into primary role and |
3982 | setting its disk to UpToDate with that */ | 4037 | setting its disk to UpToDate with that */ |
3983 | drbd_send_uuids(mdev); | 4038 | drbd_send_uuids(peer_device); |
3984 | drbd_send_current_state(mdev); | 4039 | drbd_send_current_state(peer_device); |
3985 | } | 4040 | } |
3986 | } | 4041 | } |
3987 | 4042 | ||
3988 | clear_bit(DISCARD_MY_DATA, &mdev->flags); | 4043 | clear_bit(DISCARD_MY_DATA, &device->flags); |
3989 | 4044 | ||
3990 | drbd_md_sync(mdev); /* update connected indicator, la_size_sect, ... */ | 4045 | drbd_md_sync(device); /* update connected indicator, la_size_sect, ... */ |
3991 | 4046 | ||
3992 | return 0; | 4047 | return 0; |
3993 | } | 4048 | } |
3994 | 4049 | ||
3995 | static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi) | 4050 | static int receive_sync_uuid(struct drbd_connection *connection, struct packet_info *pi) |
3996 | { | 4051 | { |
3997 | struct drbd_conf *mdev; | 4052 | struct drbd_peer_device *peer_device; |
4053 | struct drbd_device *device; | ||
3998 | struct p_rs_uuid *p = pi->data; | 4054 | struct p_rs_uuid *p = pi->data; |
3999 | 4055 | ||
4000 | mdev = vnr_to_mdev(tconn, pi->vnr); | 4056 | peer_device = conn_peer_device(connection, pi->vnr); |
4001 | if (!mdev) | 4057 | if (!peer_device) |
4002 | return -EIO; | 4058 | return -EIO; |
4059 | device = peer_device->device; | ||
4003 | 4060 | ||
4004 | wait_event(mdev->misc_wait, | 4061 | wait_event(device->misc_wait, |
4005 | mdev->state.conn == C_WF_SYNC_UUID || | 4062 | device->state.conn == C_WF_SYNC_UUID || |
4006 | mdev->state.conn == C_BEHIND || | 4063 | device->state.conn == C_BEHIND || |
4007 | mdev->state.conn < C_CONNECTED || | 4064 | device->state.conn < C_CONNECTED || |
4008 | mdev->state.disk < D_NEGOTIATING); | 4065 | device->state.disk < D_NEGOTIATING); |
4009 | 4066 | ||
4010 | /* D_ASSERT( mdev->state.conn == C_WF_SYNC_UUID ); */ | 4067 | /* D_ASSERT(device, device->state.conn == C_WF_SYNC_UUID ); */ |
4011 | 4068 | ||
4012 | /* Here the _drbd_uuid_ functions are right, current should | 4069 | /* Here the _drbd_uuid_ functions are right, current should |
4013 | _not_ be rotated into the history */ | 4070 | _not_ be rotated into the history */ |
4014 | if (get_ldev_if_state(mdev, D_NEGOTIATING)) { | 4071 | if (get_ldev_if_state(device, D_NEGOTIATING)) { |
4015 | _drbd_uuid_set(mdev, UI_CURRENT, be64_to_cpu(p->uuid)); | 4072 | _drbd_uuid_set(device, UI_CURRENT, be64_to_cpu(p->uuid)); |
4016 | _drbd_uuid_set(mdev, UI_BITMAP, 0UL); | 4073 | _drbd_uuid_set(device, UI_BITMAP, 0UL); |
4017 | 4074 | ||
4018 | drbd_print_uuids(mdev, "updated sync uuid"); | 4075 | drbd_print_uuids(device, "updated sync uuid"); |
4019 | drbd_start_resync(mdev, C_SYNC_TARGET); | 4076 | drbd_start_resync(device, C_SYNC_TARGET); |
4020 | 4077 | ||
4021 | put_ldev(mdev); | 4078 | put_ldev(device); |
4022 | } else | 4079 | } else |
4023 | dev_err(DEV, "Ignoring SyncUUID packet!\n"); | 4080 | drbd_err(device, "Ignoring SyncUUID packet!\n"); |
4024 | 4081 | ||
4025 | return 0; | 4082 | return 0; |
4026 | } | 4083 | } |
@@ -4032,27 +4089,27 @@ static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi) | |||
4032 | * code upon failure. | 4089 | * code upon failure. |
4033 | */ | 4090 | */ |
4034 | static int | 4091 | static int |
4035 | receive_bitmap_plain(struct drbd_conf *mdev, unsigned int size, | 4092 | receive_bitmap_plain(struct drbd_peer_device *peer_device, unsigned int size, |
4036 | unsigned long *p, struct bm_xfer_ctx *c) | 4093 | unsigned long *p, struct bm_xfer_ctx *c) |
4037 | { | 4094 | { |
4038 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - | 4095 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - |
4039 | drbd_header_size(mdev->tconn); | 4096 | drbd_header_size(peer_device->connection); |
4040 | unsigned int num_words = min_t(size_t, data_size / sizeof(*p), | 4097 | unsigned int num_words = min_t(size_t, data_size / sizeof(*p), |
4041 | c->bm_words - c->word_offset); | 4098 | c->bm_words - c->word_offset); |
4042 | unsigned int want = num_words * sizeof(*p); | 4099 | unsigned int want = num_words * sizeof(*p); |
4043 | int err; | 4100 | int err; |
4044 | 4101 | ||
4045 | if (want != size) { | 4102 | if (want != size) { |
4046 | dev_err(DEV, "%s:want (%u) != size (%u)\n", __func__, want, size); | 4103 | drbd_err(peer_device, "%s:want (%u) != size (%u)\n", __func__, want, size); |
4047 | return -EIO; | 4104 | return -EIO; |
4048 | } | 4105 | } |
4049 | if (want == 0) | 4106 | if (want == 0) |
4050 | return 0; | 4107 | return 0; |
4051 | err = drbd_recv_all(mdev->tconn, p, want); | 4108 | err = drbd_recv_all(peer_device->connection, p, want); |
4052 | if (err) | 4109 | if (err) |
4053 | return err; | 4110 | return err; |
4054 | 4111 | ||
4055 | drbd_bm_merge_lel(mdev, c->word_offset, num_words, p); | 4112 | drbd_bm_merge_lel(peer_device->device, c->word_offset, num_words, p); |
4056 | 4113 | ||
4057 | c->word_offset += num_words; | 4114 | c->word_offset += num_words; |
4058 | c->bit_offset = c->word_offset * BITS_PER_LONG; | 4115 | c->bit_offset = c->word_offset * BITS_PER_LONG; |
@@ -4084,7 +4141,7 @@ static int dcbp_get_pad_bits(struct p_compressed_bm *p) | |||
4084 | * code upon failure. | 4141 | * code upon failure. |
4085 | */ | 4142 | */ |
4086 | static int | 4143 | static int |
4087 | recv_bm_rle_bits(struct drbd_conf *mdev, | 4144 | recv_bm_rle_bits(struct drbd_peer_device *peer_device, |
4088 | struct p_compressed_bm *p, | 4145 | struct p_compressed_bm *p, |
4089 | struct bm_xfer_ctx *c, | 4146 | struct bm_xfer_ctx *c, |
4090 | unsigned int len) | 4147 | unsigned int len) |
@@ -4113,14 +4170,14 @@ recv_bm_rle_bits(struct drbd_conf *mdev, | |||
4113 | if (toggle) { | 4170 | if (toggle) { |
4114 | e = s + rl -1; | 4171 | e = s + rl -1; |
4115 | if (e >= c->bm_bits) { | 4172 | if (e >= c->bm_bits) { |
4116 | dev_err(DEV, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e); | 4173 | drbd_err(peer_device, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e); |
4117 | return -EIO; | 4174 | return -EIO; |
4118 | } | 4175 | } |
4119 | _drbd_bm_set_bits(mdev, s, e); | 4176 | _drbd_bm_set_bits(peer_device->device, s, e); |
4120 | } | 4177 | } |
4121 | 4178 | ||
4122 | if (have < bits) { | 4179 | if (have < bits) { |
4123 | dev_err(DEV, "bitmap decoding error: h:%d b:%d la:0x%08llx l:%u/%u\n", | 4180 | drbd_err(peer_device, "bitmap decoding error: h:%d b:%d la:0x%08llx l:%u/%u\n", |
4124 | have, bits, look_ahead, | 4181 | have, bits, look_ahead, |
4125 | (unsigned int)(bs.cur.b - p->code), | 4182 | (unsigned int)(bs.cur.b - p->code), |
4126 | (unsigned int)bs.buf_len); | 4183 | (unsigned int)bs.buf_len); |
@@ -4153,28 +4210,28 @@ recv_bm_rle_bits(struct drbd_conf *mdev, | |||
4153 | * code upon failure. | 4210 | * code upon failure. |
4154 | */ | 4211 | */ |
4155 | static int | 4212 | static int |
4156 | decode_bitmap_c(struct drbd_conf *mdev, | 4213 | decode_bitmap_c(struct drbd_peer_device *peer_device, |
4157 | struct p_compressed_bm *p, | 4214 | struct p_compressed_bm *p, |
4158 | struct bm_xfer_ctx *c, | 4215 | struct bm_xfer_ctx *c, |
4159 | unsigned int len) | 4216 | unsigned int len) |
4160 | { | 4217 | { |
4161 | if (dcbp_get_code(p) == RLE_VLI_Bits) | 4218 | if (dcbp_get_code(p) == RLE_VLI_Bits) |
4162 | return recv_bm_rle_bits(mdev, p, c, len - sizeof(*p)); | 4219 | return recv_bm_rle_bits(peer_device, p, c, len - sizeof(*p)); |
4163 | 4220 | ||
4164 | /* other variants had been implemented for evaluation, | 4221 | /* other variants had been implemented for evaluation, |
4165 | * but have been dropped as this one turned out to be "best" | 4222 | * but have been dropped as this one turned out to be "best" |
4166 | * during all our tests. */ | 4223 | * during all our tests. */ |
4167 | 4224 | ||
4168 | dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding); | 4225 | drbd_err(peer_device, "receive_bitmap_c: unknown encoding %u\n", p->encoding); |
4169 | conn_request_state(mdev->tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); | 4226 | conn_request_state(peer_device->connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
4170 | return -EIO; | 4227 | return -EIO; |
4171 | } | 4228 | } |
4172 | 4229 | ||
4173 | void INFO_bm_xfer_stats(struct drbd_conf *mdev, | 4230 | void INFO_bm_xfer_stats(struct drbd_device *device, |
4174 | const char *direction, struct bm_xfer_ctx *c) | 4231 | const char *direction, struct bm_xfer_ctx *c) |
4175 | { | 4232 | { |
4176 | /* what would it take to transfer it "plaintext" */ | 4233 | /* what would it take to transfer it "plaintext" */ |
4177 | unsigned int header_size = drbd_header_size(mdev->tconn); | 4234 | unsigned int header_size = drbd_header_size(first_peer_device(device)->connection); |
4178 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; | 4235 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; |
4179 | unsigned int plain = | 4236 | unsigned int plain = |
4180 | header_size * (DIV_ROUND_UP(c->bm_words, data_size) + 1) + | 4237 | header_size * (DIV_ROUND_UP(c->bm_words, data_size) + 1) + |
@@ -4198,7 +4255,7 @@ void INFO_bm_xfer_stats(struct drbd_conf *mdev, | |||
4198 | r = 1000; | 4255 | r = 1000; |
4199 | 4256 | ||
4200 | r = 1000 - r; | 4257 | r = 1000 - r; |
4201 | dev_info(DEV, "%s bitmap stats [Bytes(packets)]: plain %u(%u), RLE %u(%u), " | 4258 | drbd_info(device, "%s bitmap stats [Bytes(packets)]: plain %u(%u), RLE %u(%u), " |
4202 | "total %u; compression: %u.%u%%\n", | 4259 | "total %u; compression: %u.%u%%\n", |
4203 | direction, | 4260 | direction, |
4204 | c->bytes[1], c->packets[1], | 4261 | c->bytes[1], c->packets[1], |
@@ -4214,129 +4271,133 @@ void INFO_bm_xfer_stats(struct drbd_conf *mdev, | |||
4214 | in order to be agnostic to the 32 vs 64 bits issue. | 4271 | in order to be agnostic to the 32 vs 64 bits issue. |
4215 | 4272 | ||
4216 | returns 0 on failure, 1 if we successfully received it. */ | 4273 | returns 0 on failure, 1 if we successfully received it. */ |
4217 | static int receive_bitmap(struct drbd_tconn *tconn, struct packet_info *pi) | 4274 | static int receive_bitmap(struct drbd_connection *connection, struct packet_info *pi) |
4218 | { | 4275 | { |
4219 | struct drbd_conf *mdev; | 4276 | struct drbd_peer_device *peer_device; |
4277 | struct drbd_device *device; | ||
4220 | struct bm_xfer_ctx c; | 4278 | struct bm_xfer_ctx c; |
4221 | int err; | 4279 | int err; |
4222 | 4280 | ||
4223 | mdev = vnr_to_mdev(tconn, pi->vnr); | 4281 | peer_device = conn_peer_device(connection, pi->vnr); |
4224 | if (!mdev) | 4282 | if (!peer_device) |
4225 | return -EIO; | 4283 | return -EIO; |
4284 | device = peer_device->device; | ||
4226 | 4285 | ||
4227 | drbd_bm_lock(mdev, "receive bitmap", BM_LOCKED_SET_ALLOWED); | 4286 | drbd_bm_lock(device, "receive bitmap", BM_LOCKED_SET_ALLOWED); |
4228 | /* you are supposed to send additional out-of-sync information | 4287 | /* you are supposed to send additional out-of-sync information |
4229 | * if you actually set bits during this phase */ | 4288 | * if you actually set bits during this phase */ |
4230 | 4289 | ||
4231 | c = (struct bm_xfer_ctx) { | 4290 | c = (struct bm_xfer_ctx) { |
4232 | .bm_bits = drbd_bm_bits(mdev), | 4291 | .bm_bits = drbd_bm_bits(device), |
4233 | .bm_words = drbd_bm_words(mdev), | 4292 | .bm_words = drbd_bm_words(device), |
4234 | }; | 4293 | }; |
4235 | 4294 | ||
4236 | for(;;) { | 4295 | for(;;) { |
4237 | if (pi->cmd == P_BITMAP) | 4296 | if (pi->cmd == P_BITMAP) |
4238 | err = receive_bitmap_plain(mdev, pi->size, pi->data, &c); | 4297 | err = receive_bitmap_plain(peer_device, pi->size, pi->data, &c); |
4239 | else if (pi->cmd == P_COMPRESSED_BITMAP) { | 4298 | else if (pi->cmd == P_COMPRESSED_BITMAP) { |
4240 | /* MAYBE: sanity check that we speak proto >= 90, | 4299 | /* MAYBE: sanity check that we speak proto >= 90, |
4241 | * and the feature is enabled! */ | 4300 | * and the feature is enabled! */ |
4242 | struct p_compressed_bm *p = pi->data; | 4301 | struct p_compressed_bm *p = pi->data; |
4243 | 4302 | ||
4244 | if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(tconn)) { | 4303 | if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(connection)) { |
4245 | dev_err(DEV, "ReportCBitmap packet too large\n"); | 4304 | drbd_err(device, "ReportCBitmap packet too large\n"); |
4246 | err = -EIO; | 4305 | err = -EIO; |
4247 | goto out; | 4306 | goto out; |
4248 | } | 4307 | } |
4249 | if (pi->size <= sizeof(*p)) { | 4308 | if (pi->size <= sizeof(*p)) { |
4250 | dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", pi->size); | 4309 | drbd_err(device, "ReportCBitmap packet too small (l:%u)\n", pi->size); |
4251 | err = -EIO; | 4310 | err = -EIO; |
4252 | goto out; | 4311 | goto out; |
4253 | } | 4312 | } |
4254 | err = drbd_recv_all(mdev->tconn, p, pi->size); | 4313 | err = drbd_recv_all(peer_device->connection, p, pi->size); |
4255 | if (err) | 4314 | if (err) |
4256 | goto out; | 4315 | goto out; |
4257 | err = decode_bitmap_c(mdev, p, &c, pi->size); | 4316 | err = decode_bitmap_c(peer_device, p, &c, pi->size); |
4258 | } else { | 4317 | } else { |
4259 | dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); | 4318 | drbd_warn(device, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); |
4260 | err = -EIO; | 4319 | err = -EIO; |
4261 | goto out; | 4320 | goto out; |
4262 | } | 4321 | } |
4263 | 4322 | ||
4264 | c.packets[pi->cmd == P_BITMAP]++; | 4323 | c.packets[pi->cmd == P_BITMAP]++; |
4265 | c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(tconn) + pi->size; | 4324 | c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(connection) + pi->size; |
4266 | 4325 | ||
4267 | if (err <= 0) { | 4326 | if (err <= 0) { |
4268 | if (err < 0) | 4327 | if (err < 0) |
4269 | goto out; | 4328 | goto out; |
4270 | break; | 4329 | break; |
4271 | } | 4330 | } |
4272 | err = drbd_recv_header(mdev->tconn, pi); | 4331 | err = drbd_recv_header(peer_device->connection, pi); |
4273 | if (err) | 4332 | if (err) |
4274 | goto out; | 4333 | goto out; |
4275 | } | 4334 | } |
4276 | 4335 | ||
4277 | INFO_bm_xfer_stats(mdev, "receive", &c); | 4336 | INFO_bm_xfer_stats(device, "receive", &c); |
4278 | 4337 | ||
4279 | if (mdev->state.conn == C_WF_BITMAP_T) { | 4338 | if (device->state.conn == C_WF_BITMAP_T) { |
4280 | enum drbd_state_rv rv; | 4339 | enum drbd_state_rv rv; |
4281 | 4340 | ||
4282 | err = drbd_send_bitmap(mdev); | 4341 | err = drbd_send_bitmap(device); |
4283 | if (err) | 4342 | if (err) |
4284 | goto out; | 4343 | goto out; |
4285 | /* Omit CS_ORDERED with this state transition to avoid deadlocks. */ | 4344 | /* Omit CS_ORDERED with this state transition to avoid deadlocks. */ |
4286 | rv = _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); | 4345 | rv = _drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
4287 | D_ASSERT(rv == SS_SUCCESS); | 4346 | D_ASSERT(device, rv == SS_SUCCESS); |
4288 | } else if (mdev->state.conn != C_WF_BITMAP_S) { | 4347 | } else if (device->state.conn != C_WF_BITMAP_S) { |
4289 | /* admin may have requested C_DISCONNECTING, | 4348 | /* admin may have requested C_DISCONNECTING, |
4290 | * other threads may have noticed network errors */ | 4349 | * other threads may have noticed network errors */ |
4291 | dev_info(DEV, "unexpected cstate (%s) in receive_bitmap\n", | 4350 | drbd_info(device, "unexpected cstate (%s) in receive_bitmap\n", |
4292 | drbd_conn_str(mdev->state.conn)); | 4351 | drbd_conn_str(device->state.conn)); |
4293 | } | 4352 | } |
4294 | err = 0; | 4353 | err = 0; |
4295 | 4354 | ||
4296 | out: | 4355 | out: |
4297 | drbd_bm_unlock(mdev); | 4356 | drbd_bm_unlock(device); |
4298 | if (!err && mdev->state.conn == C_WF_BITMAP_S) | 4357 | if (!err && device->state.conn == C_WF_BITMAP_S) |
4299 | drbd_start_resync(mdev, C_SYNC_SOURCE); | 4358 | drbd_start_resync(device, C_SYNC_SOURCE); |
4300 | return err; | 4359 | return err; |
4301 | } | 4360 | } |
4302 | 4361 | ||
4303 | static int receive_skip(struct drbd_tconn *tconn, struct packet_info *pi) | 4362 | static int receive_skip(struct drbd_connection *connection, struct packet_info *pi) |
4304 | { | 4363 | { |
4305 | conn_warn(tconn, "skipping unknown optional packet type %d, l: %d!\n", | 4364 | drbd_warn(connection, "skipping unknown optional packet type %d, l: %d!\n", |
4306 | pi->cmd, pi->size); | 4365 | pi->cmd, pi->size); |
4307 | 4366 | ||
4308 | return ignore_remaining_packet(tconn, pi); | 4367 | return ignore_remaining_packet(connection, pi); |
4309 | } | 4368 | } |
4310 | 4369 | ||
4311 | static int receive_UnplugRemote(struct drbd_tconn *tconn, struct packet_info *pi) | 4370 | static int receive_UnplugRemote(struct drbd_connection *connection, struct packet_info *pi) |
4312 | { | 4371 | { |
4313 | /* Make sure we've acked all the TCP data associated | 4372 | /* Make sure we've acked all the TCP data associated |
4314 | * with the data requests being unplugged */ | 4373 | * with the data requests being unplugged */ |
4315 | drbd_tcp_quickack(tconn->data.socket); | 4374 | drbd_tcp_quickack(connection->data.socket); |
4316 | 4375 | ||
4317 | return 0; | 4376 | return 0; |
4318 | } | 4377 | } |
4319 | 4378 | ||
4320 | static int receive_out_of_sync(struct drbd_tconn *tconn, struct packet_info *pi) | 4379 | static int receive_out_of_sync(struct drbd_connection *connection, struct packet_info *pi) |
4321 | { | 4380 | { |
4322 | struct drbd_conf *mdev; | 4381 | struct drbd_peer_device *peer_device; |
4382 | struct drbd_device *device; | ||
4323 | struct p_block_desc *p = pi->data; | 4383 | struct p_block_desc *p = pi->data; |
4324 | 4384 | ||
4325 | mdev = vnr_to_mdev(tconn, pi->vnr); | 4385 | peer_device = conn_peer_device(connection, pi->vnr); |
4326 | if (!mdev) | 4386 | if (!peer_device) |
4327 | return -EIO; | 4387 | return -EIO; |
4388 | device = peer_device->device; | ||
4328 | 4389 | ||
4329 | switch (mdev->state.conn) { | 4390 | switch (device->state.conn) { |
4330 | case C_WF_SYNC_UUID: | 4391 | case C_WF_SYNC_UUID: |
4331 | case C_WF_BITMAP_T: | 4392 | case C_WF_BITMAP_T: |
4332 | case C_BEHIND: | 4393 | case C_BEHIND: |
4333 | break; | 4394 | break; |
4334 | default: | 4395 | default: |
4335 | dev_err(DEV, "ASSERT FAILED cstate = %s, expected: WFSyncUUID|WFBitMapT|Behind\n", | 4396 | drbd_err(device, "ASSERT FAILED cstate = %s, expected: WFSyncUUID|WFBitMapT|Behind\n", |
4336 | drbd_conn_str(mdev->state.conn)); | 4397 | drbd_conn_str(device->state.conn)); |
4337 | } | 4398 | } |
4338 | 4399 | ||
4339 | drbd_set_out_of_sync(mdev, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); | 4400 | drbd_set_out_of_sync(device, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); |
4340 | 4401 | ||
4341 | return 0; | 4402 | return 0; |
4342 | } | 4403 | } |
@@ -4344,7 +4405,7 @@ static int receive_out_of_sync(struct drbd_tconn *tconn, struct packet_info *pi) | |||
4344 | struct data_cmd { | 4405 | struct data_cmd { |
4345 | int expect_payload; | 4406 | int expect_payload; |
4346 | size_t pkt_size; | 4407 | size_t pkt_size; |
4347 | int (*fn)(struct drbd_tconn *, struct packet_info *); | 4408 | int (*fn)(struct drbd_connection *, struct packet_info *); |
4348 | }; | 4409 | }; |
4349 | 4410 | ||
4350 | static struct data_cmd drbd_cmd_handler[] = { | 4411 | static struct data_cmd drbd_cmd_handler[] = { |
@@ -4374,43 +4435,43 @@ static struct data_cmd drbd_cmd_handler[] = { | |||
4374 | [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol }, | 4435 | [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol }, |
4375 | }; | 4436 | }; |
4376 | 4437 | ||
4377 | static void drbdd(struct drbd_tconn *tconn) | 4438 | static void drbdd(struct drbd_connection *connection) |
4378 | { | 4439 | { |
4379 | struct packet_info pi; | 4440 | struct packet_info pi; |
4380 | size_t shs; /* sub header size */ | 4441 | size_t shs; /* sub header size */ |
4381 | int err; | 4442 | int err; |
4382 | 4443 | ||
4383 | while (get_t_state(&tconn->receiver) == RUNNING) { | 4444 | while (get_t_state(&connection->receiver) == RUNNING) { |
4384 | struct data_cmd *cmd; | 4445 | struct data_cmd *cmd; |
4385 | 4446 | ||
4386 | drbd_thread_current_set_cpu(&tconn->receiver); | 4447 | drbd_thread_current_set_cpu(&connection->receiver); |
4387 | if (drbd_recv_header(tconn, &pi)) | 4448 | if (drbd_recv_header(connection, &pi)) |
4388 | goto err_out; | 4449 | goto err_out; |
4389 | 4450 | ||
4390 | cmd = &drbd_cmd_handler[pi.cmd]; | 4451 | cmd = &drbd_cmd_handler[pi.cmd]; |
4391 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || !cmd->fn)) { | 4452 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || !cmd->fn)) { |
4392 | conn_err(tconn, "Unexpected data packet %s (0x%04x)", | 4453 | drbd_err(connection, "Unexpected data packet %s (0x%04x)", |
4393 | cmdname(pi.cmd), pi.cmd); | 4454 | cmdname(pi.cmd), pi.cmd); |
4394 | goto err_out; | 4455 | goto err_out; |
4395 | } | 4456 | } |
4396 | 4457 | ||
4397 | shs = cmd->pkt_size; | 4458 | shs = cmd->pkt_size; |
4398 | if (pi.size > shs && !cmd->expect_payload) { | 4459 | if (pi.size > shs && !cmd->expect_payload) { |
4399 | conn_err(tconn, "No payload expected %s l:%d\n", | 4460 | drbd_err(connection, "No payload expected %s l:%d\n", |
4400 | cmdname(pi.cmd), pi.size); | 4461 | cmdname(pi.cmd), pi.size); |
4401 | goto err_out; | 4462 | goto err_out; |
4402 | } | 4463 | } |
4403 | 4464 | ||
4404 | if (shs) { | 4465 | if (shs) { |
4405 | err = drbd_recv_all_warn(tconn, pi.data, shs); | 4466 | err = drbd_recv_all_warn(connection, pi.data, shs); |
4406 | if (err) | 4467 | if (err) |
4407 | goto err_out; | 4468 | goto err_out; |
4408 | pi.size -= shs; | 4469 | pi.size -= shs; |
4409 | } | 4470 | } |
4410 | 4471 | ||
4411 | err = cmd->fn(tconn, &pi); | 4472 | err = cmd->fn(connection, &pi); |
4412 | if (err) { | 4473 | if (err) { |
4413 | conn_err(tconn, "error receiving %s, e: %d l: %d!\n", | 4474 | drbd_err(connection, "error receiving %s, e: %d l: %d!\n", |
4414 | cmdname(pi.cmd), err, pi.size); | 4475 | cmdname(pi.cmd), err, pi.size); |
4415 | goto err_out; | 4476 | goto err_out; |
4416 | } | 4477 | } |
@@ -4418,27 +4479,16 @@ static void drbdd(struct drbd_tconn *tconn) | |||
4418 | return; | 4479 | return; |
4419 | 4480 | ||
4420 | err_out: | 4481 | err_out: |
4421 | conn_request_state(tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); | 4482 | conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
4422 | } | ||
4423 | |||
4424 | void conn_flush_workqueue(struct drbd_tconn *tconn) | ||
4425 | { | ||
4426 | struct drbd_wq_barrier barr; | ||
4427 | |||
4428 | barr.w.cb = w_prev_work_done; | ||
4429 | barr.w.tconn = tconn; | ||
4430 | init_completion(&barr.done); | ||
4431 | drbd_queue_work(&tconn->sender_work, &barr.w); | ||
4432 | wait_for_completion(&barr.done); | ||
4433 | } | 4483 | } |
4434 | 4484 | ||
4435 | static void conn_disconnect(struct drbd_tconn *tconn) | 4485 | static void conn_disconnect(struct drbd_connection *connection) |
4436 | { | 4486 | { |
4437 | struct drbd_conf *mdev; | 4487 | struct drbd_peer_device *peer_device; |
4438 | enum drbd_conns oc; | 4488 | enum drbd_conns oc; |
4439 | int vnr; | 4489 | int vnr; |
4440 | 4490 | ||
4441 | if (tconn->cstate == C_STANDALONE) | 4491 | if (connection->cstate == C_STANDALONE) |
4442 | return; | 4492 | return; |
4443 | 4493 | ||
4444 | /* We are about to start the cleanup after connection loss. | 4494 | /* We are about to start the cleanup after connection loss. |
@@ -4446,54 +4496,56 @@ static void conn_disconnect(struct drbd_tconn *tconn) | |||
4446 | * Usually we should be in some network failure state already, | 4496 | * Usually we should be in some network failure state already, |
4447 | * but just in case we are not, we fix it up here. | 4497 | * but just in case we are not, we fix it up here. |
4448 | */ | 4498 | */ |
4449 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); | 4499 | conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
4450 | 4500 | ||
4451 | /* asender does not clean up anything. it must not interfere, either */ | 4501 | /* asender does not clean up anything. it must not interfere, either */ |
4452 | drbd_thread_stop(&tconn->asender); | 4502 | drbd_thread_stop(&connection->asender); |
4453 | drbd_free_sock(tconn); | 4503 | drbd_free_sock(connection); |
4454 | 4504 | ||
4455 | rcu_read_lock(); | 4505 | rcu_read_lock(); |
4456 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 4506 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
4457 | kref_get(&mdev->kref); | 4507 | struct drbd_device *device = peer_device->device; |
4508 | kref_get(&device->kref); | ||
4458 | rcu_read_unlock(); | 4509 | rcu_read_unlock(); |
4459 | drbd_disconnected(mdev); | 4510 | drbd_disconnected(peer_device); |
4460 | kref_put(&mdev->kref, &drbd_minor_destroy); | 4511 | kref_put(&device->kref, drbd_destroy_device); |
4461 | rcu_read_lock(); | 4512 | rcu_read_lock(); |
4462 | } | 4513 | } |
4463 | rcu_read_unlock(); | 4514 | rcu_read_unlock(); |
4464 | 4515 | ||
4465 | if (!list_empty(&tconn->current_epoch->list)) | 4516 | if (!list_empty(&connection->current_epoch->list)) |
4466 | conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n"); | 4517 | drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n"); |
4467 | /* ok, no more ee's on the fly, it is safe to reset the epoch_size */ | 4518 | /* ok, no more ee's on the fly, it is safe to reset the epoch_size */ |
4468 | atomic_set(&tconn->current_epoch->epoch_size, 0); | 4519 | atomic_set(&connection->current_epoch->epoch_size, 0); |
4469 | tconn->send.seen_any_write_yet = false; | 4520 | connection->send.seen_any_write_yet = false; |
4470 | 4521 | ||
4471 | conn_info(tconn, "Connection closed\n"); | 4522 | drbd_info(connection, "Connection closed\n"); |
4472 | 4523 | ||
4473 | if (conn_highest_role(tconn) == R_PRIMARY && conn_highest_pdsk(tconn) >= D_UNKNOWN) | 4524 | if (conn_highest_role(connection) == R_PRIMARY && conn_highest_pdsk(connection) >= D_UNKNOWN) |
4474 | conn_try_outdate_peer_async(tconn); | 4525 | conn_try_outdate_peer_async(connection); |
4475 | 4526 | ||
4476 | spin_lock_irq(&tconn->req_lock); | 4527 | spin_lock_irq(&connection->resource->req_lock); |
4477 | oc = tconn->cstate; | 4528 | oc = connection->cstate; |
4478 | if (oc >= C_UNCONNECTED) | 4529 | if (oc >= C_UNCONNECTED) |
4479 | _conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); | 4530 | _conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
4480 | 4531 | ||
4481 | spin_unlock_irq(&tconn->req_lock); | 4532 | spin_unlock_irq(&connection->resource->req_lock); |
4482 | 4533 | ||
4483 | if (oc == C_DISCONNECTING) | 4534 | if (oc == C_DISCONNECTING) |
4484 | conn_request_state(tconn, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD); | 4535 | conn_request_state(connection, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD); |
4485 | } | 4536 | } |
4486 | 4537 | ||
4487 | static int drbd_disconnected(struct drbd_conf *mdev) | 4538 | static int drbd_disconnected(struct drbd_peer_device *peer_device) |
4488 | { | 4539 | { |
4540 | struct drbd_device *device = peer_device->device; | ||
4489 | unsigned int i; | 4541 | unsigned int i; |
4490 | 4542 | ||
4491 | /* wait for current activity to cease. */ | 4543 | /* wait for current activity to cease. */ |
4492 | spin_lock_irq(&mdev->tconn->req_lock); | 4544 | spin_lock_irq(&device->resource->req_lock); |
4493 | _drbd_wait_ee_list_empty(mdev, &mdev->active_ee); | 4545 | _drbd_wait_ee_list_empty(device, &device->active_ee); |
4494 | _drbd_wait_ee_list_empty(mdev, &mdev->sync_ee); | 4546 | _drbd_wait_ee_list_empty(device, &device->sync_ee); |
4495 | _drbd_wait_ee_list_empty(mdev, &mdev->read_ee); | 4547 | _drbd_wait_ee_list_empty(device, &device->read_ee); |
4496 | spin_unlock_irq(&mdev->tconn->req_lock); | 4548 | spin_unlock_irq(&device->resource->req_lock); |
4497 | 4549 | ||
4498 | /* We do not have data structures that would allow us to | 4550 | /* We do not have data structures that would allow us to |
4499 | * get the rs_pending_cnt down to 0 again. | 4551 | * get the rs_pending_cnt down to 0 again. |
@@ -4505,42 +4557,42 @@ static int drbd_disconnected(struct drbd_conf *mdev) | |||
4505 | * resync_LRU. The resync_LRU tracks the whole operation including | 4557 | * resync_LRU. The resync_LRU tracks the whole operation including |
4506 | * the disk-IO, while the rs_pending_cnt only tracks the blocks | 4558 | * the disk-IO, while the rs_pending_cnt only tracks the blocks |
4507 | * on the fly. */ | 4559 | * on the fly. */ |
4508 | drbd_rs_cancel_all(mdev); | 4560 | drbd_rs_cancel_all(device); |
4509 | mdev->rs_total = 0; | 4561 | device->rs_total = 0; |
4510 | mdev->rs_failed = 0; | 4562 | device->rs_failed = 0; |
4511 | atomic_set(&mdev->rs_pending_cnt, 0); | 4563 | atomic_set(&device->rs_pending_cnt, 0); |
4512 | wake_up(&mdev->misc_wait); | 4564 | wake_up(&device->misc_wait); |
4513 | 4565 | ||
4514 | del_timer_sync(&mdev->resync_timer); | 4566 | del_timer_sync(&device->resync_timer); |
4515 | resync_timer_fn((unsigned long)mdev); | 4567 | resync_timer_fn((unsigned long)device); |
4516 | 4568 | ||
4517 | /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, | 4569 | /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, |
4518 | * w_make_resync_request etc. which may still be on the worker queue | 4570 | * w_make_resync_request etc. which may still be on the worker queue |
4519 | * to be "canceled" */ | 4571 | * to be "canceled" */ |
4520 | drbd_flush_workqueue(mdev); | 4572 | drbd_flush_workqueue(&peer_device->connection->sender_work); |
4521 | 4573 | ||
4522 | drbd_finish_peer_reqs(mdev); | 4574 | drbd_finish_peer_reqs(device); |
4523 | 4575 | ||
4524 | /* This second workqueue flush is necessary, since drbd_finish_peer_reqs() | 4576 | /* This second workqueue flush is necessary, since drbd_finish_peer_reqs() |
4525 | might have issued a work again. The one before drbd_finish_peer_reqs() is | 4577 | might have issued a work again. The one before drbd_finish_peer_reqs() is |
4526 | necessary to reclain net_ee in drbd_finish_peer_reqs(). */ | 4578 | necessary to reclain net_ee in drbd_finish_peer_reqs(). */ |
4527 | drbd_flush_workqueue(mdev); | 4579 | drbd_flush_workqueue(&peer_device->connection->sender_work); |
4528 | 4580 | ||
4529 | /* need to do it again, drbd_finish_peer_reqs() may have populated it | 4581 | /* need to do it again, drbd_finish_peer_reqs() may have populated it |
4530 | * again via drbd_try_clear_on_disk_bm(). */ | 4582 | * again via drbd_try_clear_on_disk_bm(). */ |
4531 | drbd_rs_cancel_all(mdev); | 4583 | drbd_rs_cancel_all(device); |
4532 | 4584 | ||
4533 | kfree(mdev->p_uuid); | 4585 | kfree(device->p_uuid); |
4534 | mdev->p_uuid = NULL; | 4586 | device->p_uuid = NULL; |
4535 | 4587 | ||
4536 | if (!drbd_suspended(mdev)) | 4588 | if (!drbd_suspended(device)) |
4537 | tl_clear(mdev->tconn); | 4589 | tl_clear(peer_device->connection); |
4538 | 4590 | ||
4539 | drbd_md_sync(mdev); | 4591 | drbd_md_sync(device); |
4540 | 4592 | ||
4541 | /* serialize with bitmap writeout triggered by the state change, | 4593 | /* serialize with bitmap writeout triggered by the state change, |
4542 | * if any. */ | 4594 | * if any. */ |
4543 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); | 4595 | wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags)); |
4544 | 4596 | ||
4545 | /* tcp_close and release of sendpage pages can be deferred. I don't | 4597 | /* tcp_close and release of sendpage pages can be deferred. I don't |
4546 | * want to use SO_LINGER, because apparently it can be deferred for | 4598 | * want to use SO_LINGER, because apparently it can be deferred for |
@@ -4549,20 +4601,20 @@ static int drbd_disconnected(struct drbd_conf *mdev) | |||
4549 | * Actually we don't care for exactly when the network stack does its | 4601 | * Actually we don't care for exactly when the network stack does its |
4550 | * put_page(), but release our reference on these pages right here. | 4602 | * put_page(), but release our reference on these pages right here. |
4551 | */ | 4603 | */ |
4552 | i = drbd_free_peer_reqs(mdev, &mdev->net_ee); | 4604 | i = drbd_free_peer_reqs(device, &device->net_ee); |
4553 | if (i) | 4605 | if (i) |
4554 | dev_info(DEV, "net_ee not empty, killed %u entries\n", i); | 4606 | drbd_info(device, "net_ee not empty, killed %u entries\n", i); |
4555 | i = atomic_read(&mdev->pp_in_use_by_net); | 4607 | i = atomic_read(&device->pp_in_use_by_net); |
4556 | if (i) | 4608 | if (i) |
4557 | dev_info(DEV, "pp_in_use_by_net = %d, expected 0\n", i); | 4609 | drbd_info(device, "pp_in_use_by_net = %d, expected 0\n", i); |
4558 | i = atomic_read(&mdev->pp_in_use); | 4610 | i = atomic_read(&device->pp_in_use); |
4559 | if (i) | 4611 | if (i) |
4560 | dev_info(DEV, "pp_in_use = %d, expected 0\n", i); | 4612 | drbd_info(device, "pp_in_use = %d, expected 0\n", i); |
4561 | 4613 | ||
4562 | D_ASSERT(list_empty(&mdev->read_ee)); | 4614 | D_ASSERT(device, list_empty(&device->read_ee)); |
4563 | D_ASSERT(list_empty(&mdev->active_ee)); | 4615 | D_ASSERT(device, list_empty(&device->active_ee)); |
4564 | D_ASSERT(list_empty(&mdev->sync_ee)); | 4616 | D_ASSERT(device, list_empty(&device->sync_ee)); |
4565 | D_ASSERT(list_empty(&mdev->done_ee)); | 4617 | D_ASSERT(device, list_empty(&device->done_ee)); |
4566 | 4618 | ||
4567 | return 0; | 4619 | return 0; |
4568 | } | 4620 | } |
@@ -4576,19 +4628,19 @@ static int drbd_disconnected(struct drbd_conf *mdev) | |||
4576 | * | 4628 | * |
4577 | * for now, they are expected to be zero, but ignored. | 4629 | * for now, they are expected to be zero, but ignored. |
4578 | */ | 4630 | */ |
4579 | static int drbd_send_features(struct drbd_tconn *tconn) | 4631 | static int drbd_send_features(struct drbd_connection *connection) |
4580 | { | 4632 | { |
4581 | struct drbd_socket *sock; | 4633 | struct drbd_socket *sock; |
4582 | struct p_connection_features *p; | 4634 | struct p_connection_features *p; |
4583 | 4635 | ||
4584 | sock = &tconn->data; | 4636 | sock = &connection->data; |
4585 | p = conn_prepare_command(tconn, sock); | 4637 | p = conn_prepare_command(connection, sock); |
4586 | if (!p) | 4638 | if (!p) |
4587 | return -EIO; | 4639 | return -EIO; |
4588 | memset(p, 0, sizeof(*p)); | 4640 | memset(p, 0, sizeof(*p)); |
4589 | p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); | 4641 | p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); |
4590 | p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); | 4642 | p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); |
4591 | return conn_send_command(tconn, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0); | 4643 | return conn_send_command(connection, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0); |
4592 | } | 4644 | } |
4593 | 4645 | ||
4594 | /* | 4646 | /* |
@@ -4598,36 +4650,36 @@ static int drbd_send_features(struct drbd_tconn *tconn) | |||
4598 | * -1 peer talks different language, | 4650 | * -1 peer talks different language, |
4599 | * no point in trying again, please go standalone. | 4651 | * no point in trying again, please go standalone. |
4600 | */ | 4652 | */ |
4601 | static int drbd_do_features(struct drbd_tconn *tconn) | 4653 | static int drbd_do_features(struct drbd_connection *connection) |
4602 | { | 4654 | { |
4603 | /* ASSERT current == tconn->receiver ... */ | 4655 | /* ASSERT current == connection->receiver ... */ |
4604 | struct p_connection_features *p; | 4656 | struct p_connection_features *p; |
4605 | const int expect = sizeof(struct p_connection_features); | 4657 | const int expect = sizeof(struct p_connection_features); |
4606 | struct packet_info pi; | 4658 | struct packet_info pi; |
4607 | int err; | 4659 | int err; |
4608 | 4660 | ||
4609 | err = drbd_send_features(tconn); | 4661 | err = drbd_send_features(connection); |
4610 | if (err) | 4662 | if (err) |
4611 | return 0; | 4663 | return 0; |
4612 | 4664 | ||
4613 | err = drbd_recv_header(tconn, &pi); | 4665 | err = drbd_recv_header(connection, &pi); |
4614 | if (err) | 4666 | if (err) |
4615 | return 0; | 4667 | return 0; |
4616 | 4668 | ||
4617 | if (pi.cmd != P_CONNECTION_FEATURES) { | 4669 | if (pi.cmd != P_CONNECTION_FEATURES) { |
4618 | conn_err(tconn, "expected ConnectionFeatures packet, received: %s (0x%04x)\n", | 4670 | drbd_err(connection, "expected ConnectionFeatures packet, received: %s (0x%04x)\n", |
4619 | cmdname(pi.cmd), pi.cmd); | 4671 | cmdname(pi.cmd), pi.cmd); |
4620 | return -1; | 4672 | return -1; |
4621 | } | 4673 | } |
4622 | 4674 | ||
4623 | if (pi.size != expect) { | 4675 | if (pi.size != expect) { |
4624 | conn_err(tconn, "expected ConnectionFeatures length: %u, received: %u\n", | 4676 | drbd_err(connection, "expected ConnectionFeatures length: %u, received: %u\n", |
4625 | expect, pi.size); | 4677 | expect, pi.size); |
4626 | return -1; | 4678 | return -1; |
4627 | } | 4679 | } |
4628 | 4680 | ||
4629 | p = pi.data; | 4681 | p = pi.data; |
4630 | err = drbd_recv_all_warn(tconn, p, expect); | 4682 | err = drbd_recv_all_warn(connection, p, expect); |
4631 | if (err) | 4683 | if (err) |
4632 | return 0; | 4684 | return 0; |
4633 | 4685 | ||
@@ -4640,15 +4692,15 @@ static int drbd_do_features(struct drbd_tconn *tconn) | |||
4640 | PRO_VERSION_MIN > p->protocol_max) | 4692 | PRO_VERSION_MIN > p->protocol_max) |
4641 | goto incompat; | 4693 | goto incompat; |
4642 | 4694 | ||
4643 | tconn->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max); | 4695 | connection->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max); |
4644 | 4696 | ||
4645 | conn_info(tconn, "Handshake successful: " | 4697 | drbd_info(connection, "Handshake successful: " |
4646 | "Agreed network protocol version %d\n", tconn->agreed_pro_version); | 4698 | "Agreed network protocol version %d\n", connection->agreed_pro_version); |
4647 | 4699 | ||
4648 | return 1; | 4700 | return 1; |
4649 | 4701 | ||
4650 | incompat: | 4702 | incompat: |
4651 | conn_err(tconn, "incompatible DRBD dialects: " | 4703 | drbd_err(connection, "incompatible DRBD dialects: " |
4652 | "I support %d-%d, peer supports %d-%d\n", | 4704 | "I support %d-%d, peer supports %d-%d\n", |
4653 | PRO_VERSION_MIN, PRO_VERSION_MAX, | 4705 | PRO_VERSION_MIN, PRO_VERSION_MAX, |
4654 | p->protocol_min, p->protocol_max); | 4706 | p->protocol_min, p->protocol_max); |
@@ -4656,10 +4708,10 @@ static int drbd_do_features(struct drbd_tconn *tconn) | |||
4656 | } | 4708 | } |
4657 | 4709 | ||
4658 | #if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE) | 4710 | #if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE) |
4659 | static int drbd_do_auth(struct drbd_tconn *tconn) | 4711 | static int drbd_do_auth(struct drbd_connection *connection) |
4660 | { | 4712 | { |
4661 | conn_err(tconn, "This kernel was build without CONFIG_CRYPTO_HMAC.\n"); | 4713 | drbd_err(connection, "This kernel was build without CONFIG_CRYPTO_HMAC.\n"); |
4662 | conn_err(tconn, "You need to disable 'cram-hmac-alg' in drbd.conf.\n"); | 4714 | drbd_err(connection, "You need to disable 'cram-hmac-alg' in drbd.conf.\n"); |
4663 | return -1; | 4715 | return -1; |
4664 | } | 4716 | } |
4665 | #else | 4717 | #else |
@@ -4671,7 +4723,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4671 | -1 - auth failed, don't try again. | 4723 | -1 - auth failed, don't try again. |
4672 | */ | 4724 | */ |
4673 | 4725 | ||
4674 | static int drbd_do_auth(struct drbd_tconn *tconn) | 4726 | static int drbd_do_auth(struct drbd_connection *connection) |
4675 | { | 4727 | { |
4676 | struct drbd_socket *sock; | 4728 | struct drbd_socket *sock; |
4677 | char my_challenge[CHALLENGE_LEN]; /* 64 Bytes... */ | 4729 | char my_challenge[CHALLENGE_LEN]; /* 64 Bytes... */ |
@@ -4690,69 +4742,69 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4690 | /* FIXME: Put the challenge/response into the preallocated socket buffer. */ | 4742 | /* FIXME: Put the challenge/response into the preallocated socket buffer. */ |
4691 | 4743 | ||
4692 | rcu_read_lock(); | 4744 | rcu_read_lock(); |
4693 | nc = rcu_dereference(tconn->net_conf); | 4745 | nc = rcu_dereference(connection->net_conf); |
4694 | key_len = strlen(nc->shared_secret); | 4746 | key_len = strlen(nc->shared_secret); |
4695 | memcpy(secret, nc->shared_secret, key_len); | 4747 | memcpy(secret, nc->shared_secret, key_len); |
4696 | rcu_read_unlock(); | 4748 | rcu_read_unlock(); |
4697 | 4749 | ||
4698 | desc.tfm = tconn->cram_hmac_tfm; | 4750 | desc.tfm = connection->cram_hmac_tfm; |
4699 | desc.flags = 0; | 4751 | desc.flags = 0; |
4700 | 4752 | ||
4701 | rv = crypto_hash_setkey(tconn->cram_hmac_tfm, (u8 *)secret, key_len); | 4753 | rv = crypto_hash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len); |
4702 | if (rv) { | 4754 | if (rv) { |
4703 | conn_err(tconn, "crypto_hash_setkey() failed with %d\n", rv); | 4755 | drbd_err(connection, "crypto_hash_setkey() failed with %d\n", rv); |
4704 | rv = -1; | 4756 | rv = -1; |
4705 | goto fail; | 4757 | goto fail; |
4706 | } | 4758 | } |
4707 | 4759 | ||
4708 | get_random_bytes(my_challenge, CHALLENGE_LEN); | 4760 | get_random_bytes(my_challenge, CHALLENGE_LEN); |
4709 | 4761 | ||
4710 | sock = &tconn->data; | 4762 | sock = &connection->data; |
4711 | if (!conn_prepare_command(tconn, sock)) { | 4763 | if (!conn_prepare_command(connection, sock)) { |
4712 | rv = 0; | 4764 | rv = 0; |
4713 | goto fail; | 4765 | goto fail; |
4714 | } | 4766 | } |
4715 | rv = !conn_send_command(tconn, sock, P_AUTH_CHALLENGE, 0, | 4767 | rv = !conn_send_command(connection, sock, P_AUTH_CHALLENGE, 0, |
4716 | my_challenge, CHALLENGE_LEN); | 4768 | my_challenge, CHALLENGE_LEN); |
4717 | if (!rv) | 4769 | if (!rv) |
4718 | goto fail; | 4770 | goto fail; |
4719 | 4771 | ||
4720 | err = drbd_recv_header(tconn, &pi); | 4772 | err = drbd_recv_header(connection, &pi); |
4721 | if (err) { | 4773 | if (err) { |
4722 | rv = 0; | 4774 | rv = 0; |
4723 | goto fail; | 4775 | goto fail; |
4724 | } | 4776 | } |
4725 | 4777 | ||
4726 | if (pi.cmd != P_AUTH_CHALLENGE) { | 4778 | if (pi.cmd != P_AUTH_CHALLENGE) { |
4727 | conn_err(tconn, "expected AuthChallenge packet, received: %s (0x%04x)\n", | 4779 | drbd_err(connection, "expected AuthChallenge packet, received: %s (0x%04x)\n", |
4728 | cmdname(pi.cmd), pi.cmd); | 4780 | cmdname(pi.cmd), pi.cmd); |
4729 | rv = 0; | 4781 | rv = 0; |
4730 | goto fail; | 4782 | goto fail; |
4731 | } | 4783 | } |
4732 | 4784 | ||
4733 | if (pi.size > CHALLENGE_LEN * 2) { | 4785 | if (pi.size > CHALLENGE_LEN * 2) { |
4734 | conn_err(tconn, "expected AuthChallenge payload too big.\n"); | 4786 | drbd_err(connection, "expected AuthChallenge payload too big.\n"); |
4735 | rv = -1; | 4787 | rv = -1; |
4736 | goto fail; | 4788 | goto fail; |
4737 | } | 4789 | } |
4738 | 4790 | ||
4739 | peers_ch = kmalloc(pi.size, GFP_NOIO); | 4791 | peers_ch = kmalloc(pi.size, GFP_NOIO); |
4740 | if (peers_ch == NULL) { | 4792 | if (peers_ch == NULL) { |
4741 | conn_err(tconn, "kmalloc of peers_ch failed\n"); | 4793 | drbd_err(connection, "kmalloc of peers_ch failed\n"); |
4742 | rv = -1; | 4794 | rv = -1; |
4743 | goto fail; | 4795 | goto fail; |
4744 | } | 4796 | } |
4745 | 4797 | ||
4746 | err = drbd_recv_all_warn(tconn, peers_ch, pi.size); | 4798 | err = drbd_recv_all_warn(connection, peers_ch, pi.size); |
4747 | if (err) { | 4799 | if (err) { |
4748 | rv = 0; | 4800 | rv = 0; |
4749 | goto fail; | 4801 | goto fail; |
4750 | } | 4802 | } |
4751 | 4803 | ||
4752 | resp_size = crypto_hash_digestsize(tconn->cram_hmac_tfm); | 4804 | resp_size = crypto_hash_digestsize(connection->cram_hmac_tfm); |
4753 | response = kmalloc(resp_size, GFP_NOIO); | 4805 | response = kmalloc(resp_size, GFP_NOIO); |
4754 | if (response == NULL) { | 4806 | if (response == NULL) { |
4755 | conn_err(tconn, "kmalloc of response failed\n"); | 4807 | drbd_err(connection, "kmalloc of response failed\n"); |
4756 | rv = -1; | 4808 | rv = -1; |
4757 | goto fail; | 4809 | goto fail; |
4758 | } | 4810 | } |
@@ -4762,40 +4814,40 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4762 | 4814 | ||
4763 | rv = crypto_hash_digest(&desc, &sg, sg.length, response); | 4815 | rv = crypto_hash_digest(&desc, &sg, sg.length, response); |
4764 | if (rv) { | 4816 | if (rv) { |
4765 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); | 4817 | drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv); |
4766 | rv = -1; | 4818 | rv = -1; |
4767 | goto fail; | 4819 | goto fail; |
4768 | } | 4820 | } |
4769 | 4821 | ||
4770 | if (!conn_prepare_command(tconn, sock)) { | 4822 | if (!conn_prepare_command(connection, sock)) { |
4771 | rv = 0; | 4823 | rv = 0; |
4772 | goto fail; | 4824 | goto fail; |
4773 | } | 4825 | } |
4774 | rv = !conn_send_command(tconn, sock, P_AUTH_RESPONSE, 0, | 4826 | rv = !conn_send_command(connection, sock, P_AUTH_RESPONSE, 0, |
4775 | response, resp_size); | 4827 | response, resp_size); |
4776 | if (!rv) | 4828 | if (!rv) |
4777 | goto fail; | 4829 | goto fail; |
4778 | 4830 | ||
4779 | err = drbd_recv_header(tconn, &pi); | 4831 | err = drbd_recv_header(connection, &pi); |
4780 | if (err) { | 4832 | if (err) { |
4781 | rv = 0; | 4833 | rv = 0; |
4782 | goto fail; | 4834 | goto fail; |
4783 | } | 4835 | } |
4784 | 4836 | ||
4785 | if (pi.cmd != P_AUTH_RESPONSE) { | 4837 | if (pi.cmd != P_AUTH_RESPONSE) { |
4786 | conn_err(tconn, "expected AuthResponse packet, received: %s (0x%04x)\n", | 4838 | drbd_err(connection, "expected AuthResponse packet, received: %s (0x%04x)\n", |
4787 | cmdname(pi.cmd), pi.cmd); | 4839 | cmdname(pi.cmd), pi.cmd); |
4788 | rv = 0; | 4840 | rv = 0; |
4789 | goto fail; | 4841 | goto fail; |
4790 | } | 4842 | } |
4791 | 4843 | ||
4792 | if (pi.size != resp_size) { | 4844 | if (pi.size != resp_size) { |
4793 | conn_err(tconn, "expected AuthResponse payload of wrong size\n"); | 4845 | drbd_err(connection, "expected AuthResponse payload of wrong size\n"); |
4794 | rv = 0; | 4846 | rv = 0; |
4795 | goto fail; | 4847 | goto fail; |
4796 | } | 4848 | } |
4797 | 4849 | ||
4798 | err = drbd_recv_all_warn(tconn, response , resp_size); | 4850 | err = drbd_recv_all_warn(connection, response , resp_size); |
4799 | if (err) { | 4851 | if (err) { |
4800 | rv = 0; | 4852 | rv = 0; |
4801 | goto fail; | 4853 | goto fail; |
@@ -4803,7 +4855,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4803 | 4855 | ||
4804 | right_response = kmalloc(resp_size, GFP_NOIO); | 4856 | right_response = kmalloc(resp_size, GFP_NOIO); |
4805 | if (right_response == NULL) { | 4857 | if (right_response == NULL) { |
4806 | conn_err(tconn, "kmalloc of right_response failed\n"); | 4858 | drbd_err(connection, "kmalloc of right_response failed\n"); |
4807 | rv = -1; | 4859 | rv = -1; |
4808 | goto fail; | 4860 | goto fail; |
4809 | } | 4861 | } |
@@ -4812,7 +4864,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4812 | 4864 | ||
4813 | rv = crypto_hash_digest(&desc, &sg, sg.length, right_response); | 4865 | rv = crypto_hash_digest(&desc, &sg, sg.length, right_response); |
4814 | if (rv) { | 4866 | if (rv) { |
4815 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); | 4867 | drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv); |
4816 | rv = -1; | 4868 | rv = -1; |
4817 | goto fail; | 4869 | goto fail; |
4818 | } | 4870 | } |
@@ -4820,7 +4872,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4820 | rv = !memcmp(response, right_response, resp_size); | 4872 | rv = !memcmp(response, right_response, resp_size); |
4821 | 4873 | ||
4822 | if (rv) | 4874 | if (rv) |
4823 | conn_info(tconn, "Peer authenticated using %d bytes HMAC\n", | 4875 | drbd_info(connection, "Peer authenticated using %d bytes HMAC\n", |
4824 | resp_size); | 4876 | resp_size); |
4825 | else | 4877 | else |
4826 | rv = -1; | 4878 | rv = -1; |
@@ -4834,163 +4886,169 @@ static int drbd_do_auth(struct drbd_tconn *tconn) | |||
4834 | } | 4886 | } |
4835 | #endif | 4887 | #endif |
4836 | 4888 | ||
4837 | int drbdd_init(struct drbd_thread *thi) | 4889 | int drbd_receiver(struct drbd_thread *thi) |
4838 | { | 4890 | { |
4839 | struct drbd_tconn *tconn = thi->tconn; | 4891 | struct drbd_connection *connection = thi->connection; |
4840 | int h; | 4892 | int h; |
4841 | 4893 | ||
4842 | conn_info(tconn, "receiver (re)started\n"); | 4894 | drbd_info(connection, "receiver (re)started\n"); |
4843 | 4895 | ||
4844 | do { | 4896 | do { |
4845 | h = conn_connect(tconn); | 4897 | h = conn_connect(connection); |
4846 | if (h == 0) { | 4898 | if (h == 0) { |
4847 | conn_disconnect(tconn); | 4899 | conn_disconnect(connection); |
4848 | schedule_timeout_interruptible(HZ); | 4900 | schedule_timeout_interruptible(HZ); |
4849 | } | 4901 | } |
4850 | if (h == -1) { | 4902 | if (h == -1) { |
4851 | conn_warn(tconn, "Discarding network configuration.\n"); | 4903 | drbd_warn(connection, "Discarding network configuration.\n"); |
4852 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 4904 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
4853 | } | 4905 | } |
4854 | } while (h == 0); | 4906 | } while (h == 0); |
4855 | 4907 | ||
4856 | if (h > 0) | 4908 | if (h > 0) |
4857 | drbdd(tconn); | 4909 | drbdd(connection); |
4858 | 4910 | ||
4859 | conn_disconnect(tconn); | 4911 | conn_disconnect(connection); |
4860 | 4912 | ||
4861 | conn_info(tconn, "receiver terminated\n"); | 4913 | drbd_info(connection, "receiver terminated\n"); |
4862 | return 0; | 4914 | return 0; |
4863 | } | 4915 | } |
4864 | 4916 | ||
4865 | /* ********* acknowledge sender ******** */ | 4917 | /* ********* acknowledge sender ******** */ |
4866 | 4918 | ||
4867 | static int got_conn_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) | 4919 | static int got_conn_RqSReply(struct drbd_connection *connection, struct packet_info *pi) |
4868 | { | 4920 | { |
4869 | struct p_req_state_reply *p = pi->data; | 4921 | struct p_req_state_reply *p = pi->data; |
4870 | int retcode = be32_to_cpu(p->retcode); | 4922 | int retcode = be32_to_cpu(p->retcode); |
4871 | 4923 | ||
4872 | if (retcode >= SS_SUCCESS) { | 4924 | if (retcode >= SS_SUCCESS) { |
4873 | set_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags); | 4925 | set_bit(CONN_WD_ST_CHG_OKAY, &connection->flags); |
4874 | } else { | 4926 | } else { |
4875 | set_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags); | 4927 | set_bit(CONN_WD_ST_CHG_FAIL, &connection->flags); |
4876 | conn_err(tconn, "Requested state change failed by peer: %s (%d)\n", | 4928 | drbd_err(connection, "Requested state change failed by peer: %s (%d)\n", |
4877 | drbd_set_st_err_str(retcode), retcode); | 4929 | drbd_set_st_err_str(retcode), retcode); |
4878 | } | 4930 | } |
4879 | wake_up(&tconn->ping_wait); | 4931 | wake_up(&connection->ping_wait); |
4880 | 4932 | ||
4881 | return 0; | 4933 | return 0; |
4882 | } | 4934 | } |
4883 | 4935 | ||
4884 | static int got_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) | 4936 | static int got_RqSReply(struct drbd_connection *connection, struct packet_info *pi) |
4885 | { | 4937 | { |
4886 | struct drbd_conf *mdev; | 4938 | struct drbd_peer_device *peer_device; |
4939 | struct drbd_device *device; | ||
4887 | struct p_req_state_reply *p = pi->data; | 4940 | struct p_req_state_reply *p = pi->data; |
4888 | int retcode = be32_to_cpu(p->retcode); | 4941 | int retcode = be32_to_cpu(p->retcode); |
4889 | 4942 | ||
4890 | mdev = vnr_to_mdev(tconn, pi->vnr); | 4943 | peer_device = conn_peer_device(connection, pi->vnr); |
4891 | if (!mdev) | 4944 | if (!peer_device) |
4892 | return -EIO; | 4945 | return -EIO; |
4946 | device = peer_device->device; | ||
4893 | 4947 | ||
4894 | if (test_bit(CONN_WD_ST_CHG_REQ, &tconn->flags)) { | 4948 | if (test_bit(CONN_WD_ST_CHG_REQ, &connection->flags)) { |
4895 | D_ASSERT(tconn->agreed_pro_version < 100); | 4949 | D_ASSERT(device, connection->agreed_pro_version < 100); |
4896 | return got_conn_RqSReply(tconn, pi); | 4950 | return got_conn_RqSReply(connection, pi); |
4897 | } | 4951 | } |
4898 | 4952 | ||
4899 | if (retcode >= SS_SUCCESS) { | 4953 | if (retcode >= SS_SUCCESS) { |
4900 | set_bit(CL_ST_CHG_SUCCESS, &mdev->flags); | 4954 | set_bit(CL_ST_CHG_SUCCESS, &device->flags); |
4901 | } else { | 4955 | } else { |
4902 | set_bit(CL_ST_CHG_FAIL, &mdev->flags); | 4956 | set_bit(CL_ST_CHG_FAIL, &device->flags); |
4903 | dev_err(DEV, "Requested state change failed by peer: %s (%d)\n", | 4957 | drbd_err(device, "Requested state change failed by peer: %s (%d)\n", |
4904 | drbd_set_st_err_str(retcode), retcode); | 4958 | drbd_set_st_err_str(retcode), retcode); |
4905 | } | 4959 | } |
4906 | wake_up(&mdev->state_wait); | 4960 | wake_up(&device->state_wait); |
4907 | 4961 | ||
4908 | return 0; | 4962 | return 0; |
4909 | } | 4963 | } |
4910 | 4964 | ||
4911 | static int got_Ping(struct drbd_tconn *tconn, struct packet_info *pi) | 4965 | static int got_Ping(struct drbd_connection *connection, struct packet_info *pi) |
4912 | { | 4966 | { |
4913 | return drbd_send_ping_ack(tconn); | 4967 | return drbd_send_ping_ack(connection); |
4914 | 4968 | ||
4915 | } | 4969 | } |
4916 | 4970 | ||
4917 | static int got_PingAck(struct drbd_tconn *tconn, struct packet_info *pi) | 4971 | static int got_PingAck(struct drbd_connection *connection, struct packet_info *pi) |
4918 | { | 4972 | { |
4919 | /* restore idle timeout */ | 4973 | /* restore idle timeout */ |
4920 | tconn->meta.socket->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ; | 4974 | connection->meta.socket->sk->sk_rcvtimeo = connection->net_conf->ping_int*HZ; |
4921 | if (!test_and_set_bit(GOT_PING_ACK, &tconn->flags)) | 4975 | if (!test_and_set_bit(GOT_PING_ACK, &connection->flags)) |
4922 | wake_up(&tconn->ping_wait); | 4976 | wake_up(&connection->ping_wait); |
4923 | 4977 | ||
4924 | return 0; | 4978 | return 0; |
4925 | } | 4979 | } |
4926 | 4980 | ||
4927 | static int got_IsInSync(struct drbd_tconn *tconn, struct packet_info *pi) | 4981 | static int got_IsInSync(struct drbd_connection *connection, struct packet_info *pi) |
4928 | { | 4982 | { |
4929 | struct drbd_conf *mdev; | 4983 | struct drbd_peer_device *peer_device; |
4984 | struct drbd_device *device; | ||
4930 | struct p_block_ack *p = pi->data; | 4985 | struct p_block_ack *p = pi->data; |
4931 | sector_t sector = be64_to_cpu(p->sector); | 4986 | sector_t sector = be64_to_cpu(p->sector); |
4932 | int blksize = be32_to_cpu(p->blksize); | 4987 | int blksize = be32_to_cpu(p->blksize); |
4933 | 4988 | ||
4934 | mdev = vnr_to_mdev(tconn, pi->vnr); | 4989 | peer_device = conn_peer_device(connection, pi->vnr); |
4935 | if (!mdev) | 4990 | if (!peer_device) |
4936 | return -EIO; | 4991 | return -EIO; |
4992 | device = peer_device->device; | ||
4937 | 4993 | ||
4938 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); | 4994 | D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); |
4939 | 4995 | ||
4940 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 4996 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
4941 | 4997 | ||
4942 | if (get_ldev(mdev)) { | 4998 | if (get_ldev(device)) { |
4943 | drbd_rs_complete_io(mdev, sector); | 4999 | drbd_rs_complete_io(device, sector); |
4944 | drbd_set_in_sync(mdev, sector, blksize); | 5000 | drbd_set_in_sync(device, sector, blksize); |
4945 | /* rs_same_csums is supposed to count in units of BM_BLOCK_SIZE */ | 5001 | /* rs_same_csums is supposed to count in units of BM_BLOCK_SIZE */ |
4946 | mdev->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); | 5002 | device->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); |
4947 | put_ldev(mdev); | 5003 | put_ldev(device); |
4948 | } | 5004 | } |
4949 | dec_rs_pending(mdev); | 5005 | dec_rs_pending(device); |
4950 | atomic_add(blksize >> 9, &mdev->rs_sect_in); | 5006 | atomic_add(blksize >> 9, &device->rs_sect_in); |
4951 | 5007 | ||
4952 | return 0; | 5008 | return 0; |
4953 | } | 5009 | } |
4954 | 5010 | ||
4955 | static int | 5011 | static int |
4956 | validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector, | 5012 | validate_req_change_req_state(struct drbd_device *device, u64 id, sector_t sector, |
4957 | struct rb_root *root, const char *func, | 5013 | struct rb_root *root, const char *func, |
4958 | enum drbd_req_event what, bool missing_ok) | 5014 | enum drbd_req_event what, bool missing_ok) |
4959 | { | 5015 | { |
4960 | struct drbd_request *req; | 5016 | struct drbd_request *req; |
4961 | struct bio_and_error m; | 5017 | struct bio_and_error m; |
4962 | 5018 | ||
4963 | spin_lock_irq(&mdev->tconn->req_lock); | 5019 | spin_lock_irq(&device->resource->req_lock); |
4964 | req = find_request(mdev, root, id, sector, missing_ok, func); | 5020 | req = find_request(device, root, id, sector, missing_ok, func); |
4965 | if (unlikely(!req)) { | 5021 | if (unlikely(!req)) { |
4966 | spin_unlock_irq(&mdev->tconn->req_lock); | 5022 | spin_unlock_irq(&device->resource->req_lock); |
4967 | return -EIO; | 5023 | return -EIO; |
4968 | } | 5024 | } |
4969 | __req_mod(req, what, &m); | 5025 | __req_mod(req, what, &m); |
4970 | spin_unlock_irq(&mdev->tconn->req_lock); | 5026 | spin_unlock_irq(&device->resource->req_lock); |
4971 | 5027 | ||
4972 | if (m.bio) | 5028 | if (m.bio) |
4973 | complete_master_bio(mdev, &m); | 5029 | complete_master_bio(device, &m); |
4974 | return 0; | 5030 | return 0; |
4975 | } | 5031 | } |
4976 | 5032 | ||
4977 | static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi) | 5033 | static int got_BlockAck(struct drbd_connection *connection, struct packet_info *pi) |
4978 | { | 5034 | { |
4979 | struct drbd_conf *mdev; | 5035 | struct drbd_peer_device *peer_device; |
5036 | struct drbd_device *device; | ||
4980 | struct p_block_ack *p = pi->data; | 5037 | struct p_block_ack *p = pi->data; |
4981 | sector_t sector = be64_to_cpu(p->sector); | 5038 | sector_t sector = be64_to_cpu(p->sector); |
4982 | int blksize = be32_to_cpu(p->blksize); | 5039 | int blksize = be32_to_cpu(p->blksize); |
4983 | enum drbd_req_event what; | 5040 | enum drbd_req_event what; |
4984 | 5041 | ||
4985 | mdev = vnr_to_mdev(tconn, pi->vnr); | 5042 | peer_device = conn_peer_device(connection, pi->vnr); |
4986 | if (!mdev) | 5043 | if (!peer_device) |
4987 | return -EIO; | 5044 | return -EIO; |
5045 | device = peer_device->device; | ||
4988 | 5046 | ||
4989 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 5047 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
4990 | 5048 | ||
4991 | if (p->block_id == ID_SYNCER) { | 5049 | if (p->block_id == ID_SYNCER) { |
4992 | drbd_set_in_sync(mdev, sector, blksize); | 5050 | drbd_set_in_sync(device, sector, blksize); |
4993 | dec_rs_pending(mdev); | 5051 | dec_rs_pending(device); |
4994 | return 0; | 5052 | return 0; |
4995 | } | 5053 | } |
4996 | switch (pi->cmd) { | 5054 | switch (pi->cmd) { |
@@ -5013,33 +5071,35 @@ static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi) | |||
5013 | BUG(); | 5071 | BUG(); |
5014 | } | 5072 | } |
5015 | 5073 | ||
5016 | return validate_req_change_req_state(mdev, p->block_id, sector, | 5074 | return validate_req_change_req_state(device, p->block_id, sector, |
5017 | &mdev->write_requests, __func__, | 5075 | &device->write_requests, __func__, |
5018 | what, false); | 5076 | what, false); |
5019 | } | 5077 | } |
5020 | 5078 | ||
5021 | static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi) | 5079 | static int got_NegAck(struct drbd_connection *connection, struct packet_info *pi) |
5022 | { | 5080 | { |
5023 | struct drbd_conf *mdev; | 5081 | struct drbd_peer_device *peer_device; |
5082 | struct drbd_device *device; | ||
5024 | struct p_block_ack *p = pi->data; | 5083 | struct p_block_ack *p = pi->data; |
5025 | sector_t sector = be64_to_cpu(p->sector); | 5084 | sector_t sector = be64_to_cpu(p->sector); |
5026 | int size = be32_to_cpu(p->blksize); | 5085 | int size = be32_to_cpu(p->blksize); |
5027 | int err; | 5086 | int err; |
5028 | 5087 | ||
5029 | mdev = vnr_to_mdev(tconn, pi->vnr); | 5088 | peer_device = conn_peer_device(connection, pi->vnr); |
5030 | if (!mdev) | 5089 | if (!peer_device) |
5031 | return -EIO; | 5090 | return -EIO; |
5091 | device = peer_device->device; | ||
5032 | 5092 | ||
5033 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 5093 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
5034 | 5094 | ||
5035 | if (p->block_id == ID_SYNCER) { | 5095 | if (p->block_id == ID_SYNCER) { |
5036 | dec_rs_pending(mdev); | 5096 | dec_rs_pending(device); |
5037 | drbd_rs_failed_io(mdev, sector, size); | 5097 | drbd_rs_failed_io(device, sector, size); |
5038 | return 0; | 5098 | return 0; |
5039 | } | 5099 | } |
5040 | 5100 | ||
5041 | err = validate_req_change_req_state(mdev, p->block_id, sector, | 5101 | err = validate_req_change_req_state(device, p->block_id, sector, |
5042 | &mdev->write_requests, __func__, | 5102 | &device->write_requests, __func__, |
5043 | NEG_ACKED, true); | 5103 | NEG_ACKED, true); |
5044 | if (err) { | 5104 | if (err) { |
5045 | /* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs. | 5105 | /* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs. |
@@ -5047,80 +5107,86 @@ static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi) | |||
5047 | request is no longer in the collision hash. */ | 5107 | request is no longer in the collision hash. */ |
5048 | /* In Protocol B we might already have got a P_RECV_ACK | 5108 | /* In Protocol B we might already have got a P_RECV_ACK |
5049 | but then get a P_NEG_ACK afterwards. */ | 5109 | but then get a P_NEG_ACK afterwards. */ |
5050 | drbd_set_out_of_sync(mdev, sector, size); | 5110 | drbd_set_out_of_sync(device, sector, size); |
5051 | } | 5111 | } |
5052 | return 0; | 5112 | return 0; |
5053 | } | 5113 | } |
5054 | 5114 | ||
5055 | static int got_NegDReply(struct drbd_tconn *tconn, struct packet_info *pi) | 5115 | static int got_NegDReply(struct drbd_connection *connection, struct packet_info *pi) |
5056 | { | 5116 | { |
5057 | struct drbd_conf *mdev; | 5117 | struct drbd_peer_device *peer_device; |
5118 | struct drbd_device *device; | ||
5058 | struct p_block_ack *p = pi->data; | 5119 | struct p_block_ack *p = pi->data; |
5059 | sector_t sector = be64_to_cpu(p->sector); | 5120 | sector_t sector = be64_to_cpu(p->sector); |
5060 | 5121 | ||
5061 | mdev = vnr_to_mdev(tconn, pi->vnr); | 5122 | peer_device = conn_peer_device(connection, pi->vnr); |
5062 | if (!mdev) | 5123 | if (!peer_device) |
5063 | return -EIO; | 5124 | return -EIO; |
5125 | device = peer_device->device; | ||
5064 | 5126 | ||
5065 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 5127 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
5066 | 5128 | ||
5067 | dev_err(DEV, "Got NegDReply; Sector %llus, len %u.\n", | 5129 | drbd_err(device, "Got NegDReply; Sector %llus, len %u.\n", |
5068 | (unsigned long long)sector, be32_to_cpu(p->blksize)); | 5130 | (unsigned long long)sector, be32_to_cpu(p->blksize)); |
5069 | 5131 | ||
5070 | return validate_req_change_req_state(mdev, p->block_id, sector, | 5132 | return validate_req_change_req_state(device, p->block_id, sector, |
5071 | &mdev->read_requests, __func__, | 5133 | &device->read_requests, __func__, |
5072 | NEG_ACKED, false); | 5134 | NEG_ACKED, false); |
5073 | } | 5135 | } |
5074 | 5136 | ||
5075 | static int got_NegRSDReply(struct drbd_tconn *tconn, struct packet_info *pi) | 5137 | static int got_NegRSDReply(struct drbd_connection *connection, struct packet_info *pi) |
5076 | { | 5138 | { |
5077 | struct drbd_conf *mdev; | 5139 | struct drbd_peer_device *peer_device; |
5140 | struct drbd_device *device; | ||
5078 | sector_t sector; | 5141 | sector_t sector; |
5079 | int size; | 5142 | int size; |
5080 | struct p_block_ack *p = pi->data; | 5143 | struct p_block_ack *p = pi->data; |
5081 | 5144 | ||
5082 | mdev = vnr_to_mdev(tconn, pi->vnr); | 5145 | peer_device = conn_peer_device(connection, pi->vnr); |
5083 | if (!mdev) | 5146 | if (!peer_device) |
5084 | return -EIO; | 5147 | return -EIO; |
5148 | device = peer_device->device; | ||
5085 | 5149 | ||
5086 | sector = be64_to_cpu(p->sector); | 5150 | sector = be64_to_cpu(p->sector); |
5087 | size = be32_to_cpu(p->blksize); | 5151 | size = be32_to_cpu(p->blksize); |
5088 | 5152 | ||
5089 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 5153 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
5090 | 5154 | ||
5091 | dec_rs_pending(mdev); | 5155 | dec_rs_pending(device); |
5092 | 5156 | ||
5093 | if (get_ldev_if_state(mdev, D_FAILED)) { | 5157 | if (get_ldev_if_state(device, D_FAILED)) { |
5094 | drbd_rs_complete_io(mdev, sector); | 5158 | drbd_rs_complete_io(device, sector); |
5095 | switch (pi->cmd) { | 5159 | switch (pi->cmd) { |
5096 | case P_NEG_RS_DREPLY: | 5160 | case P_NEG_RS_DREPLY: |
5097 | drbd_rs_failed_io(mdev, sector, size); | 5161 | drbd_rs_failed_io(device, sector, size); |
5098 | case P_RS_CANCEL: | 5162 | case P_RS_CANCEL: |
5099 | break; | 5163 | break; |
5100 | default: | 5164 | default: |
5101 | BUG(); | 5165 | BUG(); |
5102 | } | 5166 | } |
5103 | put_ldev(mdev); | 5167 | put_ldev(device); |
5104 | } | 5168 | } |
5105 | 5169 | ||
5106 | return 0; | 5170 | return 0; |
5107 | } | 5171 | } |
5108 | 5172 | ||
5109 | static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi) | 5173 | static int got_BarrierAck(struct drbd_connection *connection, struct packet_info *pi) |
5110 | { | 5174 | { |
5111 | struct p_barrier_ack *p = pi->data; | 5175 | struct p_barrier_ack *p = pi->data; |
5112 | struct drbd_conf *mdev; | 5176 | struct drbd_peer_device *peer_device; |
5113 | int vnr; | 5177 | int vnr; |
5114 | 5178 | ||
5115 | tl_release(tconn, p->barrier, be32_to_cpu(p->set_size)); | 5179 | tl_release(connection, p->barrier, be32_to_cpu(p->set_size)); |
5116 | 5180 | ||
5117 | rcu_read_lock(); | 5181 | rcu_read_lock(); |
5118 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 5182 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
5119 | if (mdev->state.conn == C_AHEAD && | 5183 | struct drbd_device *device = peer_device->device; |
5120 | atomic_read(&mdev->ap_in_flight) == 0 && | 5184 | |
5121 | !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &mdev->flags)) { | 5185 | if (device->state.conn == C_AHEAD && |
5122 | mdev->start_resync_timer.expires = jiffies + HZ; | 5186 | atomic_read(&device->ap_in_flight) == 0 && |
5123 | add_timer(&mdev->start_resync_timer); | 5187 | !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &device->flags)) { |
5188 | device->start_resync_timer.expires = jiffies + HZ; | ||
5189 | add_timer(&device->start_resync_timer); | ||
5124 | } | 5190 | } |
5125 | } | 5191 | } |
5126 | rcu_read_unlock(); | 5192 | rcu_read_unlock(); |
@@ -5128,90 +5194,94 @@ static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi) | |||
5128 | return 0; | 5194 | return 0; |
5129 | } | 5195 | } |
5130 | 5196 | ||
5131 | static int got_OVResult(struct drbd_tconn *tconn, struct packet_info *pi) | 5197 | static int got_OVResult(struct drbd_connection *connection, struct packet_info *pi) |
5132 | { | 5198 | { |
5133 | struct drbd_conf *mdev; | 5199 | struct drbd_peer_device *peer_device; |
5200 | struct drbd_device *device; | ||
5134 | struct p_block_ack *p = pi->data; | 5201 | struct p_block_ack *p = pi->data; |
5135 | struct drbd_work *w; | 5202 | struct drbd_device_work *dw; |
5136 | sector_t sector; | 5203 | sector_t sector; |
5137 | int size; | 5204 | int size; |
5138 | 5205 | ||
5139 | mdev = vnr_to_mdev(tconn, pi->vnr); | 5206 | peer_device = conn_peer_device(connection, pi->vnr); |
5140 | if (!mdev) | 5207 | if (!peer_device) |
5141 | return -EIO; | 5208 | return -EIO; |
5209 | device = peer_device->device; | ||
5142 | 5210 | ||
5143 | sector = be64_to_cpu(p->sector); | 5211 | sector = be64_to_cpu(p->sector); |
5144 | size = be32_to_cpu(p->blksize); | 5212 | size = be32_to_cpu(p->blksize); |
5145 | 5213 | ||
5146 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); | 5214 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
5147 | 5215 | ||
5148 | if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) | 5216 | if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) |
5149 | drbd_ov_out_of_sync_found(mdev, sector, size); | 5217 | drbd_ov_out_of_sync_found(device, sector, size); |
5150 | else | 5218 | else |
5151 | ov_out_of_sync_print(mdev); | 5219 | ov_out_of_sync_print(device); |
5152 | 5220 | ||
5153 | if (!get_ldev(mdev)) | 5221 | if (!get_ldev(device)) |
5154 | return 0; | 5222 | return 0; |
5155 | 5223 | ||
5156 | drbd_rs_complete_io(mdev, sector); | 5224 | drbd_rs_complete_io(device, sector); |
5157 | dec_rs_pending(mdev); | 5225 | dec_rs_pending(device); |
5158 | 5226 | ||
5159 | --mdev->ov_left; | 5227 | --device->ov_left; |
5160 | 5228 | ||
5161 | /* let's advance progress step marks only for every other megabyte */ | 5229 | /* let's advance progress step marks only for every other megabyte */ |
5162 | if ((mdev->ov_left & 0x200) == 0x200) | 5230 | if ((device->ov_left & 0x200) == 0x200) |
5163 | drbd_advance_rs_marks(mdev, mdev->ov_left); | 5231 | drbd_advance_rs_marks(device, device->ov_left); |
5164 | 5232 | ||
5165 | if (mdev->ov_left == 0) { | 5233 | if (device->ov_left == 0) { |
5166 | w = kmalloc(sizeof(*w), GFP_NOIO); | 5234 | dw = kmalloc(sizeof(*dw), GFP_NOIO); |
5167 | if (w) { | 5235 | if (dw) { |
5168 | w->cb = w_ov_finished; | 5236 | dw->w.cb = w_ov_finished; |
5169 | w->mdev = mdev; | 5237 | dw->device = device; |
5170 | drbd_queue_work(&mdev->tconn->sender_work, w); | 5238 | drbd_queue_work(&peer_device->connection->sender_work, &dw->w); |
5171 | } else { | 5239 | } else { |
5172 | dev_err(DEV, "kmalloc(w) failed."); | 5240 | drbd_err(device, "kmalloc(dw) failed."); |
5173 | ov_out_of_sync_print(mdev); | 5241 | ov_out_of_sync_print(device); |
5174 | drbd_resync_finished(mdev); | 5242 | drbd_resync_finished(device); |
5175 | } | 5243 | } |
5176 | } | 5244 | } |
5177 | put_ldev(mdev); | 5245 | put_ldev(device); |
5178 | return 0; | 5246 | return 0; |
5179 | } | 5247 | } |
5180 | 5248 | ||
5181 | static int got_skip(struct drbd_tconn *tconn, struct packet_info *pi) | 5249 | static int got_skip(struct drbd_connection *connection, struct packet_info *pi) |
5182 | { | 5250 | { |
5183 | return 0; | 5251 | return 0; |
5184 | } | 5252 | } |
5185 | 5253 | ||
5186 | static int tconn_finish_peer_reqs(struct drbd_tconn *tconn) | 5254 | static int connection_finish_peer_reqs(struct drbd_connection *connection) |
5187 | { | 5255 | { |
5188 | struct drbd_conf *mdev; | 5256 | struct drbd_peer_device *peer_device; |
5189 | int vnr, not_empty = 0; | 5257 | int vnr, not_empty = 0; |
5190 | 5258 | ||
5191 | do { | 5259 | do { |
5192 | clear_bit(SIGNAL_ASENDER, &tconn->flags); | 5260 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
5193 | flush_signals(current); | 5261 | flush_signals(current); |
5194 | 5262 | ||
5195 | rcu_read_lock(); | 5263 | rcu_read_lock(); |
5196 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 5264 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
5197 | kref_get(&mdev->kref); | 5265 | struct drbd_device *device = peer_device->device; |
5266 | kref_get(&device->kref); | ||
5198 | rcu_read_unlock(); | 5267 | rcu_read_unlock(); |
5199 | if (drbd_finish_peer_reqs(mdev)) { | 5268 | if (drbd_finish_peer_reqs(device)) { |
5200 | kref_put(&mdev->kref, &drbd_minor_destroy); | 5269 | kref_put(&device->kref, drbd_destroy_device); |
5201 | return 1; | 5270 | return 1; |
5202 | } | 5271 | } |
5203 | kref_put(&mdev->kref, &drbd_minor_destroy); | 5272 | kref_put(&device->kref, drbd_destroy_device); |
5204 | rcu_read_lock(); | 5273 | rcu_read_lock(); |
5205 | } | 5274 | } |
5206 | set_bit(SIGNAL_ASENDER, &tconn->flags); | 5275 | set_bit(SIGNAL_ASENDER, &connection->flags); |
5207 | 5276 | ||
5208 | spin_lock_irq(&tconn->req_lock); | 5277 | spin_lock_irq(&connection->resource->req_lock); |
5209 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 5278 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
5210 | not_empty = !list_empty(&mdev->done_ee); | 5279 | struct drbd_device *device = peer_device->device; |
5280 | not_empty = !list_empty(&device->done_ee); | ||
5211 | if (not_empty) | 5281 | if (not_empty) |
5212 | break; | 5282 | break; |
5213 | } | 5283 | } |
5214 | spin_unlock_irq(&tconn->req_lock); | 5284 | spin_unlock_irq(&connection->resource->req_lock); |
5215 | rcu_read_unlock(); | 5285 | rcu_read_unlock(); |
5216 | } while (not_empty); | 5286 | } while (not_empty); |
5217 | 5287 | ||
@@ -5220,7 +5290,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn) | |||
5220 | 5290 | ||
5221 | struct asender_cmd { | 5291 | struct asender_cmd { |
5222 | size_t pkt_size; | 5292 | size_t pkt_size; |
5223 | int (*fn)(struct drbd_tconn *tconn, struct packet_info *); | 5293 | int (*fn)(struct drbd_connection *connection, struct packet_info *); |
5224 | }; | 5294 | }; |
5225 | 5295 | ||
5226 | static struct asender_cmd asender_tbl[] = { | 5296 | static struct asender_cmd asender_tbl[] = { |
@@ -5245,13 +5315,13 @@ static struct asender_cmd asender_tbl[] = { | |||
5245 | 5315 | ||
5246 | int drbd_asender(struct drbd_thread *thi) | 5316 | int drbd_asender(struct drbd_thread *thi) |
5247 | { | 5317 | { |
5248 | struct drbd_tconn *tconn = thi->tconn; | 5318 | struct drbd_connection *connection = thi->connection; |
5249 | struct asender_cmd *cmd = NULL; | 5319 | struct asender_cmd *cmd = NULL; |
5250 | struct packet_info pi; | 5320 | struct packet_info pi; |
5251 | int rv; | 5321 | int rv; |
5252 | void *buf = tconn->meta.rbuf; | 5322 | void *buf = connection->meta.rbuf; |
5253 | int received = 0; | 5323 | int received = 0; |
5254 | unsigned int header_size = drbd_header_size(tconn); | 5324 | unsigned int header_size = drbd_header_size(connection); |
5255 | int expect = header_size; | 5325 | int expect = header_size; |
5256 | bool ping_timeout_active = false; | 5326 | bool ping_timeout_active = false; |
5257 | struct net_conf *nc; | 5327 | struct net_conf *nc; |
@@ -5260,45 +5330,45 @@ int drbd_asender(struct drbd_thread *thi) | |||
5260 | 5330 | ||
5261 | rv = sched_setscheduler(current, SCHED_RR, ¶m); | 5331 | rv = sched_setscheduler(current, SCHED_RR, ¶m); |
5262 | if (rv < 0) | 5332 | if (rv < 0) |
5263 | conn_err(tconn, "drbd_asender: ERROR set priority, ret=%d\n", rv); | 5333 | drbd_err(connection, "drbd_asender: ERROR set priority, ret=%d\n", rv); |
5264 | 5334 | ||
5265 | while (get_t_state(thi) == RUNNING) { | 5335 | while (get_t_state(thi) == RUNNING) { |
5266 | drbd_thread_current_set_cpu(thi); | 5336 | drbd_thread_current_set_cpu(thi); |
5267 | 5337 | ||
5268 | rcu_read_lock(); | 5338 | rcu_read_lock(); |
5269 | nc = rcu_dereference(tconn->net_conf); | 5339 | nc = rcu_dereference(connection->net_conf); |
5270 | ping_timeo = nc->ping_timeo; | 5340 | ping_timeo = nc->ping_timeo; |
5271 | tcp_cork = nc->tcp_cork; | 5341 | tcp_cork = nc->tcp_cork; |
5272 | ping_int = nc->ping_int; | 5342 | ping_int = nc->ping_int; |
5273 | rcu_read_unlock(); | 5343 | rcu_read_unlock(); |
5274 | 5344 | ||
5275 | if (test_and_clear_bit(SEND_PING, &tconn->flags)) { | 5345 | if (test_and_clear_bit(SEND_PING, &connection->flags)) { |
5276 | if (drbd_send_ping(tconn)) { | 5346 | if (drbd_send_ping(connection)) { |
5277 | conn_err(tconn, "drbd_send_ping has failed\n"); | 5347 | drbd_err(connection, "drbd_send_ping has failed\n"); |
5278 | goto reconnect; | 5348 | goto reconnect; |
5279 | } | 5349 | } |
5280 | tconn->meta.socket->sk->sk_rcvtimeo = ping_timeo * HZ / 10; | 5350 | connection->meta.socket->sk->sk_rcvtimeo = ping_timeo * HZ / 10; |
5281 | ping_timeout_active = true; | 5351 | ping_timeout_active = true; |
5282 | } | 5352 | } |
5283 | 5353 | ||
5284 | /* TODO: conditionally cork; it may hurt latency if we cork without | 5354 | /* TODO: conditionally cork; it may hurt latency if we cork without |
5285 | much to send */ | 5355 | much to send */ |
5286 | if (tcp_cork) | 5356 | if (tcp_cork) |
5287 | drbd_tcp_cork(tconn->meta.socket); | 5357 | drbd_tcp_cork(connection->meta.socket); |
5288 | if (tconn_finish_peer_reqs(tconn)) { | 5358 | if (connection_finish_peer_reqs(connection)) { |
5289 | conn_err(tconn, "tconn_finish_peer_reqs() failed\n"); | 5359 | drbd_err(connection, "connection_finish_peer_reqs() failed\n"); |
5290 | goto reconnect; | 5360 | goto reconnect; |
5291 | } | 5361 | } |
5292 | /* but unconditionally uncork unless disabled */ | 5362 | /* but unconditionally uncork unless disabled */ |
5293 | if (tcp_cork) | 5363 | if (tcp_cork) |
5294 | drbd_tcp_uncork(tconn->meta.socket); | 5364 | drbd_tcp_uncork(connection->meta.socket); |
5295 | 5365 | ||
5296 | /* short circuit, recv_msg would return EINTR anyways. */ | 5366 | /* short circuit, recv_msg would return EINTR anyways. */ |
5297 | if (signal_pending(current)) | 5367 | if (signal_pending(current)) |
5298 | continue; | 5368 | continue; |
5299 | 5369 | ||
5300 | rv = drbd_recv_short(tconn->meta.socket, buf, expect-received, 0); | 5370 | rv = drbd_recv_short(connection->meta.socket, buf, expect-received, 0); |
5301 | clear_bit(SIGNAL_ASENDER, &tconn->flags); | 5371 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
5302 | 5372 | ||
5303 | flush_signals(current); | 5373 | flush_signals(current); |
5304 | 5374 | ||
@@ -5316,51 +5386,51 @@ int drbd_asender(struct drbd_thread *thi) | |||
5316 | received += rv; | 5386 | received += rv; |
5317 | buf += rv; | 5387 | buf += rv; |
5318 | } else if (rv == 0) { | 5388 | } else if (rv == 0) { |
5319 | if (test_bit(DISCONNECT_SENT, &tconn->flags)) { | 5389 | if (test_bit(DISCONNECT_SENT, &connection->flags)) { |
5320 | long t; | 5390 | long t; |
5321 | rcu_read_lock(); | 5391 | rcu_read_lock(); |
5322 | t = rcu_dereference(tconn->net_conf)->ping_timeo * HZ/10; | 5392 | t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10; |
5323 | rcu_read_unlock(); | 5393 | rcu_read_unlock(); |
5324 | 5394 | ||
5325 | t = wait_event_timeout(tconn->ping_wait, | 5395 | t = wait_event_timeout(connection->ping_wait, |
5326 | tconn->cstate < C_WF_REPORT_PARAMS, | 5396 | connection->cstate < C_WF_REPORT_PARAMS, |
5327 | t); | 5397 | t); |
5328 | if (t) | 5398 | if (t) |
5329 | break; | 5399 | break; |
5330 | } | 5400 | } |
5331 | conn_err(tconn, "meta connection shut down by peer.\n"); | 5401 | drbd_err(connection, "meta connection shut down by peer.\n"); |
5332 | goto reconnect; | 5402 | goto reconnect; |
5333 | } else if (rv == -EAGAIN) { | 5403 | } else if (rv == -EAGAIN) { |
5334 | /* If the data socket received something meanwhile, | 5404 | /* If the data socket received something meanwhile, |
5335 | * that is good enough: peer is still alive. */ | 5405 | * that is good enough: peer is still alive. */ |
5336 | if (time_after(tconn->last_received, | 5406 | if (time_after(connection->last_received, |
5337 | jiffies - tconn->meta.socket->sk->sk_rcvtimeo)) | 5407 | jiffies - connection->meta.socket->sk->sk_rcvtimeo)) |
5338 | continue; | 5408 | continue; |
5339 | if (ping_timeout_active) { | 5409 | if (ping_timeout_active) { |
5340 | conn_err(tconn, "PingAck did not arrive in time.\n"); | 5410 | drbd_err(connection, "PingAck did not arrive in time.\n"); |
5341 | goto reconnect; | 5411 | goto reconnect; |
5342 | } | 5412 | } |
5343 | set_bit(SEND_PING, &tconn->flags); | 5413 | set_bit(SEND_PING, &connection->flags); |
5344 | continue; | 5414 | continue; |
5345 | } else if (rv == -EINTR) { | 5415 | } else if (rv == -EINTR) { |
5346 | continue; | 5416 | continue; |
5347 | } else { | 5417 | } else { |
5348 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); | 5418 | drbd_err(connection, "sock_recvmsg returned %d\n", rv); |
5349 | goto reconnect; | 5419 | goto reconnect; |
5350 | } | 5420 | } |
5351 | 5421 | ||
5352 | if (received == expect && cmd == NULL) { | 5422 | if (received == expect && cmd == NULL) { |
5353 | if (decode_header(tconn, tconn->meta.rbuf, &pi)) | 5423 | if (decode_header(connection, connection->meta.rbuf, &pi)) |
5354 | goto reconnect; | 5424 | goto reconnect; |
5355 | cmd = &asender_tbl[pi.cmd]; | 5425 | cmd = &asender_tbl[pi.cmd]; |
5356 | if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) { | 5426 | if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) { |
5357 | conn_err(tconn, "Unexpected meta packet %s (0x%04x)\n", | 5427 | drbd_err(connection, "Unexpected meta packet %s (0x%04x)\n", |
5358 | cmdname(pi.cmd), pi.cmd); | 5428 | cmdname(pi.cmd), pi.cmd); |
5359 | goto disconnect; | 5429 | goto disconnect; |
5360 | } | 5430 | } |
5361 | expect = header_size + cmd->pkt_size; | 5431 | expect = header_size + cmd->pkt_size; |
5362 | if (pi.size != expect - header_size) { | 5432 | if (pi.size != expect - header_size) { |
5363 | conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n", | 5433 | drbd_err(connection, "Wrong packet size on meta (c: %d, l: %d)\n", |
5364 | pi.cmd, pi.size); | 5434 | pi.cmd, pi.size); |
5365 | goto reconnect; | 5435 | goto reconnect; |
5366 | } | 5436 | } |
@@ -5368,21 +5438,21 @@ int drbd_asender(struct drbd_thread *thi) | |||
5368 | if (received == expect) { | 5438 | if (received == expect) { |
5369 | bool err; | 5439 | bool err; |
5370 | 5440 | ||
5371 | err = cmd->fn(tconn, &pi); | 5441 | err = cmd->fn(connection, &pi); |
5372 | if (err) { | 5442 | if (err) { |
5373 | conn_err(tconn, "%pf failed\n", cmd->fn); | 5443 | drbd_err(connection, "%pf failed\n", cmd->fn); |
5374 | goto reconnect; | 5444 | goto reconnect; |
5375 | } | 5445 | } |
5376 | 5446 | ||
5377 | tconn->last_received = jiffies; | 5447 | connection->last_received = jiffies; |
5378 | 5448 | ||
5379 | if (cmd == &asender_tbl[P_PING_ACK]) { | 5449 | if (cmd == &asender_tbl[P_PING_ACK]) { |
5380 | /* restore idle timeout */ | 5450 | /* restore idle timeout */ |
5381 | tconn->meta.socket->sk->sk_rcvtimeo = ping_int * HZ; | 5451 | connection->meta.socket->sk->sk_rcvtimeo = ping_int * HZ; |
5382 | ping_timeout_active = false; | 5452 | ping_timeout_active = false; |
5383 | } | 5453 | } |
5384 | 5454 | ||
5385 | buf = tconn->meta.rbuf; | 5455 | buf = connection->meta.rbuf; |
5386 | received = 0; | 5456 | received = 0; |
5387 | expect = header_size; | 5457 | expect = header_size; |
5388 | cmd = NULL; | 5458 | cmd = NULL; |
@@ -5391,16 +5461,16 @@ int drbd_asender(struct drbd_thread *thi) | |||
5391 | 5461 | ||
5392 | if (0) { | 5462 | if (0) { |
5393 | reconnect: | 5463 | reconnect: |
5394 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); | 5464 | conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
5395 | conn_md_sync(tconn); | 5465 | conn_md_sync(connection); |
5396 | } | 5466 | } |
5397 | if (0) { | 5467 | if (0) { |
5398 | disconnect: | 5468 | disconnect: |
5399 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 5469 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
5400 | } | 5470 | } |
5401 | clear_bit(SIGNAL_ASENDER, &tconn->flags); | 5471 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
5402 | 5472 | ||
5403 | conn_info(tconn, "asender terminated\n"); | 5473 | drbd_info(connection, "asender terminated\n"); |
5404 | 5474 | ||
5405 | return 0; | 5475 | return 0; |
5406 | } | 5476 | } |
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c index 104a040f24de..3779c8d2875b 100644 --- a/drivers/block/drbd/drbd_req.c +++ b/drivers/block/drbd/drbd_req.c | |||
@@ -31,37 +31,37 @@ | |||
31 | #include "drbd_req.h" | 31 | #include "drbd_req.h" |
32 | 32 | ||
33 | 33 | ||
34 | static bool drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size); | 34 | static bool drbd_may_do_local_read(struct drbd_device *device, sector_t sector, int size); |
35 | 35 | ||
36 | /* Update disk stats at start of I/O request */ | 36 | /* Update disk stats at start of I/O request */ |
37 | static void _drbd_start_io_acct(struct drbd_conf *mdev, struct drbd_request *req) | 37 | static void _drbd_start_io_acct(struct drbd_device *device, struct drbd_request *req) |
38 | { | 38 | { |
39 | const int rw = bio_data_dir(req->master_bio); | 39 | const int rw = bio_data_dir(req->master_bio); |
40 | int cpu; | 40 | int cpu; |
41 | cpu = part_stat_lock(); | 41 | cpu = part_stat_lock(); |
42 | part_round_stats(cpu, &mdev->vdisk->part0); | 42 | part_round_stats(cpu, &device->vdisk->part0); |
43 | part_stat_inc(cpu, &mdev->vdisk->part0, ios[rw]); | 43 | part_stat_inc(cpu, &device->vdisk->part0, ios[rw]); |
44 | part_stat_add(cpu, &mdev->vdisk->part0, sectors[rw], req->i.size >> 9); | 44 | part_stat_add(cpu, &device->vdisk->part0, sectors[rw], req->i.size >> 9); |
45 | (void) cpu; /* The macro invocations above want the cpu argument, I do not like | 45 | (void) cpu; /* The macro invocations above want the cpu argument, I do not like |
46 | the compiler warning about cpu only assigned but never used... */ | 46 | the compiler warning about cpu only assigned but never used... */ |
47 | part_inc_in_flight(&mdev->vdisk->part0, rw); | 47 | part_inc_in_flight(&device->vdisk->part0, rw); |
48 | part_stat_unlock(); | 48 | part_stat_unlock(); |
49 | } | 49 | } |
50 | 50 | ||
51 | /* Update disk stats when completing request upwards */ | 51 | /* Update disk stats when completing request upwards */ |
52 | static void _drbd_end_io_acct(struct drbd_conf *mdev, struct drbd_request *req) | 52 | static void _drbd_end_io_acct(struct drbd_device *device, struct drbd_request *req) |
53 | { | 53 | { |
54 | int rw = bio_data_dir(req->master_bio); | 54 | int rw = bio_data_dir(req->master_bio); |
55 | unsigned long duration = jiffies - req->start_time; | 55 | unsigned long duration = jiffies - req->start_time; |
56 | int cpu; | 56 | int cpu; |
57 | cpu = part_stat_lock(); | 57 | cpu = part_stat_lock(); |
58 | part_stat_add(cpu, &mdev->vdisk->part0, ticks[rw], duration); | 58 | part_stat_add(cpu, &device->vdisk->part0, ticks[rw], duration); |
59 | part_round_stats(cpu, &mdev->vdisk->part0); | 59 | part_round_stats(cpu, &device->vdisk->part0); |
60 | part_dec_in_flight(&mdev->vdisk->part0, rw); | 60 | part_dec_in_flight(&device->vdisk->part0, rw); |
61 | part_stat_unlock(); | 61 | part_stat_unlock(); |
62 | } | 62 | } |
63 | 63 | ||
64 | static struct drbd_request *drbd_req_new(struct drbd_conf *mdev, | 64 | static struct drbd_request *drbd_req_new(struct drbd_device *device, |
65 | struct bio *bio_src) | 65 | struct bio *bio_src) |
66 | { | 66 | { |
67 | struct drbd_request *req; | 67 | struct drbd_request *req; |
@@ -72,7 +72,7 @@ static struct drbd_request *drbd_req_new(struct drbd_conf *mdev, | |||
72 | 72 | ||
73 | drbd_req_make_private_bio(req, bio_src); | 73 | drbd_req_make_private_bio(req, bio_src); |
74 | req->rq_state = bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0; | 74 | req->rq_state = bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0; |
75 | req->w.mdev = mdev; | 75 | req->device = device; |
76 | req->master_bio = bio_src; | 76 | req->master_bio = bio_src; |
77 | req->epoch = 0; | 77 | req->epoch = 0; |
78 | 78 | ||
@@ -95,14 +95,14 @@ static struct drbd_request *drbd_req_new(struct drbd_conf *mdev, | |||
95 | void drbd_req_destroy(struct kref *kref) | 95 | void drbd_req_destroy(struct kref *kref) |
96 | { | 96 | { |
97 | struct drbd_request *req = container_of(kref, struct drbd_request, kref); | 97 | struct drbd_request *req = container_of(kref, struct drbd_request, kref); |
98 | struct drbd_conf *mdev = req->w.mdev; | 98 | struct drbd_device *device = req->device; |
99 | const unsigned s = req->rq_state; | 99 | const unsigned s = req->rq_state; |
100 | 100 | ||
101 | if ((req->master_bio && !(s & RQ_POSTPONED)) || | 101 | if ((req->master_bio && !(s & RQ_POSTPONED)) || |
102 | atomic_read(&req->completion_ref) || | 102 | atomic_read(&req->completion_ref) || |
103 | (s & RQ_LOCAL_PENDING) || | 103 | (s & RQ_LOCAL_PENDING) || |
104 | ((s & RQ_NET_MASK) && !(s & RQ_NET_DONE))) { | 104 | ((s & RQ_NET_MASK) && !(s & RQ_NET_DONE))) { |
105 | dev_err(DEV, "drbd_req_destroy: Logic BUG rq_state = 0x%x, completion_ref = %d\n", | 105 | drbd_err(device, "drbd_req_destroy: Logic BUG rq_state = 0x%x, completion_ref = %d\n", |
106 | s, atomic_read(&req->completion_ref)); | 106 | s, atomic_read(&req->completion_ref)); |
107 | return; | 107 | return; |
108 | } | 108 | } |
@@ -132,10 +132,10 @@ void drbd_req_destroy(struct kref *kref) | |||
132 | */ | 132 | */ |
133 | if ((s & (RQ_POSTPONED|RQ_LOCAL_MASK|RQ_NET_MASK)) != RQ_POSTPONED) { | 133 | if ((s & (RQ_POSTPONED|RQ_LOCAL_MASK|RQ_NET_MASK)) != RQ_POSTPONED) { |
134 | if (!(s & RQ_NET_OK) || !(s & RQ_LOCAL_OK)) | 134 | if (!(s & RQ_NET_OK) || !(s & RQ_LOCAL_OK)) |
135 | drbd_set_out_of_sync(mdev, req->i.sector, req->i.size); | 135 | drbd_set_out_of_sync(device, req->i.sector, req->i.size); |
136 | 136 | ||
137 | if ((s & RQ_NET_OK) && (s & RQ_LOCAL_OK) && (s & RQ_NET_SIS)) | 137 | if ((s & RQ_NET_OK) && (s & RQ_LOCAL_OK) && (s & RQ_NET_SIS)) |
138 | drbd_set_in_sync(mdev, req->i.sector, req->i.size); | 138 | drbd_set_in_sync(device, req->i.sector, req->i.size); |
139 | } | 139 | } |
140 | 140 | ||
141 | /* one might be tempted to move the drbd_al_complete_io | 141 | /* one might be tempted to move the drbd_al_complete_io |
@@ -149,11 +149,11 @@ void drbd_req_destroy(struct kref *kref) | |||
149 | * we would forget to resync the corresponding extent. | 149 | * we would forget to resync the corresponding extent. |
150 | */ | 150 | */ |
151 | if (s & RQ_IN_ACT_LOG) { | 151 | if (s & RQ_IN_ACT_LOG) { |
152 | if (get_ldev_if_state(mdev, D_FAILED)) { | 152 | if (get_ldev_if_state(device, D_FAILED)) { |
153 | drbd_al_complete_io(mdev, &req->i); | 153 | drbd_al_complete_io(device, &req->i); |
154 | put_ldev(mdev); | 154 | put_ldev(device); |
155 | } else if (__ratelimit(&drbd_ratelimit_state)) { | 155 | } else if (__ratelimit(&drbd_ratelimit_state)) { |
156 | dev_warn(DEV, "Should have called drbd_al_complete_io(, %llu, %u), " | 156 | drbd_warn(device, "Should have called drbd_al_complete_io(, %llu, %u), " |
157 | "but my Disk seems to have failed :(\n", | 157 | "but my Disk seems to have failed :(\n", |
158 | (unsigned long long) req->i.sector, req->i.size); | 158 | (unsigned long long) req->i.sector, req->i.size); |
159 | } | 159 | } |
@@ -163,41 +163,42 @@ void drbd_req_destroy(struct kref *kref) | |||
163 | mempool_free(req, drbd_request_mempool); | 163 | mempool_free(req, drbd_request_mempool); |
164 | } | 164 | } |
165 | 165 | ||
166 | static void wake_all_senders(struct drbd_tconn *tconn) { | 166 | static void wake_all_senders(struct drbd_connection *connection) |
167 | wake_up(&tconn->sender_work.q_wait); | 167 | { |
168 | wake_up(&connection->sender_work.q_wait); | ||
168 | } | 169 | } |
169 | 170 | ||
170 | /* must hold resource->req_lock */ | 171 | /* must hold resource->req_lock */ |
171 | void start_new_tl_epoch(struct drbd_tconn *tconn) | 172 | void start_new_tl_epoch(struct drbd_connection *connection) |
172 | { | 173 | { |
173 | /* no point closing an epoch, if it is empty, anyways. */ | 174 | /* no point closing an epoch, if it is empty, anyways. */ |
174 | if (tconn->current_tle_writes == 0) | 175 | if (connection->current_tle_writes == 0) |
175 | return; | 176 | return; |
176 | 177 | ||
177 | tconn->current_tle_writes = 0; | 178 | connection->current_tle_writes = 0; |
178 | atomic_inc(&tconn->current_tle_nr); | 179 | atomic_inc(&connection->current_tle_nr); |
179 | wake_all_senders(tconn); | 180 | wake_all_senders(connection); |
180 | } | 181 | } |
181 | 182 | ||
182 | void complete_master_bio(struct drbd_conf *mdev, | 183 | void complete_master_bio(struct drbd_device *device, |
183 | struct bio_and_error *m) | 184 | struct bio_and_error *m) |
184 | { | 185 | { |
185 | bio_endio(m->bio, m->error); | 186 | bio_endio(m->bio, m->error); |
186 | dec_ap_bio(mdev); | 187 | dec_ap_bio(device); |
187 | } | 188 | } |
188 | 189 | ||
189 | 190 | ||
190 | static void drbd_remove_request_interval(struct rb_root *root, | 191 | static void drbd_remove_request_interval(struct rb_root *root, |
191 | struct drbd_request *req) | 192 | struct drbd_request *req) |
192 | { | 193 | { |
193 | struct drbd_conf *mdev = req->w.mdev; | 194 | struct drbd_device *device = req->device; |
194 | struct drbd_interval *i = &req->i; | 195 | struct drbd_interval *i = &req->i; |
195 | 196 | ||
196 | drbd_remove_interval(root, i); | 197 | drbd_remove_interval(root, i); |
197 | 198 | ||
198 | /* Wake up any processes waiting for this request to complete. */ | 199 | /* Wake up any processes waiting for this request to complete. */ |
199 | if (i->waiting) | 200 | if (i->waiting) |
200 | wake_up(&mdev->misc_wait); | 201 | wake_up(&device->misc_wait); |
201 | } | 202 | } |
202 | 203 | ||
203 | /* Helper for __req_mod(). | 204 | /* Helper for __req_mod(). |
@@ -210,7 +211,7 @@ static | |||
210 | void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) | 211 | void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) |
211 | { | 212 | { |
212 | const unsigned s = req->rq_state; | 213 | const unsigned s = req->rq_state; |
213 | struct drbd_conf *mdev = req->w.mdev; | 214 | struct drbd_device *device = req->device; |
214 | int rw; | 215 | int rw; |
215 | int error, ok; | 216 | int error, ok; |
216 | 217 | ||
@@ -226,12 +227,12 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) | |||
226 | if ((s & RQ_LOCAL_PENDING && !(s & RQ_LOCAL_ABORTED)) || | 227 | if ((s & RQ_LOCAL_PENDING && !(s & RQ_LOCAL_ABORTED)) || |
227 | (s & RQ_NET_QUEUED) || (s & RQ_NET_PENDING) || | 228 | (s & RQ_NET_QUEUED) || (s & RQ_NET_PENDING) || |
228 | (s & RQ_COMPLETION_SUSP)) { | 229 | (s & RQ_COMPLETION_SUSP)) { |
229 | dev_err(DEV, "drbd_req_complete: Logic BUG rq_state = 0x%x\n", s); | 230 | drbd_err(device, "drbd_req_complete: Logic BUG rq_state = 0x%x\n", s); |
230 | return; | 231 | return; |
231 | } | 232 | } |
232 | 233 | ||
233 | if (!req->master_bio) { | 234 | if (!req->master_bio) { |
234 | dev_err(DEV, "drbd_req_complete: Logic BUG, master_bio == NULL!\n"); | 235 | drbd_err(device, "drbd_req_complete: Logic BUG, master_bio == NULL!\n"); |
235 | return; | 236 | return; |
236 | } | 237 | } |
237 | 238 | ||
@@ -259,9 +260,9 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) | |||
259 | struct rb_root *root; | 260 | struct rb_root *root; |
260 | 261 | ||
261 | if (rw == WRITE) | 262 | if (rw == WRITE) |
262 | root = &mdev->write_requests; | 263 | root = &device->write_requests; |
263 | else | 264 | else |
264 | root = &mdev->read_requests; | 265 | root = &device->read_requests; |
265 | drbd_remove_request_interval(root, req); | 266 | drbd_remove_request_interval(root, req); |
266 | } | 267 | } |
267 | 268 | ||
@@ -273,11 +274,11 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) | |||
273 | * and reset the transfer log epoch write_cnt. | 274 | * and reset the transfer log epoch write_cnt. |
274 | */ | 275 | */ |
275 | if (rw == WRITE && | 276 | if (rw == WRITE && |
276 | req->epoch == atomic_read(&mdev->tconn->current_tle_nr)) | 277 | req->epoch == atomic_read(&first_peer_device(device)->connection->current_tle_nr)) |
277 | start_new_tl_epoch(mdev->tconn); | 278 | start_new_tl_epoch(first_peer_device(device)->connection); |
278 | 279 | ||
279 | /* Update disk stats */ | 280 | /* Update disk stats */ |
280 | _drbd_end_io_acct(mdev, req); | 281 | _drbd_end_io_acct(device, req); |
281 | 282 | ||
282 | /* If READ failed, | 283 | /* If READ failed, |
283 | * have it be pushed back to the retry work queue, | 284 | * have it be pushed back to the retry work queue, |
@@ -305,8 +306,8 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m) | |||
305 | 306 | ||
306 | static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_error *m, int put) | 307 | static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_error *m, int put) |
307 | { | 308 | { |
308 | struct drbd_conf *mdev = req->w.mdev; | 309 | struct drbd_device *device = req->device; |
309 | D_ASSERT(m || (req->rq_state & RQ_POSTPONED)); | 310 | D_ASSERT(device, m || (req->rq_state & RQ_POSTPONED)); |
310 | 311 | ||
311 | if (!atomic_sub_and_test(put, &req->completion_ref)) | 312 | if (!atomic_sub_and_test(put, &req->completion_ref)) |
312 | return 0; | 313 | return 0; |
@@ -328,12 +329,12 @@ static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_ | |||
328 | static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | 329 | static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, |
329 | int clear, int set) | 330 | int clear, int set) |
330 | { | 331 | { |
331 | struct drbd_conf *mdev = req->w.mdev; | 332 | struct drbd_device *device = req->device; |
332 | unsigned s = req->rq_state; | 333 | unsigned s = req->rq_state; |
333 | int c_put = 0; | 334 | int c_put = 0; |
334 | int k_put = 0; | 335 | int k_put = 0; |
335 | 336 | ||
336 | if (drbd_suspended(mdev) && !((s | clear) & RQ_COMPLETION_SUSP)) | 337 | if (drbd_suspended(device) && !((s | clear) & RQ_COMPLETION_SUSP)) |
337 | set |= RQ_COMPLETION_SUSP; | 338 | set |= RQ_COMPLETION_SUSP; |
338 | 339 | ||
339 | /* apply */ | 340 | /* apply */ |
@@ -351,7 +352,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
351 | atomic_inc(&req->completion_ref); | 352 | atomic_inc(&req->completion_ref); |
352 | 353 | ||
353 | if (!(s & RQ_NET_PENDING) && (set & RQ_NET_PENDING)) { | 354 | if (!(s & RQ_NET_PENDING) && (set & RQ_NET_PENDING)) { |
354 | inc_ap_pending(mdev); | 355 | inc_ap_pending(device); |
355 | atomic_inc(&req->completion_ref); | 356 | atomic_inc(&req->completion_ref); |
356 | } | 357 | } |
357 | 358 | ||
@@ -362,7 +363,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
362 | kref_get(&req->kref); /* wait for the DONE */ | 363 | kref_get(&req->kref); /* wait for the DONE */ |
363 | 364 | ||
364 | if (!(s & RQ_NET_SENT) && (set & RQ_NET_SENT)) | 365 | if (!(s & RQ_NET_SENT) && (set & RQ_NET_SENT)) |
365 | atomic_add(req->i.size >> 9, &mdev->ap_in_flight); | 366 | atomic_add(req->i.size >> 9, &device->ap_in_flight); |
366 | 367 | ||
367 | if (!(s & RQ_COMPLETION_SUSP) && (set & RQ_COMPLETION_SUSP)) | 368 | if (!(s & RQ_COMPLETION_SUSP) && (set & RQ_COMPLETION_SUSP)) |
368 | atomic_inc(&req->completion_ref); | 369 | atomic_inc(&req->completion_ref); |
@@ -373,7 +374,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
373 | ++c_put; | 374 | ++c_put; |
374 | 375 | ||
375 | if (!(s & RQ_LOCAL_ABORTED) && (set & RQ_LOCAL_ABORTED)) { | 376 | if (!(s & RQ_LOCAL_ABORTED) && (set & RQ_LOCAL_ABORTED)) { |
376 | D_ASSERT(req->rq_state & RQ_LOCAL_PENDING); | 377 | D_ASSERT(device, req->rq_state & RQ_LOCAL_PENDING); |
377 | /* local completion may still come in later, | 378 | /* local completion may still come in later, |
378 | * we need to keep the req object around. */ | 379 | * we need to keep the req object around. */ |
379 | kref_get(&req->kref); | 380 | kref_get(&req->kref); |
@@ -388,7 +389,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
388 | } | 389 | } |
389 | 390 | ||
390 | if ((s & RQ_NET_PENDING) && (clear & RQ_NET_PENDING)) { | 391 | if ((s & RQ_NET_PENDING) && (clear & RQ_NET_PENDING)) { |
391 | dec_ap_pending(mdev); | 392 | dec_ap_pending(device); |
392 | ++c_put; | 393 | ++c_put; |
393 | } | 394 | } |
394 | 395 | ||
@@ -397,7 +398,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
397 | 398 | ||
398 | if ((s & RQ_EXP_BARR_ACK) && !(s & RQ_NET_DONE) && (set & RQ_NET_DONE)) { | 399 | if ((s & RQ_EXP_BARR_ACK) && !(s & RQ_NET_DONE) && (set & RQ_NET_DONE)) { |
399 | if (req->rq_state & RQ_NET_SENT) | 400 | if (req->rq_state & RQ_NET_SENT) |
400 | atomic_sub(req->i.size >> 9, &mdev->ap_in_flight); | 401 | atomic_sub(req->i.size >> 9, &device->ap_in_flight); |
401 | ++k_put; | 402 | ++k_put; |
402 | } | 403 | } |
403 | 404 | ||
@@ -409,14 +410,14 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
409 | int at_least = k_put + !!c_put; | 410 | int at_least = k_put + !!c_put; |
410 | int refcount = atomic_read(&req->kref.refcount); | 411 | int refcount = atomic_read(&req->kref.refcount); |
411 | if (refcount < at_least) | 412 | if (refcount < at_least) |
412 | dev_err(DEV, | 413 | drbd_err(device, |
413 | "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n", | 414 | "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n", |
414 | s, req->rq_state, refcount, at_least); | 415 | s, req->rq_state, refcount, at_least); |
415 | } | 416 | } |
416 | 417 | ||
417 | /* If we made progress, retry conflicting peer requests, if any. */ | 418 | /* If we made progress, retry conflicting peer requests, if any. */ |
418 | if (req->i.waiting) | 419 | if (req->i.waiting) |
419 | wake_up(&mdev->misc_wait); | 420 | wake_up(&device->misc_wait); |
420 | 421 | ||
421 | if (c_put) | 422 | if (c_put) |
422 | k_put += drbd_req_put_completion_ref(req, m, c_put); | 423 | k_put += drbd_req_put_completion_ref(req, m, c_put); |
@@ -424,18 +425,18 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m, | |||
424 | kref_sub(&req->kref, k_put, drbd_req_destroy); | 425 | kref_sub(&req->kref, k_put, drbd_req_destroy); |
425 | } | 426 | } |
426 | 427 | ||
427 | static void drbd_report_io_error(struct drbd_conf *mdev, struct drbd_request *req) | 428 | static void drbd_report_io_error(struct drbd_device *device, struct drbd_request *req) |
428 | { | 429 | { |
429 | char b[BDEVNAME_SIZE]; | 430 | char b[BDEVNAME_SIZE]; |
430 | 431 | ||
431 | if (!__ratelimit(&drbd_ratelimit_state)) | 432 | if (!__ratelimit(&drbd_ratelimit_state)) |
432 | return; | 433 | return; |
433 | 434 | ||
434 | dev_warn(DEV, "local %s IO error sector %llu+%u on %s\n", | 435 | drbd_warn(device, "local %s IO error sector %llu+%u on %s\n", |
435 | (req->rq_state & RQ_WRITE) ? "WRITE" : "READ", | 436 | (req->rq_state & RQ_WRITE) ? "WRITE" : "READ", |
436 | (unsigned long long)req->i.sector, | 437 | (unsigned long long)req->i.sector, |
437 | req->i.size >> 9, | 438 | req->i.size >> 9, |
438 | bdevname(mdev->ldev->backing_bdev, b)); | 439 | bdevname(device->ldev->backing_bdev, b)); |
439 | } | 440 | } |
440 | 441 | ||
441 | /* obviously this could be coded as many single functions | 442 | /* obviously this could be coded as many single functions |
@@ -453,7 +454,7 @@ static void drbd_report_io_error(struct drbd_conf *mdev, struct drbd_request *re | |||
453 | int __req_mod(struct drbd_request *req, enum drbd_req_event what, | 454 | int __req_mod(struct drbd_request *req, enum drbd_req_event what, |
454 | struct bio_and_error *m) | 455 | struct bio_and_error *m) |
455 | { | 456 | { |
456 | struct drbd_conf *mdev = req->w.mdev; | 457 | struct drbd_device *device = req->device; |
457 | struct net_conf *nc; | 458 | struct net_conf *nc; |
458 | int p, rv = 0; | 459 | int p, rv = 0; |
459 | 460 | ||
@@ -462,7 +463,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
462 | 463 | ||
463 | switch (what) { | 464 | switch (what) { |
464 | default: | 465 | default: |
465 | dev_err(DEV, "LOGIC BUG in %s:%u\n", __FILE__ , __LINE__); | 466 | drbd_err(device, "LOGIC BUG in %s:%u\n", __FILE__ , __LINE__); |
466 | break; | 467 | break; |
467 | 468 | ||
468 | /* does not happen... | 469 | /* does not happen... |
@@ -474,9 +475,9 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
474 | case TO_BE_SENT: /* via network */ | 475 | case TO_BE_SENT: /* via network */ |
475 | /* reached via __drbd_make_request | 476 | /* reached via __drbd_make_request |
476 | * and from w_read_retry_remote */ | 477 | * and from w_read_retry_remote */ |
477 | D_ASSERT(!(req->rq_state & RQ_NET_MASK)); | 478 | D_ASSERT(device, !(req->rq_state & RQ_NET_MASK)); |
478 | rcu_read_lock(); | 479 | rcu_read_lock(); |
479 | nc = rcu_dereference(mdev->tconn->net_conf); | 480 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
480 | p = nc->wire_protocol; | 481 | p = nc->wire_protocol; |
481 | rcu_read_unlock(); | 482 | rcu_read_unlock(); |
482 | req->rq_state |= | 483 | req->rq_state |= |
@@ -487,15 +488,15 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
487 | 488 | ||
488 | case TO_BE_SUBMITTED: /* locally */ | 489 | case TO_BE_SUBMITTED: /* locally */ |
489 | /* reached via __drbd_make_request */ | 490 | /* reached via __drbd_make_request */ |
490 | D_ASSERT(!(req->rq_state & RQ_LOCAL_MASK)); | 491 | D_ASSERT(device, !(req->rq_state & RQ_LOCAL_MASK)); |
491 | mod_rq_state(req, m, 0, RQ_LOCAL_PENDING); | 492 | mod_rq_state(req, m, 0, RQ_LOCAL_PENDING); |
492 | break; | 493 | break; |
493 | 494 | ||
494 | case COMPLETED_OK: | 495 | case COMPLETED_OK: |
495 | if (req->rq_state & RQ_WRITE) | 496 | if (req->rq_state & RQ_WRITE) |
496 | mdev->writ_cnt += req->i.size >> 9; | 497 | device->writ_cnt += req->i.size >> 9; |
497 | else | 498 | else |
498 | mdev->read_cnt += req->i.size >> 9; | 499 | device->read_cnt += req->i.size >> 9; |
499 | 500 | ||
500 | mod_rq_state(req, m, RQ_LOCAL_PENDING, | 501 | mod_rq_state(req, m, RQ_LOCAL_PENDING, |
501 | RQ_LOCAL_COMPLETED|RQ_LOCAL_OK); | 502 | RQ_LOCAL_COMPLETED|RQ_LOCAL_OK); |
@@ -506,15 +507,15 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
506 | break; | 507 | break; |
507 | 508 | ||
508 | case WRITE_COMPLETED_WITH_ERROR: | 509 | case WRITE_COMPLETED_WITH_ERROR: |
509 | drbd_report_io_error(mdev, req); | 510 | drbd_report_io_error(device, req); |
510 | __drbd_chk_io_error(mdev, DRBD_WRITE_ERROR); | 511 | __drbd_chk_io_error(device, DRBD_WRITE_ERROR); |
511 | mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED); | 512 | mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED); |
512 | break; | 513 | break; |
513 | 514 | ||
514 | case READ_COMPLETED_WITH_ERROR: | 515 | case READ_COMPLETED_WITH_ERROR: |
515 | drbd_set_out_of_sync(mdev, req->i.sector, req->i.size); | 516 | drbd_set_out_of_sync(device, req->i.sector, req->i.size); |
516 | drbd_report_io_error(mdev, req); | 517 | drbd_report_io_error(device, req); |
517 | __drbd_chk_io_error(mdev, DRBD_READ_ERROR); | 518 | __drbd_chk_io_error(device, DRBD_READ_ERROR); |
518 | /* fall through. */ | 519 | /* fall through. */ |
519 | case READ_AHEAD_COMPLETED_WITH_ERROR: | 520 | case READ_AHEAD_COMPLETED_WITH_ERROR: |
520 | /* it is legal to fail READA, no __drbd_chk_io_error in that case. */ | 521 | /* it is legal to fail READA, no __drbd_chk_io_error in that case. */ |
@@ -532,16 +533,17 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
532 | /* So we can verify the handle in the answer packet. | 533 | /* So we can verify the handle in the answer packet. |
533 | * Corresponding drbd_remove_request_interval is in | 534 | * Corresponding drbd_remove_request_interval is in |
534 | * drbd_req_complete() */ | 535 | * drbd_req_complete() */ |
535 | D_ASSERT(drbd_interval_empty(&req->i)); | 536 | D_ASSERT(device, drbd_interval_empty(&req->i)); |
536 | drbd_insert_interval(&mdev->read_requests, &req->i); | 537 | drbd_insert_interval(&device->read_requests, &req->i); |
537 | 538 | ||
538 | set_bit(UNPLUG_REMOTE, &mdev->flags); | 539 | set_bit(UNPLUG_REMOTE, &device->flags); |
539 | 540 | ||
540 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 541 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
541 | D_ASSERT((req->rq_state & RQ_LOCAL_MASK) == 0); | 542 | D_ASSERT(device, (req->rq_state & RQ_LOCAL_MASK) == 0); |
542 | mod_rq_state(req, m, 0, RQ_NET_QUEUED); | 543 | mod_rq_state(req, m, 0, RQ_NET_QUEUED); |
543 | req->w.cb = w_send_read_req; | 544 | req->w.cb = w_send_read_req; |
544 | drbd_queue_work(&mdev->tconn->sender_work, &req->w); | 545 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
546 | &req->w); | ||
545 | break; | 547 | break; |
546 | 548 | ||
547 | case QUEUE_FOR_NET_WRITE: | 549 | case QUEUE_FOR_NET_WRITE: |
@@ -550,8 +552,8 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
550 | 552 | ||
551 | /* Corresponding drbd_remove_request_interval is in | 553 | /* Corresponding drbd_remove_request_interval is in |
552 | * drbd_req_complete() */ | 554 | * drbd_req_complete() */ |
553 | D_ASSERT(drbd_interval_empty(&req->i)); | 555 | D_ASSERT(device, drbd_interval_empty(&req->i)); |
554 | drbd_insert_interval(&mdev->write_requests, &req->i); | 556 | drbd_insert_interval(&device->write_requests, &req->i); |
555 | 557 | ||
556 | /* NOTE | 558 | /* NOTE |
557 | * In case the req ended up on the transfer log before being | 559 | * In case the req ended up on the transfer log before being |
@@ -570,28 +572,30 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
570 | /* otherwise we may lose an unplug, which may cause some remote | 572 | /* otherwise we may lose an unplug, which may cause some remote |
571 | * io-scheduler timeout to expire, increasing maximum latency, | 573 | * io-scheduler timeout to expire, increasing maximum latency, |
572 | * hurting performance. */ | 574 | * hurting performance. */ |
573 | set_bit(UNPLUG_REMOTE, &mdev->flags); | 575 | set_bit(UNPLUG_REMOTE, &device->flags); |
574 | 576 | ||
575 | /* queue work item to send data */ | 577 | /* queue work item to send data */ |
576 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 578 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
577 | mod_rq_state(req, m, 0, RQ_NET_QUEUED|RQ_EXP_BARR_ACK); | 579 | mod_rq_state(req, m, 0, RQ_NET_QUEUED|RQ_EXP_BARR_ACK); |
578 | req->w.cb = w_send_dblock; | 580 | req->w.cb = w_send_dblock; |
579 | drbd_queue_work(&mdev->tconn->sender_work, &req->w); | 581 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
582 | &req->w); | ||
580 | 583 | ||
581 | /* close the epoch, in case it outgrew the limit */ | 584 | /* close the epoch, in case it outgrew the limit */ |
582 | rcu_read_lock(); | 585 | rcu_read_lock(); |
583 | nc = rcu_dereference(mdev->tconn->net_conf); | 586 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
584 | p = nc->max_epoch_size; | 587 | p = nc->max_epoch_size; |
585 | rcu_read_unlock(); | 588 | rcu_read_unlock(); |
586 | if (mdev->tconn->current_tle_writes >= p) | 589 | if (first_peer_device(device)->connection->current_tle_writes >= p) |
587 | start_new_tl_epoch(mdev->tconn); | 590 | start_new_tl_epoch(first_peer_device(device)->connection); |
588 | 591 | ||
589 | break; | 592 | break; |
590 | 593 | ||
591 | case QUEUE_FOR_SEND_OOS: | 594 | case QUEUE_FOR_SEND_OOS: |
592 | mod_rq_state(req, m, 0, RQ_NET_QUEUED); | 595 | mod_rq_state(req, m, 0, RQ_NET_QUEUED); |
593 | req->w.cb = w_send_out_of_sync; | 596 | req->w.cb = w_send_out_of_sync; |
594 | drbd_queue_work(&mdev->tconn->sender_work, &req->w); | 597 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
598 | &req->w); | ||
595 | break; | 599 | break; |
596 | 600 | ||
597 | case READ_RETRY_REMOTE_CANCELED: | 601 | case READ_RETRY_REMOTE_CANCELED: |
@@ -639,15 +643,15 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
639 | * If this request had been marked as RQ_POSTPONED before, | 643 | * If this request had been marked as RQ_POSTPONED before, |
640 | * it will actually not be completed, but "restarted", | 644 | * it will actually not be completed, but "restarted", |
641 | * resubmitted from the retry worker context. */ | 645 | * resubmitted from the retry worker context. */ |
642 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 646 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
643 | D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK); | 647 | D_ASSERT(device, req->rq_state & RQ_EXP_WRITE_ACK); |
644 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_DONE|RQ_NET_OK); | 648 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_DONE|RQ_NET_OK); |
645 | break; | 649 | break; |
646 | 650 | ||
647 | case WRITE_ACKED_BY_PEER_AND_SIS: | 651 | case WRITE_ACKED_BY_PEER_AND_SIS: |
648 | req->rq_state |= RQ_NET_SIS; | 652 | req->rq_state |= RQ_NET_SIS; |
649 | case WRITE_ACKED_BY_PEER: | 653 | case WRITE_ACKED_BY_PEER: |
650 | D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK); | 654 | D_ASSERT(device, req->rq_state & RQ_EXP_WRITE_ACK); |
651 | /* protocol C; successfully written on peer. | 655 | /* protocol C; successfully written on peer. |
652 | * Nothing more to do here. | 656 | * Nothing more to do here. |
653 | * We want to keep the tl in place for all protocols, to cater | 657 | * We want to keep the tl in place for all protocols, to cater |
@@ -655,25 +659,25 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
655 | 659 | ||
656 | goto ack_common; | 660 | goto ack_common; |
657 | case RECV_ACKED_BY_PEER: | 661 | case RECV_ACKED_BY_PEER: |
658 | D_ASSERT(req->rq_state & RQ_EXP_RECEIVE_ACK); | 662 | D_ASSERT(device, req->rq_state & RQ_EXP_RECEIVE_ACK); |
659 | /* protocol B; pretends to be successfully written on peer. | 663 | /* protocol B; pretends to be successfully written on peer. |
660 | * see also notes above in HANDED_OVER_TO_NETWORK about | 664 | * see also notes above in HANDED_OVER_TO_NETWORK about |
661 | * protocol != C */ | 665 | * protocol != C */ |
662 | ack_common: | 666 | ack_common: |
663 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 667 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
664 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK); | 668 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK); |
665 | break; | 669 | break; |
666 | 670 | ||
667 | case POSTPONE_WRITE: | 671 | case POSTPONE_WRITE: |
668 | D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK); | 672 | D_ASSERT(device, req->rq_state & RQ_EXP_WRITE_ACK); |
669 | /* If this node has already detected the write conflict, the | 673 | /* If this node has already detected the write conflict, the |
670 | * worker will be waiting on misc_wait. Wake it up once this | 674 | * worker will be waiting on misc_wait. Wake it up once this |
671 | * request has completed locally. | 675 | * request has completed locally. |
672 | */ | 676 | */ |
673 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 677 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
674 | req->rq_state |= RQ_POSTPONED; | 678 | req->rq_state |= RQ_POSTPONED; |
675 | if (req->i.waiting) | 679 | if (req->i.waiting) |
676 | wake_up(&mdev->misc_wait); | 680 | wake_up(&device->misc_wait); |
677 | /* Do not clear RQ_NET_PENDING. This request will make further | 681 | /* Do not clear RQ_NET_PENDING. This request will make further |
678 | * progress via restart_conflicting_writes() or | 682 | * progress via restart_conflicting_writes() or |
679 | * fail_postponed_requests(). Hopefully. */ | 683 | * fail_postponed_requests(). Hopefully. */ |
@@ -701,9 +705,10 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
701 | if (bio_data_dir(req->master_bio) == WRITE) | 705 | if (bio_data_dir(req->master_bio) == WRITE) |
702 | rv = MR_WRITE; | 706 | rv = MR_WRITE; |
703 | 707 | ||
704 | get_ldev(mdev); /* always succeeds in this call path */ | 708 | get_ldev(device); /* always succeeds in this call path */ |
705 | req->w.cb = w_restart_disk_io; | 709 | req->w.cb = w_restart_disk_io; |
706 | drbd_queue_work(&mdev->tconn->sender_work, &req->w); | 710 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
711 | &req->w); | ||
707 | break; | 712 | break; |
708 | 713 | ||
709 | case RESEND: | 714 | case RESEND: |
@@ -719,12 +724,13 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
719 | Throwing them out of the TL here by pretending we got a BARRIER_ACK. | 724 | Throwing them out of the TL here by pretending we got a BARRIER_ACK. |
720 | During connection handshake, we ensure that the peer was not rebooted. */ | 725 | During connection handshake, we ensure that the peer was not rebooted. */ |
721 | if (!(req->rq_state & RQ_NET_OK)) { | 726 | if (!(req->rq_state & RQ_NET_OK)) { |
722 | /* FIXME could this possibly be a req->w.cb == w_send_out_of_sync? | 727 | /* FIXME could this possibly be a req->dw.cb == w_send_out_of_sync? |
723 | * in that case we must not set RQ_NET_PENDING. */ | 728 | * in that case we must not set RQ_NET_PENDING. */ |
724 | 729 | ||
725 | mod_rq_state(req, m, RQ_COMPLETION_SUSP, RQ_NET_QUEUED|RQ_NET_PENDING); | 730 | mod_rq_state(req, m, RQ_COMPLETION_SUSP, RQ_NET_QUEUED|RQ_NET_PENDING); |
726 | if (req->w.cb) { | 731 | if (req->w.cb) { |
727 | drbd_queue_work(&mdev->tconn->sender_work, &req->w); | 732 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
733 | &req->w); | ||
728 | rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ; | 734 | rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ; |
729 | } /* else: FIXME can this happen? */ | 735 | } /* else: FIXME can this happen? */ |
730 | break; | 736 | break; |
@@ -740,7 +746,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
740 | /* barrier came in before all requests were acked. | 746 | /* barrier came in before all requests were acked. |
741 | * this is bad, because if the connection is lost now, | 747 | * this is bad, because if the connection is lost now, |
742 | * we won't be able to clean them up... */ | 748 | * we won't be able to clean them up... */ |
743 | dev_err(DEV, "FIXME (BARRIER_ACKED but pending)\n"); | 749 | drbd_err(device, "FIXME (BARRIER_ACKED but pending)\n"); |
744 | } | 750 | } |
745 | /* Allowed to complete requests, even while suspended. | 751 | /* Allowed to complete requests, even while suspended. |
746 | * As this is called for all requests within a matching epoch, | 752 | * As this is called for all requests within a matching epoch, |
@@ -751,12 +757,12 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
751 | break; | 757 | break; |
752 | 758 | ||
753 | case DATA_RECEIVED: | 759 | case DATA_RECEIVED: |
754 | D_ASSERT(req->rq_state & RQ_NET_PENDING); | 760 | D_ASSERT(device, req->rq_state & RQ_NET_PENDING); |
755 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK|RQ_NET_DONE); | 761 | mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK|RQ_NET_DONE); |
756 | break; | 762 | break; |
757 | 763 | ||
758 | case QUEUE_AS_DRBD_BARRIER: | 764 | case QUEUE_AS_DRBD_BARRIER: |
759 | start_new_tl_epoch(mdev->tconn); | 765 | start_new_tl_epoch(first_peer_device(device)->connection); |
760 | mod_rq_state(req, m, 0, RQ_NET_OK|RQ_NET_DONE); | 766 | mod_rq_state(req, m, 0, RQ_NET_OK|RQ_NET_DONE); |
761 | break; | 767 | break; |
762 | }; | 768 | }; |
@@ -771,27 +777,27 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what, | |||
771 | * since size may be bigger than BM_BLOCK_SIZE, | 777 | * since size may be bigger than BM_BLOCK_SIZE, |
772 | * we may need to check several bits. | 778 | * we may need to check several bits. |
773 | */ | 779 | */ |
774 | static bool drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size) | 780 | static bool drbd_may_do_local_read(struct drbd_device *device, sector_t sector, int size) |
775 | { | 781 | { |
776 | unsigned long sbnr, ebnr; | 782 | unsigned long sbnr, ebnr; |
777 | sector_t esector, nr_sectors; | 783 | sector_t esector, nr_sectors; |
778 | 784 | ||
779 | if (mdev->state.disk == D_UP_TO_DATE) | 785 | if (device->state.disk == D_UP_TO_DATE) |
780 | return true; | 786 | return true; |
781 | if (mdev->state.disk != D_INCONSISTENT) | 787 | if (device->state.disk != D_INCONSISTENT) |
782 | return false; | 788 | return false; |
783 | esector = sector + (size >> 9) - 1; | 789 | esector = sector + (size >> 9) - 1; |
784 | nr_sectors = drbd_get_capacity(mdev->this_bdev); | 790 | nr_sectors = drbd_get_capacity(device->this_bdev); |
785 | D_ASSERT(sector < nr_sectors); | 791 | D_ASSERT(device, sector < nr_sectors); |
786 | D_ASSERT(esector < nr_sectors); | 792 | D_ASSERT(device, esector < nr_sectors); |
787 | 793 | ||
788 | sbnr = BM_SECT_TO_BIT(sector); | 794 | sbnr = BM_SECT_TO_BIT(sector); |
789 | ebnr = BM_SECT_TO_BIT(esector); | 795 | ebnr = BM_SECT_TO_BIT(esector); |
790 | 796 | ||
791 | return drbd_bm_count_bits(mdev, sbnr, ebnr) == 0; | 797 | return drbd_bm_count_bits(device, sbnr, ebnr) == 0; |
792 | } | 798 | } |
793 | 799 | ||
794 | static bool remote_due_to_read_balancing(struct drbd_conf *mdev, sector_t sector, | 800 | static bool remote_due_to_read_balancing(struct drbd_device *device, sector_t sector, |
795 | enum drbd_read_balancing rbm) | 801 | enum drbd_read_balancing rbm) |
796 | { | 802 | { |
797 | struct backing_dev_info *bdi; | 803 | struct backing_dev_info *bdi; |
@@ -799,11 +805,11 @@ static bool remote_due_to_read_balancing(struct drbd_conf *mdev, sector_t sector | |||
799 | 805 | ||
800 | switch (rbm) { | 806 | switch (rbm) { |
801 | case RB_CONGESTED_REMOTE: | 807 | case RB_CONGESTED_REMOTE: |
802 | bdi = &mdev->ldev->backing_bdev->bd_disk->queue->backing_dev_info; | 808 | bdi = &device->ldev->backing_bdev->bd_disk->queue->backing_dev_info; |
803 | return bdi_read_congested(bdi); | 809 | return bdi_read_congested(bdi); |
804 | case RB_LEAST_PENDING: | 810 | case RB_LEAST_PENDING: |
805 | return atomic_read(&mdev->local_cnt) > | 811 | return atomic_read(&device->local_cnt) > |
806 | atomic_read(&mdev->ap_pending_cnt) + atomic_read(&mdev->rs_pending_cnt); | 812 | atomic_read(&device->ap_pending_cnt) + atomic_read(&device->rs_pending_cnt); |
807 | case RB_32K_STRIPING: /* stripe_shift = 15 */ | 813 | case RB_32K_STRIPING: /* stripe_shift = 15 */ |
808 | case RB_64K_STRIPING: | 814 | case RB_64K_STRIPING: |
809 | case RB_128K_STRIPING: | 815 | case RB_128K_STRIPING: |
@@ -813,7 +819,7 @@ static bool remote_due_to_read_balancing(struct drbd_conf *mdev, sector_t sector | |||
813 | stripe_shift = (rbm - RB_32K_STRIPING + 15); | 819 | stripe_shift = (rbm - RB_32K_STRIPING + 15); |
814 | return (sector >> (stripe_shift - 9)) & 1; | 820 | return (sector >> (stripe_shift - 9)) & 1; |
815 | case RB_ROUND_ROBIN: | 821 | case RB_ROUND_ROBIN: |
816 | return test_and_change_bit(READ_BALANCE_RR, &mdev->flags); | 822 | return test_and_change_bit(READ_BALANCE_RR, &device->flags); |
817 | case RB_PREFER_REMOTE: | 823 | case RB_PREFER_REMOTE: |
818 | return true; | 824 | return true; |
819 | case RB_PREFER_LOCAL: | 825 | case RB_PREFER_LOCAL: |
@@ -834,73 +840,73 @@ static bool remote_due_to_read_balancing(struct drbd_conf *mdev, sector_t sector | |||
834 | static void complete_conflicting_writes(struct drbd_request *req) | 840 | static void complete_conflicting_writes(struct drbd_request *req) |
835 | { | 841 | { |
836 | DEFINE_WAIT(wait); | 842 | DEFINE_WAIT(wait); |
837 | struct drbd_conf *mdev = req->w.mdev; | 843 | struct drbd_device *device = req->device; |
838 | struct drbd_interval *i; | 844 | struct drbd_interval *i; |
839 | sector_t sector = req->i.sector; | 845 | sector_t sector = req->i.sector; |
840 | int size = req->i.size; | 846 | int size = req->i.size; |
841 | 847 | ||
842 | i = drbd_find_overlap(&mdev->write_requests, sector, size); | 848 | i = drbd_find_overlap(&device->write_requests, sector, size); |
843 | if (!i) | 849 | if (!i) |
844 | return; | 850 | return; |
845 | 851 | ||
846 | for (;;) { | 852 | for (;;) { |
847 | prepare_to_wait(&mdev->misc_wait, &wait, TASK_UNINTERRUPTIBLE); | 853 | prepare_to_wait(&device->misc_wait, &wait, TASK_UNINTERRUPTIBLE); |
848 | i = drbd_find_overlap(&mdev->write_requests, sector, size); | 854 | i = drbd_find_overlap(&device->write_requests, sector, size); |
849 | if (!i) | 855 | if (!i) |
850 | break; | 856 | break; |
851 | /* Indicate to wake up device->misc_wait on progress. */ | 857 | /* Indicate to wake up device->misc_wait on progress. */ |
852 | i->waiting = true; | 858 | i->waiting = true; |
853 | spin_unlock_irq(&mdev->tconn->req_lock); | 859 | spin_unlock_irq(&device->resource->req_lock); |
854 | schedule(); | 860 | schedule(); |
855 | spin_lock_irq(&mdev->tconn->req_lock); | 861 | spin_lock_irq(&device->resource->req_lock); |
856 | } | 862 | } |
857 | finish_wait(&mdev->misc_wait, &wait); | 863 | finish_wait(&device->misc_wait, &wait); |
858 | } | 864 | } |
859 | 865 | ||
860 | /* called within req_lock and rcu_read_lock() */ | 866 | /* called within req_lock and rcu_read_lock() */ |
861 | static void maybe_pull_ahead(struct drbd_conf *mdev) | 867 | static void maybe_pull_ahead(struct drbd_device *device) |
862 | { | 868 | { |
863 | struct drbd_tconn *tconn = mdev->tconn; | 869 | struct drbd_connection *connection = first_peer_device(device)->connection; |
864 | struct net_conf *nc; | 870 | struct net_conf *nc; |
865 | bool congested = false; | 871 | bool congested = false; |
866 | enum drbd_on_congestion on_congestion; | 872 | enum drbd_on_congestion on_congestion; |
867 | 873 | ||
868 | rcu_read_lock(); | 874 | rcu_read_lock(); |
869 | nc = rcu_dereference(tconn->net_conf); | 875 | nc = rcu_dereference(connection->net_conf); |
870 | on_congestion = nc ? nc->on_congestion : OC_BLOCK; | 876 | on_congestion = nc ? nc->on_congestion : OC_BLOCK; |
871 | rcu_read_unlock(); | 877 | rcu_read_unlock(); |
872 | if (on_congestion == OC_BLOCK || | 878 | if (on_congestion == OC_BLOCK || |
873 | tconn->agreed_pro_version < 96) | 879 | connection->agreed_pro_version < 96) |
874 | return; | 880 | return; |
875 | 881 | ||
876 | /* If I don't even have good local storage, we can not reasonably try | 882 | /* If I don't even have good local storage, we can not reasonably try |
877 | * to pull ahead of the peer. We also need the local reference to make | 883 | * to pull ahead of the peer. We also need the local reference to make |
878 | * sure mdev->act_log is there. | 884 | * sure device->act_log is there. |
879 | */ | 885 | */ |
880 | if (!get_ldev_if_state(mdev, D_UP_TO_DATE)) | 886 | if (!get_ldev_if_state(device, D_UP_TO_DATE)) |
881 | return; | 887 | return; |
882 | 888 | ||
883 | if (nc->cong_fill && | 889 | if (nc->cong_fill && |
884 | atomic_read(&mdev->ap_in_flight) >= nc->cong_fill) { | 890 | atomic_read(&device->ap_in_flight) >= nc->cong_fill) { |
885 | dev_info(DEV, "Congestion-fill threshold reached\n"); | 891 | drbd_info(device, "Congestion-fill threshold reached\n"); |
886 | congested = true; | 892 | congested = true; |
887 | } | 893 | } |
888 | 894 | ||
889 | if (mdev->act_log->used >= nc->cong_extents) { | 895 | if (device->act_log->used >= nc->cong_extents) { |
890 | dev_info(DEV, "Congestion-extents threshold reached\n"); | 896 | drbd_info(device, "Congestion-extents threshold reached\n"); |
891 | congested = true; | 897 | congested = true; |
892 | } | 898 | } |
893 | 899 | ||
894 | if (congested) { | 900 | if (congested) { |
895 | /* start a new epoch for non-mirrored writes */ | 901 | /* start a new epoch for non-mirrored writes */ |
896 | start_new_tl_epoch(mdev->tconn); | 902 | start_new_tl_epoch(first_peer_device(device)->connection); |
897 | 903 | ||
898 | if (on_congestion == OC_PULL_AHEAD) | 904 | if (on_congestion == OC_PULL_AHEAD) |
899 | _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL); | 905 | _drbd_set_state(_NS(device, conn, C_AHEAD), 0, NULL); |
900 | else /*nc->on_congestion == OC_DISCONNECT */ | 906 | else /*nc->on_congestion == OC_DISCONNECT */ |
901 | _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL); | 907 | _drbd_set_state(_NS(device, conn, C_DISCONNECTING), 0, NULL); |
902 | } | 908 | } |
903 | put_ldev(mdev); | 909 | put_ldev(device); |
904 | } | 910 | } |
905 | 911 | ||
906 | /* If this returns false, and req->private_bio is still set, | 912 | /* If this returns false, and req->private_bio is still set, |
@@ -914,19 +920,19 @@ static void maybe_pull_ahead(struct drbd_conf *mdev) | |||
914 | */ | 920 | */ |
915 | static bool do_remote_read(struct drbd_request *req) | 921 | static bool do_remote_read(struct drbd_request *req) |
916 | { | 922 | { |
917 | struct drbd_conf *mdev = req->w.mdev; | 923 | struct drbd_device *device = req->device; |
918 | enum drbd_read_balancing rbm; | 924 | enum drbd_read_balancing rbm; |
919 | 925 | ||
920 | if (req->private_bio) { | 926 | if (req->private_bio) { |
921 | if (!drbd_may_do_local_read(mdev, | 927 | if (!drbd_may_do_local_read(device, |
922 | req->i.sector, req->i.size)) { | 928 | req->i.sector, req->i.size)) { |
923 | bio_put(req->private_bio); | 929 | bio_put(req->private_bio); |
924 | req->private_bio = NULL; | 930 | req->private_bio = NULL; |
925 | put_ldev(mdev); | 931 | put_ldev(device); |
926 | } | 932 | } |
927 | } | 933 | } |
928 | 934 | ||
929 | if (mdev->state.pdsk != D_UP_TO_DATE) | 935 | if (device->state.pdsk != D_UP_TO_DATE) |
930 | return false; | 936 | return false; |
931 | 937 | ||
932 | if (req->private_bio == NULL) | 938 | if (req->private_bio == NULL) |
@@ -936,17 +942,17 @@ static bool do_remote_read(struct drbd_request *req) | |||
936 | * protocol, pending requests etc. */ | 942 | * protocol, pending requests etc. */ |
937 | 943 | ||
938 | rcu_read_lock(); | 944 | rcu_read_lock(); |
939 | rbm = rcu_dereference(mdev->ldev->disk_conf)->read_balancing; | 945 | rbm = rcu_dereference(device->ldev->disk_conf)->read_balancing; |
940 | rcu_read_unlock(); | 946 | rcu_read_unlock(); |
941 | 947 | ||
942 | if (rbm == RB_PREFER_LOCAL && req->private_bio) | 948 | if (rbm == RB_PREFER_LOCAL && req->private_bio) |
943 | return false; /* submit locally */ | 949 | return false; /* submit locally */ |
944 | 950 | ||
945 | if (remote_due_to_read_balancing(mdev, req->i.sector, rbm)) { | 951 | if (remote_due_to_read_balancing(device, req->i.sector, rbm)) { |
946 | if (req->private_bio) { | 952 | if (req->private_bio) { |
947 | bio_put(req->private_bio); | 953 | bio_put(req->private_bio); |
948 | req->private_bio = NULL; | 954 | req->private_bio = NULL; |
949 | put_ldev(mdev); | 955 | put_ldev(device); |
950 | } | 956 | } |
951 | return true; | 957 | return true; |
952 | } | 958 | } |
@@ -959,11 +965,11 @@ static bool do_remote_read(struct drbd_request *req) | |||
959 | * which does NOT include those that we are L_AHEAD for. */ | 965 | * which does NOT include those that we are L_AHEAD for. */ |
960 | static int drbd_process_write_request(struct drbd_request *req) | 966 | static int drbd_process_write_request(struct drbd_request *req) |
961 | { | 967 | { |
962 | struct drbd_conf *mdev = req->w.mdev; | 968 | struct drbd_device *device = req->device; |
963 | int remote, send_oos; | 969 | int remote, send_oos; |
964 | 970 | ||
965 | remote = drbd_should_do_remote(mdev->state); | 971 | remote = drbd_should_do_remote(device->state); |
966 | send_oos = drbd_should_send_out_of_sync(mdev->state); | 972 | send_oos = drbd_should_send_out_of_sync(device->state); |
967 | 973 | ||
968 | /* Need to replicate writes. Unless it is an empty flush, | 974 | /* Need to replicate writes. Unless it is an empty flush, |
969 | * which is better mapped to a DRBD P_BARRIER packet, | 975 | * which is better mapped to a DRBD P_BARRIER packet, |
@@ -973,7 +979,7 @@ static int drbd_process_write_request(struct drbd_request *req) | |||
973 | * replicating, in which case there is no point. */ | 979 | * replicating, in which case there is no point. */ |
974 | if (unlikely(req->i.size == 0)) { | 980 | if (unlikely(req->i.size == 0)) { |
975 | /* The only size==0 bios we expect are empty flushes. */ | 981 | /* The only size==0 bios we expect are empty flushes. */ |
976 | D_ASSERT(req->master_bio->bi_rw & REQ_FLUSH); | 982 | D_ASSERT(device, req->master_bio->bi_rw & REQ_FLUSH); |
977 | if (remote) | 983 | if (remote) |
978 | _req_mod(req, QUEUE_AS_DRBD_BARRIER); | 984 | _req_mod(req, QUEUE_AS_DRBD_BARRIER); |
979 | return remote; | 985 | return remote; |
@@ -982,12 +988,12 @@ static int drbd_process_write_request(struct drbd_request *req) | |||
982 | if (!remote && !send_oos) | 988 | if (!remote && !send_oos) |
983 | return 0; | 989 | return 0; |
984 | 990 | ||
985 | D_ASSERT(!(remote && send_oos)); | 991 | D_ASSERT(device, !(remote && send_oos)); |
986 | 992 | ||
987 | if (remote) { | 993 | if (remote) { |
988 | _req_mod(req, TO_BE_SENT); | 994 | _req_mod(req, TO_BE_SENT); |
989 | _req_mod(req, QUEUE_FOR_NET_WRITE); | 995 | _req_mod(req, QUEUE_FOR_NET_WRITE); |
990 | } else if (drbd_set_out_of_sync(mdev, req->i.sector, req->i.size)) | 996 | } else if (drbd_set_out_of_sync(device, req->i.sector, req->i.size)) |
991 | _req_mod(req, QUEUE_FOR_SEND_OOS); | 997 | _req_mod(req, QUEUE_FOR_SEND_OOS); |
992 | 998 | ||
993 | return remote; | 999 | return remote; |
@@ -996,36 +1002,36 @@ static int drbd_process_write_request(struct drbd_request *req) | |||
996 | static void | 1002 | static void |
997 | drbd_submit_req_private_bio(struct drbd_request *req) | 1003 | drbd_submit_req_private_bio(struct drbd_request *req) |
998 | { | 1004 | { |
999 | struct drbd_conf *mdev = req->w.mdev; | 1005 | struct drbd_device *device = req->device; |
1000 | struct bio *bio = req->private_bio; | 1006 | struct bio *bio = req->private_bio; |
1001 | const int rw = bio_rw(bio); | 1007 | const int rw = bio_rw(bio); |
1002 | 1008 | ||
1003 | bio->bi_bdev = mdev->ldev->backing_bdev; | 1009 | bio->bi_bdev = device->ldev->backing_bdev; |
1004 | 1010 | ||
1005 | /* State may have changed since we grabbed our reference on the | 1011 | /* State may have changed since we grabbed our reference on the |
1006 | * ->ldev member. Double check, and short-circuit to endio. | 1012 | * ->ldev member. Double check, and short-circuit to endio. |
1007 | * In case the last activity log transaction failed to get on | 1013 | * In case the last activity log transaction failed to get on |
1008 | * stable storage, and this is a WRITE, we may not even submit | 1014 | * stable storage, and this is a WRITE, we may not even submit |
1009 | * this bio. */ | 1015 | * this bio. */ |
1010 | if (get_ldev(mdev)) { | 1016 | if (get_ldev(device)) { |
1011 | if (drbd_insert_fault(mdev, | 1017 | if (drbd_insert_fault(device, |
1012 | rw == WRITE ? DRBD_FAULT_DT_WR | 1018 | rw == WRITE ? DRBD_FAULT_DT_WR |
1013 | : rw == READ ? DRBD_FAULT_DT_RD | 1019 | : rw == READ ? DRBD_FAULT_DT_RD |
1014 | : DRBD_FAULT_DT_RA)) | 1020 | : DRBD_FAULT_DT_RA)) |
1015 | bio_endio(bio, -EIO); | 1021 | bio_endio(bio, -EIO); |
1016 | else | 1022 | else |
1017 | generic_make_request(bio); | 1023 | generic_make_request(bio); |
1018 | put_ldev(mdev); | 1024 | put_ldev(device); |
1019 | } else | 1025 | } else |
1020 | bio_endio(bio, -EIO); | 1026 | bio_endio(bio, -EIO); |
1021 | } | 1027 | } |
1022 | 1028 | ||
1023 | static void drbd_queue_write(struct drbd_conf *mdev, struct drbd_request *req) | 1029 | static void drbd_queue_write(struct drbd_device *device, struct drbd_request *req) |
1024 | { | 1030 | { |
1025 | spin_lock(&mdev->submit.lock); | 1031 | spin_lock(&device->submit.lock); |
1026 | list_add_tail(&req->tl_requests, &mdev->submit.writes); | 1032 | list_add_tail(&req->tl_requests, &device->submit.writes); |
1027 | spin_unlock(&mdev->submit.lock); | 1033 | spin_unlock(&device->submit.lock); |
1028 | queue_work(mdev->submit.wq, &mdev->submit.worker); | 1034 | queue_work(device->submit.wq, &device->submit.worker); |
1029 | } | 1035 | } |
1030 | 1036 | ||
1031 | /* returns the new drbd_request pointer, if the caller is expected to | 1037 | /* returns the new drbd_request pointer, if the caller is expected to |
@@ -1033,36 +1039,36 @@ static void drbd_queue_write(struct drbd_conf *mdev, struct drbd_request *req) | |||
1033 | * request on the submitter thread. | 1039 | * request on the submitter thread. |
1034 | * Returns ERR_PTR(-ENOMEM) if we cannot allocate a drbd_request. | 1040 | * Returns ERR_PTR(-ENOMEM) if we cannot allocate a drbd_request. |
1035 | */ | 1041 | */ |
1036 | struct drbd_request * | 1042 | static struct drbd_request * |
1037 | drbd_request_prepare(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time) | 1043 | drbd_request_prepare(struct drbd_device *device, struct bio *bio, unsigned long start_time) |
1038 | { | 1044 | { |
1039 | const int rw = bio_data_dir(bio); | 1045 | const int rw = bio_data_dir(bio); |
1040 | struct drbd_request *req; | 1046 | struct drbd_request *req; |
1041 | 1047 | ||
1042 | /* allocate outside of all locks; */ | 1048 | /* allocate outside of all locks; */ |
1043 | req = drbd_req_new(mdev, bio); | 1049 | req = drbd_req_new(device, bio); |
1044 | if (!req) { | 1050 | if (!req) { |
1045 | dec_ap_bio(mdev); | 1051 | dec_ap_bio(device); |
1046 | /* only pass the error to the upper layers. | 1052 | /* only pass the error to the upper layers. |
1047 | * if user cannot handle io errors, that's not our business. */ | 1053 | * if user cannot handle io errors, that's not our business. */ |
1048 | dev_err(DEV, "could not kmalloc() req\n"); | 1054 | drbd_err(device, "could not kmalloc() req\n"); |
1049 | bio_endio(bio, -ENOMEM); | 1055 | bio_endio(bio, -ENOMEM); |
1050 | return ERR_PTR(-ENOMEM); | 1056 | return ERR_PTR(-ENOMEM); |
1051 | } | 1057 | } |
1052 | req->start_time = start_time; | 1058 | req->start_time = start_time; |
1053 | 1059 | ||
1054 | if (!get_ldev(mdev)) { | 1060 | if (!get_ldev(device)) { |
1055 | bio_put(req->private_bio); | 1061 | bio_put(req->private_bio); |
1056 | req->private_bio = NULL; | 1062 | req->private_bio = NULL; |
1057 | } | 1063 | } |
1058 | 1064 | ||
1059 | /* Update disk stats */ | 1065 | /* Update disk stats */ |
1060 | _drbd_start_io_acct(mdev, req); | 1066 | _drbd_start_io_acct(device, req); |
1061 | 1067 | ||
1062 | if (rw == WRITE && req->private_bio && req->i.size | 1068 | if (rw == WRITE && req->private_bio && req->i.size |
1063 | && !test_bit(AL_SUSPENDED, &mdev->flags)) { | 1069 | && !test_bit(AL_SUSPENDED, &device->flags)) { |
1064 | if (!drbd_al_begin_io_fastpath(mdev, &req->i)) { | 1070 | if (!drbd_al_begin_io_fastpath(device, &req->i)) { |
1065 | drbd_queue_write(mdev, req); | 1071 | drbd_queue_write(device, req); |
1066 | return NULL; | 1072 | return NULL; |
1067 | } | 1073 | } |
1068 | req->rq_state |= RQ_IN_ACT_LOG; | 1074 | req->rq_state |= RQ_IN_ACT_LOG; |
@@ -1071,13 +1077,13 @@ drbd_request_prepare(struct drbd_conf *mdev, struct bio *bio, unsigned long star | |||
1071 | return req; | 1077 | return req; |
1072 | } | 1078 | } |
1073 | 1079 | ||
1074 | static void drbd_send_and_submit(struct drbd_conf *mdev, struct drbd_request *req) | 1080 | static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request *req) |
1075 | { | 1081 | { |
1076 | const int rw = bio_rw(req->master_bio); | 1082 | const int rw = bio_rw(req->master_bio); |
1077 | struct bio_and_error m = { NULL, }; | 1083 | struct bio_and_error m = { NULL, }; |
1078 | bool no_remote = false; | 1084 | bool no_remote = false; |
1079 | 1085 | ||
1080 | spin_lock_irq(&mdev->tconn->req_lock); | 1086 | spin_lock_irq(&device->resource->req_lock); |
1081 | if (rw == WRITE) { | 1087 | if (rw == WRITE) { |
1082 | /* This may temporarily give up the req_lock, | 1088 | /* This may temporarily give up the req_lock, |
1083 | * but will re-aquire it before it returns here. | 1089 | * but will re-aquire it before it returns here. |
@@ -1087,17 +1093,17 @@ static void drbd_send_and_submit(struct drbd_conf *mdev, struct drbd_request *re | |||
1087 | 1093 | ||
1088 | /* check for congestion, and potentially stop sending | 1094 | /* check for congestion, and potentially stop sending |
1089 | * full data updates, but start sending "dirty bits" only. */ | 1095 | * full data updates, but start sending "dirty bits" only. */ |
1090 | maybe_pull_ahead(mdev); | 1096 | maybe_pull_ahead(device); |
1091 | } | 1097 | } |
1092 | 1098 | ||
1093 | 1099 | ||
1094 | if (drbd_suspended(mdev)) { | 1100 | if (drbd_suspended(device)) { |
1095 | /* push back and retry: */ | 1101 | /* push back and retry: */ |
1096 | req->rq_state |= RQ_POSTPONED; | 1102 | req->rq_state |= RQ_POSTPONED; |
1097 | if (req->private_bio) { | 1103 | if (req->private_bio) { |
1098 | bio_put(req->private_bio); | 1104 | bio_put(req->private_bio); |
1099 | req->private_bio = NULL; | 1105 | req->private_bio = NULL; |
1100 | put_ldev(mdev); | 1106 | put_ldev(device); |
1101 | } | 1107 | } |
1102 | goto out; | 1108 | goto out; |
1103 | } | 1109 | } |
@@ -1111,15 +1117,15 @@ static void drbd_send_and_submit(struct drbd_conf *mdev, struct drbd_request *re | |||
1111 | } | 1117 | } |
1112 | 1118 | ||
1113 | /* which transfer log epoch does this belong to? */ | 1119 | /* which transfer log epoch does this belong to? */ |
1114 | req->epoch = atomic_read(&mdev->tconn->current_tle_nr); | 1120 | req->epoch = atomic_read(&first_peer_device(device)->connection->current_tle_nr); |
1115 | 1121 | ||
1116 | /* no point in adding empty flushes to the transfer log, | 1122 | /* no point in adding empty flushes to the transfer log, |
1117 | * they are mapped to drbd barriers already. */ | 1123 | * they are mapped to drbd barriers already. */ |
1118 | if (likely(req->i.size!=0)) { | 1124 | if (likely(req->i.size!=0)) { |
1119 | if (rw == WRITE) | 1125 | if (rw == WRITE) |
1120 | mdev->tconn->current_tle_writes++; | 1126 | first_peer_device(device)->connection->current_tle_writes++; |
1121 | 1127 | ||
1122 | list_add_tail(&req->tl_requests, &mdev->tconn->transfer_log); | 1128 | list_add_tail(&req->tl_requests, &first_peer_device(device)->connection->transfer_log); |
1123 | } | 1129 | } |
1124 | 1130 | ||
1125 | if (rw == WRITE) { | 1131 | if (rw == WRITE) { |
@@ -1139,13 +1145,13 @@ static void drbd_send_and_submit(struct drbd_conf *mdev, struct drbd_request *re | |||
1139 | /* needs to be marked within the same spinlock */ | 1145 | /* needs to be marked within the same spinlock */ |
1140 | _req_mod(req, TO_BE_SUBMITTED); | 1146 | _req_mod(req, TO_BE_SUBMITTED); |
1141 | /* but we need to give up the spinlock to submit */ | 1147 | /* but we need to give up the spinlock to submit */ |
1142 | spin_unlock_irq(&mdev->tconn->req_lock); | 1148 | spin_unlock_irq(&device->resource->req_lock); |
1143 | drbd_submit_req_private_bio(req); | 1149 | drbd_submit_req_private_bio(req); |
1144 | spin_lock_irq(&mdev->tconn->req_lock); | 1150 | spin_lock_irq(&device->resource->req_lock); |
1145 | } else if (no_remote) { | 1151 | } else if (no_remote) { |
1146 | nodata: | 1152 | nodata: |
1147 | if (__ratelimit(&drbd_ratelimit_state)) | 1153 | if (__ratelimit(&drbd_ratelimit_state)) |
1148 | dev_err(DEV, "IO ERROR: neither local nor remote data, sector %llu+%u\n", | 1154 | drbd_err(device, "IO ERROR: neither local nor remote data, sector %llu+%u\n", |
1149 | (unsigned long long)req->i.sector, req->i.size >> 9); | 1155 | (unsigned long long)req->i.sector, req->i.size >> 9); |
1150 | /* A write may have been queued for send_oos, however. | 1156 | /* A write may have been queued for send_oos, however. |
1151 | * So we can not simply free it, we must go through drbd_req_put_completion_ref() */ | 1157 | * So we can not simply free it, we must go through drbd_req_put_completion_ref() */ |
@@ -1154,21 +1160,21 @@ nodata: | |||
1154 | out: | 1160 | out: |
1155 | if (drbd_req_put_completion_ref(req, &m, 1)) | 1161 | if (drbd_req_put_completion_ref(req, &m, 1)) |
1156 | kref_put(&req->kref, drbd_req_destroy); | 1162 | kref_put(&req->kref, drbd_req_destroy); |
1157 | spin_unlock_irq(&mdev->tconn->req_lock); | 1163 | spin_unlock_irq(&device->resource->req_lock); |
1158 | 1164 | ||
1159 | if (m.bio) | 1165 | if (m.bio) |
1160 | complete_master_bio(mdev, &m); | 1166 | complete_master_bio(device, &m); |
1161 | } | 1167 | } |
1162 | 1168 | ||
1163 | void __drbd_make_request(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time) | 1169 | void __drbd_make_request(struct drbd_device *device, struct bio *bio, unsigned long start_time) |
1164 | { | 1170 | { |
1165 | struct drbd_request *req = drbd_request_prepare(mdev, bio, start_time); | 1171 | struct drbd_request *req = drbd_request_prepare(device, bio, start_time); |
1166 | if (IS_ERR_OR_NULL(req)) | 1172 | if (IS_ERR_OR_NULL(req)) |
1167 | return; | 1173 | return; |
1168 | drbd_send_and_submit(mdev, req); | 1174 | drbd_send_and_submit(device, req); |
1169 | } | 1175 | } |
1170 | 1176 | ||
1171 | static void submit_fast_path(struct drbd_conf *mdev, struct list_head *incoming) | 1177 | static void submit_fast_path(struct drbd_device *device, struct list_head *incoming) |
1172 | { | 1178 | { |
1173 | struct drbd_request *req, *tmp; | 1179 | struct drbd_request *req, *tmp; |
1174 | list_for_each_entry_safe(req, tmp, incoming, tl_requests) { | 1180 | list_for_each_entry_safe(req, tmp, incoming, tl_requests) { |
@@ -1176,19 +1182,19 @@ static void submit_fast_path(struct drbd_conf *mdev, struct list_head *incoming) | |||
1176 | 1182 | ||
1177 | if (rw == WRITE /* rw != WRITE should not even end up here! */ | 1183 | if (rw == WRITE /* rw != WRITE should not even end up here! */ |
1178 | && req->private_bio && req->i.size | 1184 | && req->private_bio && req->i.size |
1179 | && !test_bit(AL_SUSPENDED, &mdev->flags)) { | 1185 | && !test_bit(AL_SUSPENDED, &device->flags)) { |
1180 | if (!drbd_al_begin_io_fastpath(mdev, &req->i)) | 1186 | if (!drbd_al_begin_io_fastpath(device, &req->i)) |
1181 | continue; | 1187 | continue; |
1182 | 1188 | ||
1183 | req->rq_state |= RQ_IN_ACT_LOG; | 1189 | req->rq_state |= RQ_IN_ACT_LOG; |
1184 | } | 1190 | } |
1185 | 1191 | ||
1186 | list_del_init(&req->tl_requests); | 1192 | list_del_init(&req->tl_requests); |
1187 | drbd_send_and_submit(mdev, req); | 1193 | drbd_send_and_submit(device, req); |
1188 | } | 1194 | } |
1189 | } | 1195 | } |
1190 | 1196 | ||
1191 | static bool prepare_al_transaction_nonblock(struct drbd_conf *mdev, | 1197 | static bool prepare_al_transaction_nonblock(struct drbd_device *device, |
1192 | struct list_head *incoming, | 1198 | struct list_head *incoming, |
1193 | struct list_head *pending) | 1199 | struct list_head *pending) |
1194 | { | 1200 | { |
@@ -1196,9 +1202,9 @@ static bool prepare_al_transaction_nonblock(struct drbd_conf *mdev, | |||
1196 | int wake = 0; | 1202 | int wake = 0; |
1197 | int err; | 1203 | int err; |
1198 | 1204 | ||
1199 | spin_lock_irq(&mdev->al_lock); | 1205 | spin_lock_irq(&device->al_lock); |
1200 | list_for_each_entry_safe(req, tmp, incoming, tl_requests) { | 1206 | list_for_each_entry_safe(req, tmp, incoming, tl_requests) { |
1201 | err = drbd_al_begin_io_nonblock(mdev, &req->i); | 1207 | err = drbd_al_begin_io_nonblock(device, &req->i); |
1202 | if (err == -EBUSY) | 1208 | if (err == -EBUSY) |
1203 | wake = 1; | 1209 | wake = 1; |
1204 | if (err) | 1210 | if (err) |
@@ -1206,30 +1212,30 @@ static bool prepare_al_transaction_nonblock(struct drbd_conf *mdev, | |||
1206 | req->rq_state |= RQ_IN_ACT_LOG; | 1212 | req->rq_state |= RQ_IN_ACT_LOG; |
1207 | list_move_tail(&req->tl_requests, pending); | 1213 | list_move_tail(&req->tl_requests, pending); |
1208 | } | 1214 | } |
1209 | spin_unlock_irq(&mdev->al_lock); | 1215 | spin_unlock_irq(&device->al_lock); |
1210 | if (wake) | 1216 | if (wake) |
1211 | wake_up(&mdev->al_wait); | 1217 | wake_up(&device->al_wait); |
1212 | 1218 | ||
1213 | return !list_empty(pending); | 1219 | return !list_empty(pending); |
1214 | } | 1220 | } |
1215 | 1221 | ||
1216 | void do_submit(struct work_struct *ws) | 1222 | void do_submit(struct work_struct *ws) |
1217 | { | 1223 | { |
1218 | struct drbd_conf *mdev = container_of(ws, struct drbd_conf, submit.worker); | 1224 | struct drbd_device *device = container_of(ws, struct drbd_device, submit.worker); |
1219 | LIST_HEAD(incoming); | 1225 | LIST_HEAD(incoming); |
1220 | LIST_HEAD(pending); | 1226 | LIST_HEAD(pending); |
1221 | struct drbd_request *req, *tmp; | 1227 | struct drbd_request *req, *tmp; |
1222 | 1228 | ||
1223 | for (;;) { | 1229 | for (;;) { |
1224 | spin_lock(&mdev->submit.lock); | 1230 | spin_lock(&device->submit.lock); |
1225 | list_splice_tail_init(&mdev->submit.writes, &incoming); | 1231 | list_splice_tail_init(&device->submit.writes, &incoming); |
1226 | spin_unlock(&mdev->submit.lock); | 1232 | spin_unlock(&device->submit.lock); |
1227 | 1233 | ||
1228 | submit_fast_path(mdev, &incoming); | 1234 | submit_fast_path(device, &incoming); |
1229 | if (list_empty(&incoming)) | 1235 | if (list_empty(&incoming)) |
1230 | break; | 1236 | break; |
1231 | 1237 | ||
1232 | wait_event(mdev->al_wait, prepare_al_transaction_nonblock(mdev, &incoming, &pending)); | 1238 | wait_event(device->al_wait, prepare_al_transaction_nonblock(device, &incoming, &pending)); |
1233 | /* Maybe more was queued, while we prepared the transaction? | 1239 | /* Maybe more was queued, while we prepared the transaction? |
1234 | * Try to stuff them into this transaction as well. | 1240 | * Try to stuff them into this transaction as well. |
1235 | * Be strictly non-blocking here, no wait_event, we already | 1241 | * Be strictly non-blocking here, no wait_event, we already |
@@ -1243,17 +1249,17 @@ void do_submit(struct work_struct *ws) | |||
1243 | 1249 | ||
1244 | /* It is ok to look outside the lock, | 1250 | /* It is ok to look outside the lock, |
1245 | * it's only an optimization anyways */ | 1251 | * it's only an optimization anyways */ |
1246 | if (list_empty(&mdev->submit.writes)) | 1252 | if (list_empty(&device->submit.writes)) |
1247 | break; | 1253 | break; |
1248 | 1254 | ||
1249 | spin_lock(&mdev->submit.lock); | 1255 | spin_lock(&device->submit.lock); |
1250 | list_splice_tail_init(&mdev->submit.writes, &more_incoming); | 1256 | list_splice_tail_init(&device->submit.writes, &more_incoming); |
1251 | spin_unlock(&mdev->submit.lock); | 1257 | spin_unlock(&device->submit.lock); |
1252 | 1258 | ||
1253 | if (list_empty(&more_incoming)) | 1259 | if (list_empty(&more_incoming)) |
1254 | break; | 1260 | break; |
1255 | 1261 | ||
1256 | made_progress = prepare_al_transaction_nonblock(mdev, &more_incoming, &more_pending); | 1262 | made_progress = prepare_al_transaction_nonblock(device, &more_incoming, &more_pending); |
1257 | 1263 | ||
1258 | list_splice_tail_init(&more_pending, &pending); | 1264 | list_splice_tail_init(&more_pending, &pending); |
1259 | list_splice_tail_init(&more_incoming, &incoming); | 1265 | list_splice_tail_init(&more_incoming, &incoming); |
@@ -1261,18 +1267,18 @@ void do_submit(struct work_struct *ws) | |||
1261 | if (!made_progress) | 1267 | if (!made_progress) |
1262 | break; | 1268 | break; |
1263 | } | 1269 | } |
1264 | drbd_al_begin_io_commit(mdev, false); | 1270 | drbd_al_begin_io_commit(device, false); |
1265 | 1271 | ||
1266 | list_for_each_entry_safe(req, tmp, &pending, tl_requests) { | 1272 | list_for_each_entry_safe(req, tmp, &pending, tl_requests) { |
1267 | list_del_init(&req->tl_requests); | 1273 | list_del_init(&req->tl_requests); |
1268 | drbd_send_and_submit(mdev, req); | 1274 | drbd_send_and_submit(device, req); |
1269 | } | 1275 | } |
1270 | } | 1276 | } |
1271 | } | 1277 | } |
1272 | 1278 | ||
1273 | void drbd_make_request(struct request_queue *q, struct bio *bio) | 1279 | void drbd_make_request(struct request_queue *q, struct bio *bio) |
1274 | { | 1280 | { |
1275 | struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata; | 1281 | struct drbd_device *device = (struct drbd_device *) q->queuedata; |
1276 | unsigned long start_time; | 1282 | unsigned long start_time; |
1277 | 1283 | ||
1278 | start_time = jiffies; | 1284 | start_time = jiffies; |
@@ -1280,10 +1286,10 @@ void drbd_make_request(struct request_queue *q, struct bio *bio) | |||
1280 | /* | 1286 | /* |
1281 | * what we "blindly" assume: | 1287 | * what we "blindly" assume: |
1282 | */ | 1288 | */ |
1283 | D_ASSERT(IS_ALIGNED(bio->bi_iter.bi_size, 512)); | 1289 | D_ASSERT(device, IS_ALIGNED(bio->bi_iter.bi_size, 512)); |
1284 | 1290 | ||
1285 | inc_ap_bio(mdev); | 1291 | inc_ap_bio(device); |
1286 | __drbd_make_request(mdev, bio, start_time); | 1292 | __drbd_make_request(device, bio, start_time); |
1287 | } | 1293 | } |
1288 | 1294 | ||
1289 | /* This is called by bio_add_page(). | 1295 | /* This is called by bio_add_page(). |
@@ -1300,32 +1306,32 @@ void drbd_make_request(struct request_queue *q, struct bio *bio) | |||
1300 | */ | 1306 | */ |
1301 | int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec) | 1307 | int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec) |
1302 | { | 1308 | { |
1303 | struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata; | 1309 | struct drbd_device *device = (struct drbd_device *) q->queuedata; |
1304 | unsigned int bio_size = bvm->bi_size; | 1310 | unsigned int bio_size = bvm->bi_size; |
1305 | int limit = DRBD_MAX_BIO_SIZE; | 1311 | int limit = DRBD_MAX_BIO_SIZE; |
1306 | int backing_limit; | 1312 | int backing_limit; |
1307 | 1313 | ||
1308 | if (bio_size && get_ldev(mdev)) { | 1314 | if (bio_size && get_ldev(device)) { |
1309 | unsigned int max_hw_sectors = queue_max_hw_sectors(q); | 1315 | unsigned int max_hw_sectors = queue_max_hw_sectors(q); |
1310 | struct request_queue * const b = | 1316 | struct request_queue * const b = |
1311 | mdev->ldev->backing_bdev->bd_disk->queue; | 1317 | device->ldev->backing_bdev->bd_disk->queue; |
1312 | if (b->merge_bvec_fn) { | 1318 | if (b->merge_bvec_fn) { |
1313 | backing_limit = b->merge_bvec_fn(b, bvm, bvec); | 1319 | backing_limit = b->merge_bvec_fn(b, bvm, bvec); |
1314 | limit = min(limit, backing_limit); | 1320 | limit = min(limit, backing_limit); |
1315 | } | 1321 | } |
1316 | put_ldev(mdev); | 1322 | put_ldev(device); |
1317 | if ((limit >> 9) > max_hw_sectors) | 1323 | if ((limit >> 9) > max_hw_sectors) |
1318 | limit = max_hw_sectors << 9; | 1324 | limit = max_hw_sectors << 9; |
1319 | } | 1325 | } |
1320 | return limit; | 1326 | return limit; |
1321 | } | 1327 | } |
1322 | 1328 | ||
1323 | struct drbd_request *find_oldest_request(struct drbd_tconn *tconn) | 1329 | static struct drbd_request *find_oldest_request(struct drbd_connection *connection) |
1324 | { | 1330 | { |
1325 | /* Walk the transfer log, | 1331 | /* Walk the transfer log, |
1326 | * and find the oldest not yet completed request */ | 1332 | * and find the oldest not yet completed request */ |
1327 | struct drbd_request *r; | 1333 | struct drbd_request *r; |
1328 | list_for_each_entry(r, &tconn->transfer_log, tl_requests) { | 1334 | list_for_each_entry(r, &connection->transfer_log, tl_requests) { |
1329 | if (atomic_read(&r->completion_ref)) | 1335 | if (atomic_read(&r->completion_ref)) |
1330 | return r; | 1336 | return r; |
1331 | } | 1337 | } |
@@ -1334,21 +1340,21 @@ struct drbd_request *find_oldest_request(struct drbd_tconn *tconn) | |||
1334 | 1340 | ||
1335 | void request_timer_fn(unsigned long data) | 1341 | void request_timer_fn(unsigned long data) |
1336 | { | 1342 | { |
1337 | struct drbd_conf *mdev = (struct drbd_conf *) data; | 1343 | struct drbd_device *device = (struct drbd_device *) data; |
1338 | struct drbd_tconn *tconn = mdev->tconn; | 1344 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1339 | struct drbd_request *req; /* oldest request */ | 1345 | struct drbd_request *req; /* oldest request */ |
1340 | struct net_conf *nc; | 1346 | struct net_conf *nc; |
1341 | unsigned long ent = 0, dt = 0, et, nt; /* effective timeout = ko_count * timeout */ | 1347 | unsigned long ent = 0, dt = 0, et, nt; /* effective timeout = ko_count * timeout */ |
1342 | unsigned long now; | 1348 | unsigned long now; |
1343 | 1349 | ||
1344 | rcu_read_lock(); | 1350 | rcu_read_lock(); |
1345 | nc = rcu_dereference(tconn->net_conf); | 1351 | nc = rcu_dereference(connection->net_conf); |
1346 | if (nc && mdev->state.conn >= C_WF_REPORT_PARAMS) | 1352 | if (nc && device->state.conn >= C_WF_REPORT_PARAMS) |
1347 | ent = nc->timeout * HZ/10 * nc->ko_count; | 1353 | ent = nc->timeout * HZ/10 * nc->ko_count; |
1348 | 1354 | ||
1349 | if (get_ldev(mdev)) { /* implicit state.disk >= D_INCONSISTENT */ | 1355 | if (get_ldev(device)) { /* implicit state.disk >= D_INCONSISTENT */ |
1350 | dt = rcu_dereference(mdev->ldev->disk_conf)->disk_timeout * HZ / 10; | 1356 | dt = rcu_dereference(device->ldev->disk_conf)->disk_timeout * HZ / 10; |
1351 | put_ldev(mdev); | 1357 | put_ldev(device); |
1352 | } | 1358 | } |
1353 | rcu_read_unlock(); | 1359 | rcu_read_unlock(); |
1354 | 1360 | ||
@@ -1359,11 +1365,11 @@ void request_timer_fn(unsigned long data) | |||
1359 | 1365 | ||
1360 | now = jiffies; | 1366 | now = jiffies; |
1361 | 1367 | ||
1362 | spin_lock_irq(&tconn->req_lock); | 1368 | spin_lock_irq(&device->resource->req_lock); |
1363 | req = find_oldest_request(tconn); | 1369 | req = find_oldest_request(connection); |
1364 | if (!req) { | 1370 | if (!req) { |
1365 | spin_unlock_irq(&tconn->req_lock); | 1371 | spin_unlock_irq(&device->resource->req_lock); |
1366 | mod_timer(&mdev->request_timer, now + et); | 1372 | mod_timer(&device->request_timer, now + et); |
1367 | return; | 1373 | return; |
1368 | } | 1374 | } |
1369 | 1375 | ||
@@ -1385,17 +1391,17 @@ void request_timer_fn(unsigned long data) | |||
1385 | */ | 1391 | */ |
1386 | if (ent && req->rq_state & RQ_NET_PENDING && | 1392 | if (ent && req->rq_state & RQ_NET_PENDING && |
1387 | time_after(now, req->start_time + ent) && | 1393 | time_after(now, req->start_time + ent) && |
1388 | !time_in_range(now, tconn->last_reconnect_jif, tconn->last_reconnect_jif + ent)) { | 1394 | !time_in_range(now, connection->last_reconnect_jif, connection->last_reconnect_jif + ent)) { |
1389 | dev_warn(DEV, "Remote failed to finish a request within ko-count * timeout\n"); | 1395 | drbd_warn(device, "Remote failed to finish a request within ko-count * timeout\n"); |
1390 | _drbd_set_state(_NS(mdev, conn, C_TIMEOUT), CS_VERBOSE | CS_HARD, NULL); | 1396 | _drbd_set_state(_NS(device, conn, C_TIMEOUT), CS_VERBOSE | CS_HARD, NULL); |
1391 | } | 1397 | } |
1392 | if (dt && req->rq_state & RQ_LOCAL_PENDING && req->w.mdev == mdev && | 1398 | if (dt && req->rq_state & RQ_LOCAL_PENDING && req->device == device && |
1393 | time_after(now, req->start_time + dt) && | 1399 | time_after(now, req->start_time + dt) && |
1394 | !time_in_range(now, mdev->last_reattach_jif, mdev->last_reattach_jif + dt)) { | 1400 | !time_in_range(now, device->last_reattach_jif, device->last_reattach_jif + dt)) { |
1395 | dev_warn(DEV, "Local backing device failed to meet the disk-timeout\n"); | 1401 | drbd_warn(device, "Local backing device failed to meet the disk-timeout\n"); |
1396 | __drbd_chk_io_error(mdev, DRBD_FORCE_DETACH); | 1402 | __drbd_chk_io_error(device, DRBD_FORCE_DETACH); |
1397 | } | 1403 | } |
1398 | nt = (time_after(now, req->start_time + et) ? now : req->start_time) + et; | 1404 | nt = (time_after(now, req->start_time + et) ? now : req->start_time) + et; |
1399 | spin_unlock_irq(&tconn->req_lock); | 1405 | spin_unlock_irq(&connection->resource->req_lock); |
1400 | mod_timer(&mdev->request_timer, nt); | 1406 | mod_timer(&device->request_timer, nt); |
1401 | } | 1407 | } |
diff --git a/drivers/block/drbd/drbd_req.h b/drivers/block/drbd/drbd_req.h index 28e15d91197a..c684c963538e 100644 --- a/drivers/block/drbd/drbd_req.h +++ b/drivers/block/drbd/drbd_req.h | |||
@@ -275,17 +275,17 @@ struct bio_and_error { | |||
275 | int error; | 275 | int error; |
276 | }; | 276 | }; |
277 | 277 | ||
278 | extern void start_new_tl_epoch(struct drbd_tconn *tconn); | 278 | extern void start_new_tl_epoch(struct drbd_connection *connection); |
279 | extern void drbd_req_destroy(struct kref *kref); | 279 | extern void drbd_req_destroy(struct kref *kref); |
280 | extern void _req_may_be_done(struct drbd_request *req, | 280 | extern void _req_may_be_done(struct drbd_request *req, |
281 | struct bio_and_error *m); | 281 | struct bio_and_error *m); |
282 | extern int __req_mod(struct drbd_request *req, enum drbd_req_event what, | 282 | extern int __req_mod(struct drbd_request *req, enum drbd_req_event what, |
283 | struct bio_and_error *m); | 283 | struct bio_and_error *m); |
284 | extern void complete_master_bio(struct drbd_conf *mdev, | 284 | extern void complete_master_bio(struct drbd_device *device, |
285 | struct bio_and_error *m); | 285 | struct bio_and_error *m); |
286 | extern void request_timer_fn(unsigned long data); | 286 | extern void request_timer_fn(unsigned long data); |
287 | extern void tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what); | 287 | extern void tl_restart(struct drbd_connection *connection, enum drbd_req_event what); |
288 | extern void _tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what); | 288 | extern void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what); |
289 | 289 | ||
290 | /* this is in drbd_main.c */ | 290 | /* this is in drbd_main.c */ |
291 | extern void drbd_restart_request(struct drbd_request *req); | 291 | extern void drbd_restart_request(struct drbd_request *req); |
@@ -294,14 +294,14 @@ extern void drbd_restart_request(struct drbd_request *req); | |||
294 | * outside the spinlock, e.g. when walking some list on cleanup. */ | 294 | * outside the spinlock, e.g. when walking some list on cleanup. */ |
295 | static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what) | 295 | static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what) |
296 | { | 296 | { |
297 | struct drbd_conf *mdev = req->w.mdev; | 297 | struct drbd_device *device = req->device; |
298 | struct bio_and_error m; | 298 | struct bio_and_error m; |
299 | int rv; | 299 | int rv; |
300 | 300 | ||
301 | /* __req_mod possibly frees req, do not touch req after that! */ | 301 | /* __req_mod possibly frees req, do not touch req after that! */ |
302 | rv = __req_mod(req, what, &m); | 302 | rv = __req_mod(req, what, &m); |
303 | if (m.bio) | 303 | if (m.bio) |
304 | complete_master_bio(mdev, &m); | 304 | complete_master_bio(device, &m); |
305 | 305 | ||
306 | return rv; | 306 | return rv; |
307 | } | 307 | } |
@@ -314,16 +314,16 @@ static inline int req_mod(struct drbd_request *req, | |||
314 | enum drbd_req_event what) | 314 | enum drbd_req_event what) |
315 | { | 315 | { |
316 | unsigned long flags; | 316 | unsigned long flags; |
317 | struct drbd_conf *mdev = req->w.mdev; | 317 | struct drbd_device *device = req->device; |
318 | struct bio_and_error m; | 318 | struct bio_and_error m; |
319 | int rv; | 319 | int rv; |
320 | 320 | ||
321 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 321 | spin_lock_irqsave(&device->resource->req_lock, flags); |
322 | rv = __req_mod(req, what, &m); | 322 | rv = __req_mod(req, what, &m); |
323 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 323 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
324 | 324 | ||
325 | if (m.bio) | 325 | if (m.bio) |
326 | complete_master_bio(mdev, &m); | 326 | complete_master_bio(device, &m); |
327 | 327 | ||
328 | return rv; | 328 | return rv; |
329 | } | 329 | } |
diff --git a/drivers/block/drbd/drbd_state.c b/drivers/block/drbd/drbd_state.c index 216d47b7e88b..1a84345a3868 100644 --- a/drivers/block/drbd/drbd_state.c +++ b/drivers/block/drbd/drbd_state.c | |||
@@ -27,13 +27,12 @@ | |||
27 | 27 | ||
28 | #include <linux/drbd_limits.h> | 28 | #include <linux/drbd_limits.h> |
29 | #include "drbd_int.h" | 29 | #include "drbd_int.h" |
30 | #include "drbd_protocol.h" | ||
30 | #include "drbd_req.h" | 31 | #include "drbd_req.h" |
31 | 32 | ||
32 | /* in drbd_main.c */ | ||
33 | extern void tl_abort_disk_io(struct drbd_conf *mdev); | ||
34 | |||
35 | struct after_state_chg_work { | 33 | struct after_state_chg_work { |
36 | struct drbd_work w; | 34 | struct drbd_work w; |
35 | struct drbd_device *device; | ||
37 | union drbd_state os; | 36 | union drbd_state os; |
38 | union drbd_state ns; | 37 | union drbd_state ns; |
39 | enum chg_state_flags flags; | 38 | enum chg_state_flags flags; |
@@ -50,12 +49,12 @@ enum sanitize_state_warnings { | |||
50 | }; | 49 | }; |
51 | 50 | ||
52 | static int w_after_state_ch(struct drbd_work *w, int unused); | 51 | static int w_after_state_ch(struct drbd_work *w, int unused); |
53 | static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | 52 | static void after_state_ch(struct drbd_device *device, union drbd_state os, |
54 | union drbd_state ns, enum chg_state_flags flags); | 53 | union drbd_state ns, enum chg_state_flags flags); |
55 | static enum drbd_state_rv is_valid_state(struct drbd_conf *, union drbd_state); | 54 | static enum drbd_state_rv is_valid_state(struct drbd_device *, union drbd_state); |
56 | static enum drbd_state_rv is_valid_soft_transition(union drbd_state, union drbd_state, struct drbd_tconn *); | 55 | static enum drbd_state_rv is_valid_soft_transition(union drbd_state, union drbd_state, struct drbd_connection *); |
57 | static enum drbd_state_rv is_valid_transition(union drbd_state os, union drbd_state ns); | 56 | static enum drbd_state_rv is_valid_transition(union drbd_state os, union drbd_state ns); |
58 | static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state ns, | 57 | static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state ns, |
59 | enum sanitize_state_warnings *warn); | 58 | enum sanitize_state_warnings *warn); |
60 | 59 | ||
61 | static inline bool is_susp(union drbd_state s) | 60 | static inline bool is_susp(union drbd_state s) |
@@ -63,17 +62,18 @@ static inline bool is_susp(union drbd_state s) | |||
63 | return s.susp || s.susp_nod || s.susp_fen; | 62 | return s.susp || s.susp_nod || s.susp_fen; |
64 | } | 63 | } |
65 | 64 | ||
66 | bool conn_all_vols_unconf(struct drbd_tconn *tconn) | 65 | bool conn_all_vols_unconf(struct drbd_connection *connection) |
67 | { | 66 | { |
68 | struct drbd_conf *mdev; | 67 | struct drbd_peer_device *peer_device; |
69 | bool rv = true; | 68 | bool rv = true; |
70 | int vnr; | 69 | int vnr; |
71 | 70 | ||
72 | rcu_read_lock(); | 71 | rcu_read_lock(); |
73 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 72 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
74 | if (mdev->state.disk != D_DISKLESS || | 73 | struct drbd_device *device = peer_device->device; |
75 | mdev->state.conn != C_STANDALONE || | 74 | if (device->state.disk != D_DISKLESS || |
76 | mdev->state.role != R_SECONDARY) { | 75 | device->state.conn != C_STANDALONE || |
76 | device->state.role != R_SECONDARY) { | ||
77 | rv = false; | 77 | rv = false; |
78 | break; | 78 | break; |
79 | } | 79 | } |
@@ -102,99 +102,111 @@ static enum drbd_role min_role(enum drbd_role role1, enum drbd_role role2) | |||
102 | return R_PRIMARY; | 102 | return R_PRIMARY; |
103 | } | 103 | } |
104 | 104 | ||
105 | enum drbd_role conn_highest_role(struct drbd_tconn *tconn) | 105 | enum drbd_role conn_highest_role(struct drbd_connection *connection) |
106 | { | 106 | { |
107 | enum drbd_role role = R_UNKNOWN; | 107 | enum drbd_role role = R_UNKNOWN; |
108 | struct drbd_conf *mdev; | 108 | struct drbd_peer_device *peer_device; |
109 | int vnr; | 109 | int vnr; |
110 | 110 | ||
111 | rcu_read_lock(); | 111 | rcu_read_lock(); |
112 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 112 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
113 | role = max_role(role, mdev->state.role); | 113 | struct drbd_device *device = peer_device->device; |
114 | role = max_role(role, device->state.role); | ||
115 | } | ||
114 | rcu_read_unlock(); | 116 | rcu_read_unlock(); |
115 | 117 | ||
116 | return role; | 118 | return role; |
117 | } | 119 | } |
118 | 120 | ||
119 | enum drbd_role conn_highest_peer(struct drbd_tconn *tconn) | 121 | enum drbd_role conn_highest_peer(struct drbd_connection *connection) |
120 | { | 122 | { |
121 | enum drbd_role peer = R_UNKNOWN; | 123 | enum drbd_role peer = R_UNKNOWN; |
122 | struct drbd_conf *mdev; | 124 | struct drbd_peer_device *peer_device; |
123 | int vnr; | 125 | int vnr; |
124 | 126 | ||
125 | rcu_read_lock(); | 127 | rcu_read_lock(); |
126 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 128 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
127 | peer = max_role(peer, mdev->state.peer); | 129 | struct drbd_device *device = peer_device->device; |
130 | peer = max_role(peer, device->state.peer); | ||
131 | } | ||
128 | rcu_read_unlock(); | 132 | rcu_read_unlock(); |
129 | 133 | ||
130 | return peer; | 134 | return peer; |
131 | } | 135 | } |
132 | 136 | ||
133 | enum drbd_disk_state conn_highest_disk(struct drbd_tconn *tconn) | 137 | enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection) |
134 | { | 138 | { |
135 | enum drbd_disk_state ds = D_DISKLESS; | 139 | enum drbd_disk_state ds = D_DISKLESS; |
136 | struct drbd_conf *mdev; | 140 | struct drbd_peer_device *peer_device; |
137 | int vnr; | 141 | int vnr; |
138 | 142 | ||
139 | rcu_read_lock(); | 143 | rcu_read_lock(); |
140 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 144 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
141 | ds = max_t(enum drbd_disk_state, ds, mdev->state.disk); | 145 | struct drbd_device *device = peer_device->device; |
146 | ds = max_t(enum drbd_disk_state, ds, device->state.disk); | ||
147 | } | ||
142 | rcu_read_unlock(); | 148 | rcu_read_unlock(); |
143 | 149 | ||
144 | return ds; | 150 | return ds; |
145 | } | 151 | } |
146 | 152 | ||
147 | enum drbd_disk_state conn_lowest_disk(struct drbd_tconn *tconn) | 153 | enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection) |
148 | { | 154 | { |
149 | enum drbd_disk_state ds = D_MASK; | 155 | enum drbd_disk_state ds = D_MASK; |
150 | struct drbd_conf *mdev; | 156 | struct drbd_peer_device *peer_device; |
151 | int vnr; | 157 | int vnr; |
152 | 158 | ||
153 | rcu_read_lock(); | 159 | rcu_read_lock(); |
154 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 160 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
155 | ds = min_t(enum drbd_disk_state, ds, mdev->state.disk); | 161 | struct drbd_device *device = peer_device->device; |
162 | ds = min_t(enum drbd_disk_state, ds, device->state.disk); | ||
163 | } | ||
156 | rcu_read_unlock(); | 164 | rcu_read_unlock(); |
157 | 165 | ||
158 | return ds; | 166 | return ds; |
159 | } | 167 | } |
160 | 168 | ||
161 | enum drbd_disk_state conn_highest_pdsk(struct drbd_tconn *tconn) | 169 | enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection) |
162 | { | 170 | { |
163 | enum drbd_disk_state ds = D_DISKLESS; | 171 | enum drbd_disk_state ds = D_DISKLESS; |
164 | struct drbd_conf *mdev; | 172 | struct drbd_peer_device *peer_device; |
165 | int vnr; | 173 | int vnr; |
166 | 174 | ||
167 | rcu_read_lock(); | 175 | rcu_read_lock(); |
168 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 176 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
169 | ds = max_t(enum drbd_disk_state, ds, mdev->state.pdsk); | 177 | struct drbd_device *device = peer_device->device; |
178 | ds = max_t(enum drbd_disk_state, ds, device->state.pdsk); | ||
179 | } | ||
170 | rcu_read_unlock(); | 180 | rcu_read_unlock(); |
171 | 181 | ||
172 | return ds; | 182 | return ds; |
173 | } | 183 | } |
174 | 184 | ||
175 | enum drbd_conns conn_lowest_conn(struct drbd_tconn *tconn) | 185 | enum drbd_conns conn_lowest_conn(struct drbd_connection *connection) |
176 | { | 186 | { |
177 | enum drbd_conns conn = C_MASK; | 187 | enum drbd_conns conn = C_MASK; |
178 | struct drbd_conf *mdev; | 188 | struct drbd_peer_device *peer_device; |
179 | int vnr; | 189 | int vnr; |
180 | 190 | ||
181 | rcu_read_lock(); | 191 | rcu_read_lock(); |
182 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 192 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
183 | conn = min_t(enum drbd_conns, conn, mdev->state.conn); | 193 | struct drbd_device *device = peer_device->device; |
194 | conn = min_t(enum drbd_conns, conn, device->state.conn); | ||
195 | } | ||
184 | rcu_read_unlock(); | 196 | rcu_read_unlock(); |
185 | 197 | ||
186 | return conn; | 198 | return conn; |
187 | } | 199 | } |
188 | 200 | ||
189 | static bool no_peer_wf_report_params(struct drbd_tconn *tconn) | 201 | static bool no_peer_wf_report_params(struct drbd_connection *connection) |
190 | { | 202 | { |
191 | struct drbd_conf *mdev; | 203 | struct drbd_peer_device *peer_device; |
192 | int vnr; | 204 | int vnr; |
193 | bool rv = true; | 205 | bool rv = true; |
194 | 206 | ||
195 | rcu_read_lock(); | 207 | rcu_read_lock(); |
196 | idr_for_each_entry(&tconn->volumes, mdev, vnr) | 208 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
197 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { | 209 | if (peer_device->device->state.conn == C_WF_REPORT_PARAMS) { |
198 | rv = false; | 210 | rv = false; |
199 | break; | 211 | break; |
200 | } | 212 | } |
@@ -206,11 +218,11 @@ static bool no_peer_wf_report_params(struct drbd_tconn *tconn) | |||
206 | 218 | ||
207 | /** | 219 | /** |
208 | * cl_wide_st_chg() - true if the state change is a cluster wide one | 220 | * cl_wide_st_chg() - true if the state change is a cluster wide one |
209 | * @mdev: DRBD device. | 221 | * @device: DRBD device. |
210 | * @os: old (current) state. | 222 | * @os: old (current) state. |
211 | * @ns: new (wanted) state. | 223 | * @ns: new (wanted) state. |
212 | */ | 224 | */ |
213 | static int cl_wide_st_chg(struct drbd_conf *mdev, | 225 | static int cl_wide_st_chg(struct drbd_device *device, |
214 | union drbd_state os, union drbd_state ns) | 226 | union drbd_state os, union drbd_state ns) |
215 | { | 227 | { |
216 | return (os.conn >= C_CONNECTED && ns.conn >= C_CONNECTED && | 228 | return (os.conn >= C_CONNECTED && ns.conn >= C_CONNECTED && |
@@ -232,72 +244,72 @@ apply_mask_val(union drbd_state os, union drbd_state mask, union drbd_state val) | |||
232 | } | 244 | } |
233 | 245 | ||
234 | enum drbd_state_rv | 246 | enum drbd_state_rv |
235 | drbd_change_state(struct drbd_conf *mdev, enum chg_state_flags f, | 247 | drbd_change_state(struct drbd_device *device, enum chg_state_flags f, |
236 | union drbd_state mask, union drbd_state val) | 248 | union drbd_state mask, union drbd_state val) |
237 | { | 249 | { |
238 | unsigned long flags; | 250 | unsigned long flags; |
239 | union drbd_state ns; | 251 | union drbd_state ns; |
240 | enum drbd_state_rv rv; | 252 | enum drbd_state_rv rv; |
241 | 253 | ||
242 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 254 | spin_lock_irqsave(&device->resource->req_lock, flags); |
243 | ns = apply_mask_val(drbd_read_state(mdev), mask, val); | 255 | ns = apply_mask_val(drbd_read_state(device), mask, val); |
244 | rv = _drbd_set_state(mdev, ns, f, NULL); | 256 | rv = _drbd_set_state(device, ns, f, NULL); |
245 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 257 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
246 | 258 | ||
247 | return rv; | 259 | return rv; |
248 | } | 260 | } |
249 | 261 | ||
250 | /** | 262 | /** |
251 | * drbd_force_state() - Impose a change which happens outside our control on our state | 263 | * drbd_force_state() - Impose a change which happens outside our control on our state |
252 | * @mdev: DRBD device. | 264 | * @device: DRBD device. |
253 | * @mask: mask of state bits to change. | 265 | * @mask: mask of state bits to change. |
254 | * @val: value of new state bits. | 266 | * @val: value of new state bits. |
255 | */ | 267 | */ |
256 | void drbd_force_state(struct drbd_conf *mdev, | 268 | void drbd_force_state(struct drbd_device *device, |
257 | union drbd_state mask, union drbd_state val) | 269 | union drbd_state mask, union drbd_state val) |
258 | { | 270 | { |
259 | drbd_change_state(mdev, CS_HARD, mask, val); | 271 | drbd_change_state(device, CS_HARD, mask, val); |
260 | } | 272 | } |
261 | 273 | ||
262 | static enum drbd_state_rv | 274 | static enum drbd_state_rv |
263 | _req_st_cond(struct drbd_conf *mdev, union drbd_state mask, | 275 | _req_st_cond(struct drbd_device *device, union drbd_state mask, |
264 | union drbd_state val) | 276 | union drbd_state val) |
265 | { | 277 | { |
266 | union drbd_state os, ns; | 278 | union drbd_state os, ns; |
267 | unsigned long flags; | 279 | unsigned long flags; |
268 | enum drbd_state_rv rv; | 280 | enum drbd_state_rv rv; |
269 | 281 | ||
270 | if (test_and_clear_bit(CL_ST_CHG_SUCCESS, &mdev->flags)) | 282 | if (test_and_clear_bit(CL_ST_CHG_SUCCESS, &device->flags)) |
271 | return SS_CW_SUCCESS; | 283 | return SS_CW_SUCCESS; |
272 | 284 | ||
273 | if (test_and_clear_bit(CL_ST_CHG_FAIL, &mdev->flags)) | 285 | if (test_and_clear_bit(CL_ST_CHG_FAIL, &device->flags)) |
274 | return SS_CW_FAILED_BY_PEER; | 286 | return SS_CW_FAILED_BY_PEER; |
275 | 287 | ||
276 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 288 | spin_lock_irqsave(&device->resource->req_lock, flags); |
277 | os = drbd_read_state(mdev); | 289 | os = drbd_read_state(device); |
278 | ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL); | 290 | ns = sanitize_state(device, apply_mask_val(os, mask, val), NULL); |
279 | rv = is_valid_transition(os, ns); | 291 | rv = is_valid_transition(os, ns); |
280 | if (rv >= SS_SUCCESS) | 292 | if (rv >= SS_SUCCESS) |
281 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ | 293 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ |
282 | 294 | ||
283 | if (!cl_wide_st_chg(mdev, os, ns)) | 295 | if (!cl_wide_st_chg(device, os, ns)) |
284 | rv = SS_CW_NO_NEED; | 296 | rv = SS_CW_NO_NEED; |
285 | if (rv == SS_UNKNOWN_ERROR) { | 297 | if (rv == SS_UNKNOWN_ERROR) { |
286 | rv = is_valid_state(mdev, ns); | 298 | rv = is_valid_state(device, ns); |
287 | if (rv >= SS_SUCCESS) { | 299 | if (rv >= SS_SUCCESS) { |
288 | rv = is_valid_soft_transition(os, ns, mdev->tconn); | 300 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
289 | if (rv >= SS_SUCCESS) | 301 | if (rv >= SS_SUCCESS) |
290 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ | 302 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ |
291 | } | 303 | } |
292 | } | 304 | } |
293 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 305 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
294 | 306 | ||
295 | return rv; | 307 | return rv; |
296 | } | 308 | } |
297 | 309 | ||
298 | /** | 310 | /** |
299 | * drbd_req_state() - Perform an eventually cluster wide state change | 311 | * drbd_req_state() - Perform an eventually cluster wide state change |
300 | * @mdev: DRBD device. | 312 | * @device: DRBD device. |
301 | * @mask: mask of state bits to change. | 313 | * @mask: mask of state bits to change. |
302 | * @val: value of new state bits. | 314 | * @val: value of new state bits. |
303 | * @f: flags | 315 | * @f: flags |
@@ -306,7 +318,7 @@ _req_st_cond(struct drbd_conf *mdev, union drbd_state mask, | |||
306 | * _drbd_request_state(). | 318 | * _drbd_request_state(). |
307 | */ | 319 | */ |
308 | static enum drbd_state_rv | 320 | static enum drbd_state_rv |
309 | drbd_req_state(struct drbd_conf *mdev, union drbd_state mask, | 321 | drbd_req_state(struct drbd_device *device, union drbd_state mask, |
310 | union drbd_state val, enum chg_state_flags f) | 322 | union drbd_state val, enum chg_state_flags f) |
311 | { | 323 | { |
312 | struct completion done; | 324 | struct completion done; |
@@ -317,68 +329,68 @@ drbd_req_state(struct drbd_conf *mdev, union drbd_state mask, | |||
317 | init_completion(&done); | 329 | init_completion(&done); |
318 | 330 | ||
319 | if (f & CS_SERIALIZE) | 331 | if (f & CS_SERIALIZE) |
320 | mutex_lock(mdev->state_mutex); | 332 | mutex_lock(device->state_mutex); |
321 | 333 | ||
322 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 334 | spin_lock_irqsave(&device->resource->req_lock, flags); |
323 | os = drbd_read_state(mdev); | 335 | os = drbd_read_state(device); |
324 | ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL); | 336 | ns = sanitize_state(device, apply_mask_val(os, mask, val), NULL); |
325 | rv = is_valid_transition(os, ns); | 337 | rv = is_valid_transition(os, ns); |
326 | if (rv < SS_SUCCESS) { | 338 | if (rv < SS_SUCCESS) { |
327 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 339 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
328 | goto abort; | 340 | goto abort; |
329 | } | 341 | } |
330 | 342 | ||
331 | if (cl_wide_st_chg(mdev, os, ns)) { | 343 | if (cl_wide_st_chg(device, os, ns)) { |
332 | rv = is_valid_state(mdev, ns); | 344 | rv = is_valid_state(device, ns); |
333 | if (rv == SS_SUCCESS) | 345 | if (rv == SS_SUCCESS) |
334 | rv = is_valid_soft_transition(os, ns, mdev->tconn); | 346 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
335 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 347 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
336 | 348 | ||
337 | if (rv < SS_SUCCESS) { | 349 | if (rv < SS_SUCCESS) { |
338 | if (f & CS_VERBOSE) | 350 | if (f & CS_VERBOSE) |
339 | print_st_err(mdev, os, ns, rv); | 351 | print_st_err(device, os, ns, rv); |
340 | goto abort; | 352 | goto abort; |
341 | } | 353 | } |
342 | 354 | ||
343 | if (drbd_send_state_req(mdev, mask, val)) { | 355 | if (drbd_send_state_req(first_peer_device(device), mask, val)) { |
344 | rv = SS_CW_FAILED_BY_PEER; | 356 | rv = SS_CW_FAILED_BY_PEER; |
345 | if (f & CS_VERBOSE) | 357 | if (f & CS_VERBOSE) |
346 | print_st_err(mdev, os, ns, rv); | 358 | print_st_err(device, os, ns, rv); |
347 | goto abort; | 359 | goto abort; |
348 | } | 360 | } |
349 | 361 | ||
350 | wait_event(mdev->state_wait, | 362 | wait_event(device->state_wait, |
351 | (rv = _req_st_cond(mdev, mask, val))); | 363 | (rv = _req_st_cond(device, mask, val))); |
352 | 364 | ||
353 | if (rv < SS_SUCCESS) { | 365 | if (rv < SS_SUCCESS) { |
354 | if (f & CS_VERBOSE) | 366 | if (f & CS_VERBOSE) |
355 | print_st_err(mdev, os, ns, rv); | 367 | print_st_err(device, os, ns, rv); |
356 | goto abort; | 368 | goto abort; |
357 | } | 369 | } |
358 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 370 | spin_lock_irqsave(&device->resource->req_lock, flags); |
359 | ns = apply_mask_val(drbd_read_state(mdev), mask, val); | 371 | ns = apply_mask_val(drbd_read_state(device), mask, val); |
360 | rv = _drbd_set_state(mdev, ns, f, &done); | 372 | rv = _drbd_set_state(device, ns, f, &done); |
361 | } else { | 373 | } else { |
362 | rv = _drbd_set_state(mdev, ns, f, &done); | 374 | rv = _drbd_set_state(device, ns, f, &done); |
363 | } | 375 | } |
364 | 376 | ||
365 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 377 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
366 | 378 | ||
367 | if (f & CS_WAIT_COMPLETE && rv == SS_SUCCESS) { | 379 | if (f & CS_WAIT_COMPLETE && rv == SS_SUCCESS) { |
368 | D_ASSERT(current != mdev->tconn->worker.task); | 380 | D_ASSERT(device, current != first_peer_device(device)->connection->worker.task); |
369 | wait_for_completion(&done); | 381 | wait_for_completion(&done); |
370 | } | 382 | } |
371 | 383 | ||
372 | abort: | 384 | abort: |
373 | if (f & CS_SERIALIZE) | 385 | if (f & CS_SERIALIZE) |
374 | mutex_unlock(mdev->state_mutex); | 386 | mutex_unlock(device->state_mutex); |
375 | 387 | ||
376 | return rv; | 388 | return rv; |
377 | } | 389 | } |
378 | 390 | ||
379 | /** | 391 | /** |
380 | * _drbd_request_state() - Request a state change (with flags) | 392 | * _drbd_request_state() - Request a state change (with flags) |
381 | * @mdev: DRBD device. | 393 | * @device: DRBD device. |
382 | * @mask: mask of state bits to change. | 394 | * @mask: mask of state bits to change. |
383 | * @val: value of new state bits. | 395 | * @val: value of new state bits. |
384 | * @f: flags | 396 | * @f: flags |
@@ -387,20 +399,20 @@ abort: | |||
387 | * flag, or when logging of failed state change requests is not desired. | 399 | * flag, or when logging of failed state change requests is not desired. |
388 | */ | 400 | */ |
389 | enum drbd_state_rv | 401 | enum drbd_state_rv |
390 | _drbd_request_state(struct drbd_conf *mdev, union drbd_state mask, | 402 | _drbd_request_state(struct drbd_device *device, union drbd_state mask, |
391 | union drbd_state val, enum chg_state_flags f) | 403 | union drbd_state val, enum chg_state_flags f) |
392 | { | 404 | { |
393 | enum drbd_state_rv rv; | 405 | enum drbd_state_rv rv; |
394 | 406 | ||
395 | wait_event(mdev->state_wait, | 407 | wait_event(device->state_wait, |
396 | (rv = drbd_req_state(mdev, mask, val, f)) != SS_IN_TRANSIENT_STATE); | 408 | (rv = drbd_req_state(device, mask, val, f)) != SS_IN_TRANSIENT_STATE); |
397 | 409 | ||
398 | return rv; | 410 | return rv; |
399 | } | 411 | } |
400 | 412 | ||
401 | static void print_st(struct drbd_conf *mdev, char *name, union drbd_state ns) | 413 | static void print_st(struct drbd_device *device, char *name, union drbd_state ns) |
402 | { | 414 | { |
403 | dev_err(DEV, " %s = { cs:%s ro:%s/%s ds:%s/%s %c%c%c%c%c%c }\n", | 415 | drbd_err(device, " %s = { cs:%s ro:%s/%s ds:%s/%s %c%c%c%c%c%c }\n", |
404 | name, | 416 | name, |
405 | drbd_conn_str(ns.conn), | 417 | drbd_conn_str(ns.conn), |
406 | drbd_role_str(ns.role), | 418 | drbd_role_str(ns.role), |
@@ -416,14 +428,14 @@ static void print_st(struct drbd_conf *mdev, char *name, union drbd_state ns) | |||
416 | ); | 428 | ); |
417 | } | 429 | } |
418 | 430 | ||
419 | void print_st_err(struct drbd_conf *mdev, union drbd_state os, | 431 | void print_st_err(struct drbd_device *device, union drbd_state os, |
420 | union drbd_state ns, enum drbd_state_rv err) | 432 | union drbd_state ns, enum drbd_state_rv err) |
421 | { | 433 | { |
422 | if (err == SS_IN_TRANSIENT_STATE) | 434 | if (err == SS_IN_TRANSIENT_STATE) |
423 | return; | 435 | return; |
424 | dev_err(DEV, "State change failed: %s\n", drbd_set_st_err_str(err)); | 436 | drbd_err(device, "State change failed: %s\n", drbd_set_st_err_str(err)); |
425 | print_st(mdev, " state", os); | 437 | print_st(device, " state", os); |
426 | print_st(mdev, "wanted", ns); | 438 | print_st(device, "wanted", ns); |
427 | } | 439 | } |
428 | 440 | ||
429 | static long print_state_change(char *pb, union drbd_state os, union drbd_state ns, | 441 | static long print_state_change(char *pb, union drbd_state os, union drbd_state ns, |
@@ -457,7 +469,7 @@ static long print_state_change(char *pb, union drbd_state os, union drbd_state n | |||
457 | return pbp - pb; | 469 | return pbp - pb; |
458 | } | 470 | } |
459 | 471 | ||
460 | static void drbd_pr_state_change(struct drbd_conf *mdev, union drbd_state os, union drbd_state ns, | 472 | static void drbd_pr_state_change(struct drbd_device *device, union drbd_state os, union drbd_state ns, |
461 | enum chg_state_flags flags) | 473 | enum chg_state_flags flags) |
462 | { | 474 | { |
463 | char pb[300]; | 475 | char pb[300]; |
@@ -479,10 +491,10 @@ static void drbd_pr_state_change(struct drbd_conf *mdev, union drbd_state os, un | |||
479 | ns.user_isp); | 491 | ns.user_isp); |
480 | 492 | ||
481 | if (pbp != pb) | 493 | if (pbp != pb) |
482 | dev_info(DEV, "%s\n", pb); | 494 | drbd_info(device, "%s\n", pb); |
483 | } | 495 | } |
484 | 496 | ||
485 | static void conn_pr_state_change(struct drbd_tconn *tconn, union drbd_state os, union drbd_state ns, | 497 | static void conn_pr_state_change(struct drbd_connection *connection, union drbd_state os, union drbd_state ns, |
486 | enum chg_state_flags flags) | 498 | enum chg_state_flags flags) |
487 | { | 499 | { |
488 | char pb[300]; | 500 | char pb[300]; |
@@ -496,17 +508,17 @@ static void conn_pr_state_change(struct drbd_tconn *tconn, union drbd_state os, | |||
496 | is_susp(ns)); | 508 | is_susp(ns)); |
497 | 509 | ||
498 | if (pbp != pb) | 510 | if (pbp != pb) |
499 | conn_info(tconn, "%s\n", pb); | 511 | drbd_info(connection, "%s\n", pb); |
500 | } | 512 | } |
501 | 513 | ||
502 | 514 | ||
503 | /** | 515 | /** |
504 | * is_valid_state() - Returns an SS_ error code if ns is not valid | 516 | * is_valid_state() - Returns an SS_ error code if ns is not valid |
505 | * @mdev: DRBD device. | 517 | * @device: DRBD device. |
506 | * @ns: State to consider. | 518 | * @ns: State to consider. |
507 | */ | 519 | */ |
508 | static enum drbd_state_rv | 520 | static enum drbd_state_rv |
509 | is_valid_state(struct drbd_conf *mdev, union drbd_state ns) | 521 | is_valid_state(struct drbd_device *device, union drbd_state ns) |
510 | { | 522 | { |
511 | /* See drbd_state_sw_errors in drbd_strings.c */ | 523 | /* See drbd_state_sw_errors in drbd_strings.c */ |
512 | 524 | ||
@@ -516,24 +528,24 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns) | |||
516 | 528 | ||
517 | rcu_read_lock(); | 529 | rcu_read_lock(); |
518 | fp = FP_DONT_CARE; | 530 | fp = FP_DONT_CARE; |
519 | if (get_ldev(mdev)) { | 531 | if (get_ldev(device)) { |
520 | fp = rcu_dereference(mdev->ldev->disk_conf)->fencing; | 532 | fp = rcu_dereference(device->ldev->disk_conf)->fencing; |
521 | put_ldev(mdev); | 533 | put_ldev(device); |
522 | } | 534 | } |
523 | 535 | ||
524 | nc = rcu_dereference(mdev->tconn->net_conf); | 536 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
525 | if (nc) { | 537 | if (nc) { |
526 | if (!nc->two_primaries && ns.role == R_PRIMARY) { | 538 | if (!nc->two_primaries && ns.role == R_PRIMARY) { |
527 | if (ns.peer == R_PRIMARY) | 539 | if (ns.peer == R_PRIMARY) |
528 | rv = SS_TWO_PRIMARIES; | 540 | rv = SS_TWO_PRIMARIES; |
529 | else if (conn_highest_peer(mdev->tconn) == R_PRIMARY) | 541 | else if (conn_highest_peer(first_peer_device(device)->connection) == R_PRIMARY) |
530 | rv = SS_O_VOL_PEER_PRI; | 542 | rv = SS_O_VOL_PEER_PRI; |
531 | } | 543 | } |
532 | } | 544 | } |
533 | 545 | ||
534 | if (rv <= 0) | 546 | if (rv <= 0) |
535 | /* already found a reason to abort */; | 547 | /* already found a reason to abort */; |
536 | else if (ns.role == R_SECONDARY && mdev->open_cnt) | 548 | else if (ns.role == R_SECONDARY && device->open_cnt) |
537 | rv = SS_DEVICE_IN_USE; | 549 | rv = SS_DEVICE_IN_USE; |
538 | 550 | ||
539 | else if (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.disk < D_UP_TO_DATE) | 551 | else if (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.disk < D_UP_TO_DATE) |
@@ -567,7 +579,7 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns) | |||
567 | rv = SS_NO_VERIFY_ALG; | 579 | rv = SS_NO_VERIFY_ALG; |
568 | 580 | ||
569 | else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && | 581 | else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && |
570 | mdev->tconn->agreed_pro_version < 88) | 582 | first_peer_device(device)->connection->agreed_pro_version < 88) |
571 | rv = SS_NOT_SUPPORTED; | 583 | rv = SS_NOT_SUPPORTED; |
572 | 584 | ||
573 | else if (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) | 585 | else if (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) |
@@ -589,12 +601,12 @@ is_valid_state(struct drbd_conf *mdev, union drbd_state ns) | |||
589 | * is_valid_soft_transition() - Returns an SS_ error code if the state transition is not possible | 601 | * is_valid_soft_transition() - Returns an SS_ error code if the state transition is not possible |
590 | * This function limits state transitions that may be declined by DRBD. I.e. | 602 | * This function limits state transitions that may be declined by DRBD. I.e. |
591 | * user requests (aka soft transitions). | 603 | * user requests (aka soft transitions). |
592 | * @mdev: DRBD device. | 604 | * @device: DRBD device. |
593 | * @ns: new state. | 605 | * @ns: new state. |
594 | * @os: old state. | 606 | * @os: old state. |
595 | */ | 607 | */ |
596 | static enum drbd_state_rv | 608 | static enum drbd_state_rv |
597 | is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_tconn *tconn) | 609 | is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_connection *connection) |
598 | { | 610 | { |
599 | enum drbd_state_rv rv = SS_SUCCESS; | 611 | enum drbd_state_rv rv = SS_SUCCESS; |
600 | 612 | ||
@@ -622,7 +634,7 @@ is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_t | |||
622 | 634 | ||
623 | /* While establishing a connection only allow cstate to change. | 635 | /* While establishing a connection only allow cstate to change. |
624 | Delay/refuse role changes, detach attach etc... */ | 636 | Delay/refuse role changes, detach attach etc... */ |
625 | if (test_bit(STATE_SENT, &tconn->flags) && | 637 | if (test_bit(STATE_SENT, &connection->flags) && |
626 | !(os.conn == C_WF_REPORT_PARAMS || | 638 | !(os.conn == C_WF_REPORT_PARAMS || |
627 | (ns.conn == C_WF_REPORT_PARAMS && os.conn == C_WF_CONNECTION))) | 639 | (ns.conn == C_WF_REPORT_PARAMS && os.conn == C_WF_CONNECTION))) |
628 | rv = SS_IN_TRANSIENT_STATE; | 640 | rv = SS_IN_TRANSIENT_STATE; |
@@ -703,7 +715,7 @@ is_valid_transition(union drbd_state os, union drbd_state ns) | |||
703 | return rv; | 715 | return rv; |
704 | } | 716 | } |
705 | 717 | ||
706 | static void print_sanitize_warnings(struct drbd_conf *mdev, enum sanitize_state_warnings warn) | 718 | static void print_sanitize_warnings(struct drbd_device *device, enum sanitize_state_warnings warn) |
707 | { | 719 | { |
708 | static const char *msg_table[] = { | 720 | static const char *msg_table[] = { |
709 | [NO_WARNING] = "", | 721 | [NO_WARNING] = "", |
@@ -715,12 +727,12 @@ static void print_sanitize_warnings(struct drbd_conf *mdev, enum sanitize_state_ | |||
715 | }; | 727 | }; |
716 | 728 | ||
717 | if (warn != NO_WARNING) | 729 | if (warn != NO_WARNING) |
718 | dev_warn(DEV, "%s\n", msg_table[warn]); | 730 | drbd_warn(device, "%s\n", msg_table[warn]); |
719 | } | 731 | } |
720 | 732 | ||
721 | /** | 733 | /** |
722 | * sanitize_state() - Resolves implicitly necessary additional changes to a state transition | 734 | * sanitize_state() - Resolves implicitly necessary additional changes to a state transition |
723 | * @mdev: DRBD device. | 735 | * @device: DRBD device. |
724 | * @os: old state. | 736 | * @os: old state. |
725 | * @ns: new state. | 737 | * @ns: new state. |
726 | * @warn_sync_abort: | 738 | * @warn_sync_abort: |
@@ -728,7 +740,7 @@ static void print_sanitize_warnings(struct drbd_conf *mdev, enum sanitize_state_ | |||
728 | * When we loose connection, we have to set the state of the peers disk (pdsk) | 740 | * When we loose connection, we have to set the state of the peers disk (pdsk) |
729 | * to D_UNKNOWN. This rule and many more along those lines are in this function. | 741 | * to D_UNKNOWN. This rule and many more along those lines are in this function. |
730 | */ | 742 | */ |
731 | static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state ns, | 743 | static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state ns, |
732 | enum sanitize_state_warnings *warn) | 744 | enum sanitize_state_warnings *warn) |
733 | { | 745 | { |
734 | enum drbd_fencing_p fp; | 746 | enum drbd_fencing_p fp; |
@@ -738,11 +750,11 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state | |||
738 | *warn = NO_WARNING; | 750 | *warn = NO_WARNING; |
739 | 751 | ||
740 | fp = FP_DONT_CARE; | 752 | fp = FP_DONT_CARE; |
741 | if (get_ldev(mdev)) { | 753 | if (get_ldev(device)) { |
742 | rcu_read_lock(); | 754 | rcu_read_lock(); |
743 | fp = rcu_dereference(mdev->ldev->disk_conf)->fencing; | 755 | fp = rcu_dereference(device->ldev->disk_conf)->fencing; |
744 | rcu_read_unlock(); | 756 | rcu_read_unlock(); |
745 | put_ldev(mdev); | 757 | put_ldev(device); |
746 | } | 758 | } |
747 | 759 | ||
748 | /* Implications from connection to peer and peer_isp */ | 760 | /* Implications from connection to peer and peer_isp */ |
@@ -768,17 +780,17 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state | |||
768 | 780 | ||
769 | /* Connection breaks down before we finished "Negotiating" */ | 781 | /* Connection breaks down before we finished "Negotiating" */ |
770 | if (ns.conn < C_CONNECTED && ns.disk == D_NEGOTIATING && | 782 | if (ns.conn < C_CONNECTED && ns.disk == D_NEGOTIATING && |
771 | get_ldev_if_state(mdev, D_NEGOTIATING)) { | 783 | get_ldev_if_state(device, D_NEGOTIATING)) { |
772 | if (mdev->ed_uuid == mdev->ldev->md.uuid[UI_CURRENT]) { | 784 | if (device->ed_uuid == device->ldev->md.uuid[UI_CURRENT]) { |
773 | ns.disk = mdev->new_state_tmp.disk; | 785 | ns.disk = device->new_state_tmp.disk; |
774 | ns.pdsk = mdev->new_state_tmp.pdsk; | 786 | ns.pdsk = device->new_state_tmp.pdsk; |
775 | } else { | 787 | } else { |
776 | if (warn) | 788 | if (warn) |
777 | *warn = CONNECTION_LOST_NEGOTIATING; | 789 | *warn = CONNECTION_LOST_NEGOTIATING; |
778 | ns.disk = D_DISKLESS; | 790 | ns.disk = D_DISKLESS; |
779 | ns.pdsk = D_UNKNOWN; | 791 | ns.pdsk = D_UNKNOWN; |
780 | } | 792 | } |
781 | put_ldev(mdev); | 793 | put_ldev(device); |
782 | } | 794 | } |
783 | 795 | ||
784 | /* D_CONSISTENT and D_OUTDATED vanish when we get connected */ | 796 | /* D_CONSISTENT and D_OUTDATED vanish when we get connected */ |
@@ -873,7 +885,7 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state | |||
873 | (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED)) | 885 | (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED)) |
874 | ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */ | 886 | ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */ |
875 | 887 | ||
876 | if (mdev->tconn->res_opts.on_no_data == OND_SUSPEND_IO && | 888 | if (device->resource->res_opts.on_no_data == OND_SUSPEND_IO && |
877 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)) | 889 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)) |
878 | ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */ | 890 | ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */ |
879 | 891 | ||
@@ -892,42 +904,42 @@ static union drbd_state sanitize_state(struct drbd_conf *mdev, union drbd_state | |||
892 | return ns; | 904 | return ns; |
893 | } | 905 | } |
894 | 906 | ||
895 | void drbd_resume_al(struct drbd_conf *mdev) | 907 | void drbd_resume_al(struct drbd_device *device) |
896 | { | 908 | { |
897 | if (test_and_clear_bit(AL_SUSPENDED, &mdev->flags)) | 909 | if (test_and_clear_bit(AL_SUSPENDED, &device->flags)) |
898 | dev_info(DEV, "Resumed AL updates\n"); | 910 | drbd_info(device, "Resumed AL updates\n"); |
899 | } | 911 | } |
900 | 912 | ||
901 | /* helper for __drbd_set_state */ | 913 | /* helper for __drbd_set_state */ |
902 | static void set_ov_position(struct drbd_conf *mdev, enum drbd_conns cs) | 914 | static void set_ov_position(struct drbd_device *device, enum drbd_conns cs) |
903 | { | 915 | { |
904 | if (mdev->tconn->agreed_pro_version < 90) | 916 | if (first_peer_device(device)->connection->agreed_pro_version < 90) |
905 | mdev->ov_start_sector = 0; | 917 | device->ov_start_sector = 0; |
906 | mdev->rs_total = drbd_bm_bits(mdev); | 918 | device->rs_total = drbd_bm_bits(device); |
907 | mdev->ov_position = 0; | 919 | device->ov_position = 0; |
908 | if (cs == C_VERIFY_T) { | 920 | if (cs == C_VERIFY_T) { |
909 | /* starting online verify from an arbitrary position | 921 | /* starting online verify from an arbitrary position |
910 | * does not fit well into the existing protocol. | 922 | * does not fit well into the existing protocol. |
911 | * on C_VERIFY_T, we initialize ov_left and friends | 923 | * on C_VERIFY_T, we initialize ov_left and friends |
912 | * implicitly in receive_DataRequest once the | 924 | * implicitly in receive_DataRequest once the |
913 | * first P_OV_REQUEST is received */ | 925 | * first P_OV_REQUEST is received */ |
914 | mdev->ov_start_sector = ~(sector_t)0; | 926 | device->ov_start_sector = ~(sector_t)0; |
915 | } else { | 927 | } else { |
916 | unsigned long bit = BM_SECT_TO_BIT(mdev->ov_start_sector); | 928 | unsigned long bit = BM_SECT_TO_BIT(device->ov_start_sector); |
917 | if (bit >= mdev->rs_total) { | 929 | if (bit >= device->rs_total) { |
918 | mdev->ov_start_sector = | 930 | device->ov_start_sector = |
919 | BM_BIT_TO_SECT(mdev->rs_total - 1); | 931 | BM_BIT_TO_SECT(device->rs_total - 1); |
920 | mdev->rs_total = 1; | 932 | device->rs_total = 1; |
921 | } else | 933 | } else |
922 | mdev->rs_total -= bit; | 934 | device->rs_total -= bit; |
923 | mdev->ov_position = mdev->ov_start_sector; | 935 | device->ov_position = device->ov_start_sector; |
924 | } | 936 | } |
925 | mdev->ov_left = mdev->rs_total; | 937 | device->ov_left = device->rs_total; |
926 | } | 938 | } |
927 | 939 | ||
928 | /** | 940 | /** |
929 | * __drbd_set_state() - Set a new DRBD state | 941 | * __drbd_set_state() - Set a new DRBD state |
930 | * @mdev: DRBD device. | 942 | * @device: DRBD device. |
931 | * @ns: new state. | 943 | * @ns: new state. |
932 | * @flags: Flags | 944 | * @flags: Flags |
933 | * @done: Optional completion, that will get completed after the after_state_ch() finished | 945 | * @done: Optional completion, that will get completed after the after_state_ch() finished |
@@ -935,7 +947,7 @@ static void set_ov_position(struct drbd_conf *mdev, enum drbd_conns cs) | |||
935 | * Caller needs to hold req_lock, and global_state_lock. Do not call directly. | 947 | * Caller needs to hold req_lock, and global_state_lock. Do not call directly. |
936 | */ | 948 | */ |
937 | enum drbd_state_rv | 949 | enum drbd_state_rv |
938 | __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | 950 | __drbd_set_state(struct drbd_device *device, union drbd_state ns, |
939 | enum chg_state_flags flags, struct completion *done) | 951 | enum chg_state_flags flags, struct completion *done) |
940 | { | 952 | { |
941 | union drbd_state os; | 953 | union drbd_state os; |
@@ -944,9 +956,9 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
944 | struct after_state_chg_work *ascw; | 956 | struct after_state_chg_work *ascw; |
945 | bool did_remote, should_do_remote; | 957 | bool did_remote, should_do_remote; |
946 | 958 | ||
947 | os = drbd_read_state(mdev); | 959 | os = drbd_read_state(device); |
948 | 960 | ||
949 | ns = sanitize_state(mdev, ns, &ssw); | 961 | ns = sanitize_state(device, ns, &ssw); |
950 | if (ns.i == os.i) | 962 | if (ns.i == os.i) |
951 | return SS_NOTHING_TO_DO; | 963 | return SS_NOTHING_TO_DO; |
952 | 964 | ||
@@ -958,32 +970,33 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
958 | /* pre-state-change checks ; only look at ns */ | 970 | /* pre-state-change checks ; only look at ns */ |
959 | /* See drbd_state_sw_errors in drbd_strings.c */ | 971 | /* See drbd_state_sw_errors in drbd_strings.c */ |
960 | 972 | ||
961 | rv = is_valid_state(mdev, ns); | 973 | rv = is_valid_state(device, ns); |
962 | if (rv < SS_SUCCESS) { | 974 | if (rv < SS_SUCCESS) { |
963 | /* If the old state was illegal as well, then let | 975 | /* If the old state was illegal as well, then let |
964 | this happen...*/ | 976 | this happen...*/ |
965 | 977 | ||
966 | if (is_valid_state(mdev, os) == rv) | 978 | if (is_valid_state(device, os) == rv) |
967 | rv = is_valid_soft_transition(os, ns, mdev->tconn); | 979 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
968 | } else | 980 | } else |
969 | rv = is_valid_soft_transition(os, ns, mdev->tconn); | 981 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
970 | } | 982 | } |
971 | 983 | ||
972 | if (rv < SS_SUCCESS) { | 984 | if (rv < SS_SUCCESS) { |
973 | if (flags & CS_VERBOSE) | 985 | if (flags & CS_VERBOSE) |
974 | print_st_err(mdev, os, ns, rv); | 986 | print_st_err(device, os, ns, rv); |
975 | return rv; | 987 | return rv; |
976 | } | 988 | } |
977 | 989 | ||
978 | print_sanitize_warnings(mdev, ssw); | 990 | print_sanitize_warnings(device, ssw); |
979 | 991 | ||
980 | drbd_pr_state_change(mdev, os, ns, flags); | 992 | drbd_pr_state_change(device, os, ns, flags); |
981 | 993 | ||
982 | /* Display changes to the susp* flags that where caused by the call to | 994 | /* Display changes to the susp* flags that where caused by the call to |
983 | sanitize_state(). Only display it here if we where not called from | 995 | sanitize_state(). Only display it here if we where not called from |
984 | _conn_request_state() */ | 996 | _conn_request_state() */ |
985 | if (!(flags & CS_DC_SUSP)) | 997 | if (!(flags & CS_DC_SUSP)) |
986 | conn_pr_state_change(mdev->tconn, os, ns, (flags & ~CS_DC_MASK) | CS_DC_SUSP); | 998 | conn_pr_state_change(first_peer_device(device)->connection, os, ns, |
999 | (flags & ~CS_DC_MASK) | CS_DC_SUSP); | ||
987 | 1000 | ||
988 | /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference | 1001 | /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference |
989 | * on the ldev here, to be sure the transition -> D_DISKLESS resp. | 1002 | * on the ldev here, to be sure the transition -> D_DISKLESS resp. |
@@ -991,55 +1004,55 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
991 | * after_state_ch works run, where we put_ldev again. */ | 1004 | * after_state_ch works run, where we put_ldev again. */ |
992 | if ((os.disk != D_FAILED && ns.disk == D_FAILED) || | 1005 | if ((os.disk != D_FAILED && ns.disk == D_FAILED) || |
993 | (os.disk != D_DISKLESS && ns.disk == D_DISKLESS)) | 1006 | (os.disk != D_DISKLESS && ns.disk == D_DISKLESS)) |
994 | atomic_inc(&mdev->local_cnt); | 1007 | atomic_inc(&device->local_cnt); |
995 | 1008 | ||
996 | did_remote = drbd_should_do_remote(mdev->state); | 1009 | did_remote = drbd_should_do_remote(device->state); |
997 | mdev->state.i = ns.i; | 1010 | device->state.i = ns.i; |
998 | should_do_remote = drbd_should_do_remote(mdev->state); | 1011 | should_do_remote = drbd_should_do_remote(device->state); |
999 | mdev->tconn->susp = ns.susp; | 1012 | device->resource->susp = ns.susp; |
1000 | mdev->tconn->susp_nod = ns.susp_nod; | 1013 | device->resource->susp_nod = ns.susp_nod; |
1001 | mdev->tconn->susp_fen = ns.susp_fen; | 1014 | device->resource->susp_fen = ns.susp_fen; |
1002 | 1015 | ||
1003 | /* put replicated vs not-replicated requests in seperate epochs */ | 1016 | /* put replicated vs not-replicated requests in seperate epochs */ |
1004 | if (did_remote != should_do_remote) | 1017 | if (did_remote != should_do_remote) |
1005 | start_new_tl_epoch(mdev->tconn); | 1018 | start_new_tl_epoch(first_peer_device(device)->connection); |
1006 | 1019 | ||
1007 | if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING) | 1020 | if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING) |
1008 | drbd_print_uuids(mdev, "attached to UUIDs"); | 1021 | drbd_print_uuids(device, "attached to UUIDs"); |
1009 | 1022 | ||
1010 | /* Wake up role changes, that were delayed because of connection establishing */ | 1023 | /* Wake up role changes, that were delayed because of connection establishing */ |
1011 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS && | 1024 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS && |
1012 | no_peer_wf_report_params(mdev->tconn)) | 1025 | no_peer_wf_report_params(first_peer_device(device)->connection)) |
1013 | clear_bit(STATE_SENT, &mdev->tconn->flags); | 1026 | clear_bit(STATE_SENT, &first_peer_device(device)->connection->flags); |
1014 | 1027 | ||
1015 | wake_up(&mdev->misc_wait); | 1028 | wake_up(&device->misc_wait); |
1016 | wake_up(&mdev->state_wait); | 1029 | wake_up(&device->state_wait); |
1017 | wake_up(&mdev->tconn->ping_wait); | 1030 | wake_up(&first_peer_device(device)->connection->ping_wait); |
1018 | 1031 | ||
1019 | /* Aborted verify run, or we reached the stop sector. | 1032 | /* Aborted verify run, or we reached the stop sector. |
1020 | * Log the last position, unless end-of-device. */ | 1033 | * Log the last position, unless end-of-device. */ |
1021 | if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) && | 1034 | if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) && |
1022 | ns.conn <= C_CONNECTED) { | 1035 | ns.conn <= C_CONNECTED) { |
1023 | mdev->ov_start_sector = | 1036 | device->ov_start_sector = |
1024 | BM_BIT_TO_SECT(drbd_bm_bits(mdev) - mdev->ov_left); | 1037 | BM_BIT_TO_SECT(drbd_bm_bits(device) - device->ov_left); |
1025 | if (mdev->ov_left) | 1038 | if (device->ov_left) |
1026 | dev_info(DEV, "Online Verify reached sector %llu\n", | 1039 | drbd_info(device, "Online Verify reached sector %llu\n", |
1027 | (unsigned long long)mdev->ov_start_sector); | 1040 | (unsigned long long)device->ov_start_sector); |
1028 | } | 1041 | } |
1029 | 1042 | ||
1030 | if ((os.conn == C_PAUSED_SYNC_T || os.conn == C_PAUSED_SYNC_S) && | 1043 | if ((os.conn == C_PAUSED_SYNC_T || os.conn == C_PAUSED_SYNC_S) && |
1031 | (ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE)) { | 1044 | (ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE)) { |
1032 | dev_info(DEV, "Syncer continues.\n"); | 1045 | drbd_info(device, "Syncer continues.\n"); |
1033 | mdev->rs_paused += (long)jiffies | 1046 | device->rs_paused += (long)jiffies |
1034 | -(long)mdev->rs_mark_time[mdev->rs_last_mark]; | 1047 | -(long)device->rs_mark_time[device->rs_last_mark]; |
1035 | if (ns.conn == C_SYNC_TARGET) | 1048 | if (ns.conn == C_SYNC_TARGET) |
1036 | mod_timer(&mdev->resync_timer, jiffies); | 1049 | mod_timer(&device->resync_timer, jiffies); |
1037 | } | 1050 | } |
1038 | 1051 | ||
1039 | if ((os.conn == C_SYNC_TARGET || os.conn == C_SYNC_SOURCE) && | 1052 | if ((os.conn == C_SYNC_TARGET || os.conn == C_SYNC_SOURCE) && |
1040 | (ns.conn == C_PAUSED_SYNC_T || ns.conn == C_PAUSED_SYNC_S)) { | 1053 | (ns.conn == C_PAUSED_SYNC_T || ns.conn == C_PAUSED_SYNC_S)) { |
1041 | dev_info(DEV, "Resync suspended\n"); | 1054 | drbd_info(device, "Resync suspended\n"); |
1042 | mdev->rs_mark_time[mdev->rs_last_mark] = jiffies; | 1055 | device->rs_mark_time[device->rs_last_mark] = jiffies; |
1043 | } | 1056 | } |
1044 | 1057 | ||
1045 | if (os.conn == C_CONNECTED && | 1058 | if (os.conn == C_CONNECTED && |
@@ -1047,77 +1060,77 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
1047 | unsigned long now = jiffies; | 1060 | unsigned long now = jiffies; |
1048 | int i; | 1061 | int i; |
1049 | 1062 | ||
1050 | set_ov_position(mdev, ns.conn); | 1063 | set_ov_position(device, ns.conn); |
1051 | mdev->rs_start = now; | 1064 | device->rs_start = now; |
1052 | mdev->rs_last_events = 0; | 1065 | device->rs_last_events = 0; |
1053 | mdev->rs_last_sect_ev = 0; | 1066 | device->rs_last_sect_ev = 0; |
1054 | mdev->ov_last_oos_size = 0; | 1067 | device->ov_last_oos_size = 0; |
1055 | mdev->ov_last_oos_start = 0; | 1068 | device->ov_last_oos_start = 0; |
1056 | 1069 | ||
1057 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { | 1070 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
1058 | mdev->rs_mark_left[i] = mdev->ov_left; | 1071 | device->rs_mark_left[i] = device->ov_left; |
1059 | mdev->rs_mark_time[i] = now; | 1072 | device->rs_mark_time[i] = now; |
1060 | } | 1073 | } |
1061 | 1074 | ||
1062 | drbd_rs_controller_reset(mdev); | 1075 | drbd_rs_controller_reset(device); |
1063 | 1076 | ||
1064 | if (ns.conn == C_VERIFY_S) { | 1077 | if (ns.conn == C_VERIFY_S) { |
1065 | dev_info(DEV, "Starting Online Verify from sector %llu\n", | 1078 | drbd_info(device, "Starting Online Verify from sector %llu\n", |
1066 | (unsigned long long)mdev->ov_position); | 1079 | (unsigned long long)device->ov_position); |
1067 | mod_timer(&mdev->resync_timer, jiffies); | 1080 | mod_timer(&device->resync_timer, jiffies); |
1068 | } | 1081 | } |
1069 | } | 1082 | } |
1070 | 1083 | ||
1071 | if (get_ldev(mdev)) { | 1084 | if (get_ldev(device)) { |
1072 | u32 mdf = mdev->ldev->md.flags & ~(MDF_CONSISTENT|MDF_PRIMARY_IND| | 1085 | u32 mdf = device->ldev->md.flags & ~(MDF_CONSISTENT|MDF_PRIMARY_IND| |
1073 | MDF_CONNECTED_IND|MDF_WAS_UP_TO_DATE| | 1086 | MDF_CONNECTED_IND|MDF_WAS_UP_TO_DATE| |
1074 | MDF_PEER_OUT_DATED|MDF_CRASHED_PRIMARY); | 1087 | MDF_PEER_OUT_DATED|MDF_CRASHED_PRIMARY); |
1075 | 1088 | ||
1076 | mdf &= ~MDF_AL_CLEAN; | 1089 | mdf &= ~MDF_AL_CLEAN; |
1077 | if (test_bit(CRASHED_PRIMARY, &mdev->flags)) | 1090 | if (test_bit(CRASHED_PRIMARY, &device->flags)) |
1078 | mdf |= MDF_CRASHED_PRIMARY; | 1091 | mdf |= MDF_CRASHED_PRIMARY; |
1079 | if (mdev->state.role == R_PRIMARY || | 1092 | if (device->state.role == R_PRIMARY || |
1080 | (mdev->state.pdsk < D_INCONSISTENT && mdev->state.peer == R_PRIMARY)) | 1093 | (device->state.pdsk < D_INCONSISTENT && device->state.peer == R_PRIMARY)) |
1081 | mdf |= MDF_PRIMARY_IND; | 1094 | mdf |= MDF_PRIMARY_IND; |
1082 | if (mdev->state.conn > C_WF_REPORT_PARAMS) | 1095 | if (device->state.conn > C_WF_REPORT_PARAMS) |
1083 | mdf |= MDF_CONNECTED_IND; | 1096 | mdf |= MDF_CONNECTED_IND; |
1084 | if (mdev->state.disk > D_INCONSISTENT) | 1097 | if (device->state.disk > D_INCONSISTENT) |
1085 | mdf |= MDF_CONSISTENT; | 1098 | mdf |= MDF_CONSISTENT; |
1086 | if (mdev->state.disk > D_OUTDATED) | 1099 | if (device->state.disk > D_OUTDATED) |
1087 | mdf |= MDF_WAS_UP_TO_DATE; | 1100 | mdf |= MDF_WAS_UP_TO_DATE; |
1088 | if (mdev->state.pdsk <= D_OUTDATED && mdev->state.pdsk >= D_INCONSISTENT) | 1101 | if (device->state.pdsk <= D_OUTDATED && device->state.pdsk >= D_INCONSISTENT) |
1089 | mdf |= MDF_PEER_OUT_DATED; | 1102 | mdf |= MDF_PEER_OUT_DATED; |
1090 | if (mdf != mdev->ldev->md.flags) { | 1103 | if (mdf != device->ldev->md.flags) { |
1091 | mdev->ldev->md.flags = mdf; | 1104 | device->ldev->md.flags = mdf; |
1092 | drbd_md_mark_dirty(mdev); | 1105 | drbd_md_mark_dirty(device); |
1093 | } | 1106 | } |
1094 | if (os.disk < D_CONSISTENT && ns.disk >= D_CONSISTENT) | 1107 | if (os.disk < D_CONSISTENT && ns.disk >= D_CONSISTENT) |
1095 | drbd_set_ed_uuid(mdev, mdev->ldev->md.uuid[UI_CURRENT]); | 1108 | drbd_set_ed_uuid(device, device->ldev->md.uuid[UI_CURRENT]); |
1096 | put_ldev(mdev); | 1109 | put_ldev(device); |
1097 | } | 1110 | } |
1098 | 1111 | ||
1099 | /* Peer was forced D_UP_TO_DATE & R_PRIMARY, consider to resync */ | 1112 | /* Peer was forced D_UP_TO_DATE & R_PRIMARY, consider to resync */ |
1100 | if (os.disk == D_INCONSISTENT && os.pdsk == D_INCONSISTENT && | 1113 | if (os.disk == D_INCONSISTENT && os.pdsk == D_INCONSISTENT && |
1101 | os.peer == R_SECONDARY && ns.peer == R_PRIMARY) | 1114 | os.peer == R_SECONDARY && ns.peer == R_PRIMARY) |
1102 | set_bit(CONSIDER_RESYNC, &mdev->flags); | 1115 | set_bit(CONSIDER_RESYNC, &device->flags); |
1103 | 1116 | ||
1104 | /* Receiver should clean up itself */ | 1117 | /* Receiver should clean up itself */ |
1105 | if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING) | 1118 | if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING) |
1106 | drbd_thread_stop_nowait(&mdev->tconn->receiver); | 1119 | drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver); |
1107 | 1120 | ||
1108 | /* Now the receiver finished cleaning up itself, it should die */ | 1121 | /* Now the receiver finished cleaning up itself, it should die */ |
1109 | if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE) | 1122 | if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE) |
1110 | drbd_thread_stop_nowait(&mdev->tconn->receiver); | 1123 | drbd_thread_stop_nowait(&first_peer_device(device)->connection->receiver); |
1111 | 1124 | ||
1112 | /* Upon network failure, we need to restart the receiver. */ | 1125 | /* Upon network failure, we need to restart the receiver. */ |
1113 | if (os.conn > C_WF_CONNECTION && | 1126 | if (os.conn > C_WF_CONNECTION && |
1114 | ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT) | 1127 | ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT) |
1115 | drbd_thread_restart_nowait(&mdev->tconn->receiver); | 1128 | drbd_thread_restart_nowait(&first_peer_device(device)->connection->receiver); |
1116 | 1129 | ||
1117 | /* Resume AL writing if we get a connection */ | 1130 | /* Resume AL writing if we get a connection */ |
1118 | if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) { | 1131 | if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) { |
1119 | drbd_resume_al(mdev); | 1132 | drbd_resume_al(device); |
1120 | mdev->tconn->connect_cnt++; | 1133 | first_peer_device(device)->connection->connect_cnt++; |
1121 | } | 1134 | } |
1122 | 1135 | ||
1123 | /* remember last attach time so request_timer_fn() won't | 1136 | /* remember last attach time so request_timer_fn() won't |
@@ -1125,7 +1138,7 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
1125 | * previously frozen IO */ | 1138 | * previously frozen IO */ |
1126 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && | 1139 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && |
1127 | ns.disk > D_NEGOTIATING) | 1140 | ns.disk > D_NEGOTIATING) |
1128 | mdev->last_reattach_jif = jiffies; | 1141 | device->last_reattach_jif = jiffies; |
1129 | 1142 | ||
1130 | ascw = kmalloc(sizeof(*ascw), GFP_ATOMIC); | 1143 | ascw = kmalloc(sizeof(*ascw), GFP_ATOMIC); |
1131 | if (ascw) { | 1144 | if (ascw) { |
@@ -1133,11 +1146,12 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, | |||
1133 | ascw->ns = ns; | 1146 | ascw->ns = ns; |
1134 | ascw->flags = flags; | 1147 | ascw->flags = flags; |
1135 | ascw->w.cb = w_after_state_ch; | 1148 | ascw->w.cb = w_after_state_ch; |
1136 | ascw->w.mdev = mdev; | 1149 | ascw->device = device; |
1137 | ascw->done = done; | 1150 | ascw->done = done; |
1138 | drbd_queue_work(&mdev->tconn->sender_work, &ascw->w); | 1151 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
1152 | &ascw->w); | ||
1139 | } else { | 1153 | } else { |
1140 | dev_err(DEV, "Could not kmalloc an ascw\n"); | 1154 | drbd_err(device, "Could not kmalloc an ascw\n"); |
1141 | } | 1155 | } |
1142 | 1156 | ||
1143 | return rv; | 1157 | return rv; |
@@ -1147,66 +1161,65 @@ static int w_after_state_ch(struct drbd_work *w, int unused) | |||
1147 | { | 1161 | { |
1148 | struct after_state_chg_work *ascw = | 1162 | struct after_state_chg_work *ascw = |
1149 | container_of(w, struct after_state_chg_work, w); | 1163 | container_of(w, struct after_state_chg_work, w); |
1150 | struct drbd_conf *mdev = w->mdev; | 1164 | struct drbd_device *device = ascw->device; |
1151 | 1165 | ||
1152 | after_state_ch(mdev, ascw->os, ascw->ns, ascw->flags); | 1166 | after_state_ch(device, ascw->os, ascw->ns, ascw->flags); |
1153 | if (ascw->flags & CS_WAIT_COMPLETE) { | 1167 | if (ascw->flags & CS_WAIT_COMPLETE) |
1154 | D_ASSERT(ascw->done != NULL); | ||
1155 | complete(ascw->done); | 1168 | complete(ascw->done); |
1156 | } | ||
1157 | kfree(ascw); | 1169 | kfree(ascw); |
1158 | 1170 | ||
1159 | return 0; | 1171 | return 0; |
1160 | } | 1172 | } |
1161 | 1173 | ||
1162 | static void abw_start_sync(struct drbd_conf *mdev, int rv) | 1174 | static void abw_start_sync(struct drbd_device *device, int rv) |
1163 | { | 1175 | { |
1164 | if (rv) { | 1176 | if (rv) { |
1165 | dev_err(DEV, "Writing the bitmap failed not starting resync.\n"); | 1177 | drbd_err(device, "Writing the bitmap failed not starting resync.\n"); |
1166 | _drbd_request_state(mdev, NS(conn, C_CONNECTED), CS_VERBOSE); | 1178 | _drbd_request_state(device, NS(conn, C_CONNECTED), CS_VERBOSE); |
1167 | return; | 1179 | return; |
1168 | } | 1180 | } |
1169 | 1181 | ||
1170 | switch (mdev->state.conn) { | 1182 | switch (device->state.conn) { |
1171 | case C_STARTING_SYNC_T: | 1183 | case C_STARTING_SYNC_T: |
1172 | _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); | 1184 | _drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
1173 | break; | 1185 | break; |
1174 | case C_STARTING_SYNC_S: | 1186 | case C_STARTING_SYNC_S: |
1175 | drbd_start_resync(mdev, C_SYNC_SOURCE); | 1187 | drbd_start_resync(device, C_SYNC_SOURCE); |
1176 | break; | 1188 | break; |
1177 | } | 1189 | } |
1178 | } | 1190 | } |
1179 | 1191 | ||
1180 | int drbd_bitmap_io_from_worker(struct drbd_conf *mdev, | 1192 | int drbd_bitmap_io_from_worker(struct drbd_device *device, |
1181 | int (*io_fn)(struct drbd_conf *), | 1193 | int (*io_fn)(struct drbd_device *), |
1182 | char *why, enum bm_flag flags) | 1194 | char *why, enum bm_flag flags) |
1183 | { | 1195 | { |
1184 | int rv; | 1196 | int rv; |
1185 | 1197 | ||
1186 | D_ASSERT(current == mdev->tconn->worker.task); | 1198 | D_ASSERT(device, current == first_peer_device(device)->connection->worker.task); |
1187 | 1199 | ||
1188 | /* open coded non-blocking drbd_suspend_io(mdev); */ | 1200 | /* open coded non-blocking drbd_suspend_io(device); */ |
1189 | set_bit(SUSPEND_IO, &mdev->flags); | 1201 | set_bit(SUSPEND_IO, &device->flags); |
1190 | 1202 | ||
1191 | drbd_bm_lock(mdev, why, flags); | 1203 | drbd_bm_lock(device, why, flags); |
1192 | rv = io_fn(mdev); | 1204 | rv = io_fn(device); |
1193 | drbd_bm_unlock(mdev); | 1205 | drbd_bm_unlock(device); |
1194 | 1206 | ||
1195 | drbd_resume_io(mdev); | 1207 | drbd_resume_io(device); |
1196 | 1208 | ||
1197 | return rv; | 1209 | return rv; |
1198 | } | 1210 | } |
1199 | 1211 | ||
1200 | /** | 1212 | /** |
1201 | * after_state_ch() - Perform after state change actions that may sleep | 1213 | * after_state_ch() - Perform after state change actions that may sleep |
1202 | * @mdev: DRBD device. | 1214 | * @device: DRBD device. |
1203 | * @os: old state. | 1215 | * @os: old state. |
1204 | * @ns: new state. | 1216 | * @ns: new state. |
1205 | * @flags: Flags | 1217 | * @flags: Flags |
1206 | */ | 1218 | */ |
1207 | static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | 1219 | static void after_state_ch(struct drbd_device *device, union drbd_state os, |
1208 | union drbd_state ns, enum chg_state_flags flags) | 1220 | union drbd_state ns, enum chg_state_flags flags) |
1209 | { | 1221 | { |
1222 | struct drbd_resource *resource = device->resource; | ||
1210 | struct sib_info sib; | 1223 | struct sib_info sib; |
1211 | 1224 | ||
1212 | sib.sib_reason = SIB_STATE_CHANGE; | 1225 | sib.sib_reason = SIB_STATE_CHANGE; |
@@ -1214,63 +1227,63 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1214 | sib.ns = ns; | 1227 | sib.ns = ns; |
1215 | 1228 | ||
1216 | if (os.conn != C_CONNECTED && ns.conn == C_CONNECTED) { | 1229 | if (os.conn != C_CONNECTED && ns.conn == C_CONNECTED) { |
1217 | clear_bit(CRASHED_PRIMARY, &mdev->flags); | 1230 | clear_bit(CRASHED_PRIMARY, &device->flags); |
1218 | if (mdev->p_uuid) | 1231 | if (device->p_uuid) |
1219 | mdev->p_uuid[UI_FLAGS] &= ~((u64)2); | 1232 | device->p_uuid[UI_FLAGS] &= ~((u64)2); |
1220 | } | 1233 | } |
1221 | 1234 | ||
1222 | /* Inform userspace about the change... */ | 1235 | /* Inform userspace about the change... */ |
1223 | drbd_bcast_event(mdev, &sib); | 1236 | drbd_bcast_event(device, &sib); |
1224 | 1237 | ||
1225 | if (!(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE) && | 1238 | if (!(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE) && |
1226 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)) | 1239 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)) |
1227 | drbd_khelper(mdev, "pri-on-incon-degr"); | 1240 | drbd_khelper(device, "pri-on-incon-degr"); |
1228 | 1241 | ||
1229 | /* Here we have the actions that are performed after a | 1242 | /* Here we have the actions that are performed after a |
1230 | state change. This function might sleep */ | 1243 | state change. This function might sleep */ |
1231 | 1244 | ||
1232 | if (ns.susp_nod) { | 1245 | if (ns.susp_nod) { |
1233 | struct drbd_tconn *tconn = mdev->tconn; | 1246 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1234 | enum drbd_req_event what = NOTHING; | 1247 | enum drbd_req_event what = NOTHING; |
1235 | 1248 | ||
1236 | spin_lock_irq(&tconn->req_lock); | 1249 | spin_lock_irq(&device->resource->req_lock); |
1237 | if (os.conn < C_CONNECTED && conn_lowest_conn(tconn) >= C_CONNECTED) | 1250 | if (os.conn < C_CONNECTED && conn_lowest_conn(connection) >= C_CONNECTED) |
1238 | what = RESEND; | 1251 | what = RESEND; |
1239 | 1252 | ||
1240 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && | 1253 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && |
1241 | conn_lowest_disk(tconn) > D_NEGOTIATING) | 1254 | conn_lowest_disk(connection) > D_NEGOTIATING) |
1242 | what = RESTART_FROZEN_DISK_IO; | 1255 | what = RESTART_FROZEN_DISK_IO; |
1243 | 1256 | ||
1244 | if (tconn->susp_nod && what != NOTHING) { | 1257 | if (resource->susp_nod && what != NOTHING) { |
1245 | _tl_restart(tconn, what); | 1258 | _tl_restart(connection, what); |
1246 | _conn_request_state(tconn, | 1259 | _conn_request_state(connection, |
1247 | (union drbd_state) { { .susp_nod = 1 } }, | 1260 | (union drbd_state) { { .susp_nod = 1 } }, |
1248 | (union drbd_state) { { .susp_nod = 0 } }, | 1261 | (union drbd_state) { { .susp_nod = 0 } }, |
1249 | CS_VERBOSE); | 1262 | CS_VERBOSE); |
1250 | } | 1263 | } |
1251 | spin_unlock_irq(&tconn->req_lock); | 1264 | spin_unlock_irq(&device->resource->req_lock); |
1252 | } | 1265 | } |
1253 | 1266 | ||
1254 | if (ns.susp_fen) { | 1267 | if (ns.susp_fen) { |
1255 | struct drbd_tconn *tconn = mdev->tconn; | 1268 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1256 | 1269 | ||
1257 | spin_lock_irq(&tconn->req_lock); | 1270 | spin_lock_irq(&device->resource->req_lock); |
1258 | if (tconn->susp_fen && conn_lowest_conn(tconn) >= C_CONNECTED) { | 1271 | if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) { |
1259 | /* case2: The connection was established again: */ | 1272 | /* case2: The connection was established again: */ |
1260 | struct drbd_conf *odev; | 1273 | struct drbd_peer_device *peer_device; |
1261 | int vnr; | 1274 | int vnr; |
1262 | 1275 | ||
1263 | rcu_read_lock(); | 1276 | rcu_read_lock(); |
1264 | idr_for_each_entry(&tconn->volumes, odev, vnr) | 1277 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
1265 | clear_bit(NEW_CUR_UUID, &odev->flags); | 1278 | clear_bit(NEW_CUR_UUID, &peer_device->device->flags); |
1266 | rcu_read_unlock(); | 1279 | rcu_read_unlock(); |
1267 | _tl_restart(tconn, RESEND); | 1280 | _tl_restart(connection, RESEND); |
1268 | _conn_request_state(tconn, | 1281 | _conn_request_state(connection, |
1269 | (union drbd_state) { { .susp_fen = 1 } }, | 1282 | (union drbd_state) { { .susp_fen = 1 } }, |
1270 | (union drbd_state) { { .susp_fen = 0 } }, | 1283 | (union drbd_state) { { .susp_fen = 0 } }, |
1271 | CS_VERBOSE); | 1284 | CS_VERBOSE); |
1272 | } | 1285 | } |
1273 | spin_unlock_irq(&tconn->req_lock); | 1286 | spin_unlock_irq(&device->resource->req_lock); |
1274 | } | 1287 | } |
1275 | 1288 | ||
1276 | /* Became sync source. With protocol >= 96, we still need to send out | 1289 | /* Became sync source. With protocol >= 96, we still need to send out |
@@ -1279,9 +1292,9 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1279 | * which is unexpected. */ | 1292 | * which is unexpected. */ |
1280 | if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) && | 1293 | if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) && |
1281 | (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) && | 1294 | (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) && |
1282 | mdev->tconn->agreed_pro_version >= 96 && get_ldev(mdev)) { | 1295 | first_peer_device(device)->connection->agreed_pro_version >= 96 && get_ldev(device)) { |
1283 | drbd_gen_and_send_sync_uuid(mdev); | 1296 | drbd_gen_and_send_sync_uuid(first_peer_device(device)); |
1284 | put_ldev(mdev); | 1297 | put_ldev(device); |
1285 | } | 1298 | } |
1286 | 1299 | ||
1287 | /* Do not change the order of the if above and the two below... */ | 1300 | /* Do not change the order of the if above and the two below... */ |
@@ -1289,20 +1302,20 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1289 | ns.pdsk > D_DISKLESS && ns.pdsk != D_UNKNOWN) { /* attach on the peer */ | 1302 | ns.pdsk > D_DISKLESS && ns.pdsk != D_UNKNOWN) { /* attach on the peer */ |
1290 | /* we probably will start a resync soon. | 1303 | /* we probably will start a resync soon. |
1291 | * make sure those things are properly reset. */ | 1304 | * make sure those things are properly reset. */ |
1292 | mdev->rs_total = 0; | 1305 | device->rs_total = 0; |
1293 | mdev->rs_failed = 0; | 1306 | device->rs_failed = 0; |
1294 | atomic_set(&mdev->rs_pending_cnt, 0); | 1307 | atomic_set(&device->rs_pending_cnt, 0); |
1295 | drbd_rs_cancel_all(mdev); | 1308 | drbd_rs_cancel_all(device); |
1296 | 1309 | ||
1297 | drbd_send_uuids(mdev); | 1310 | drbd_send_uuids(first_peer_device(device)); |
1298 | drbd_send_state(mdev, ns); | 1311 | drbd_send_state(first_peer_device(device), ns); |
1299 | } | 1312 | } |
1300 | /* No point in queuing send_bitmap if we don't have a connection | 1313 | /* No point in queuing send_bitmap if we don't have a connection |
1301 | * anymore, so check also the _current_ state, not only the new state | 1314 | * anymore, so check also the _current_ state, not only the new state |
1302 | * at the time this work was queued. */ | 1315 | * at the time this work was queued. */ |
1303 | if (os.conn != C_WF_BITMAP_S && ns.conn == C_WF_BITMAP_S && | 1316 | if (os.conn != C_WF_BITMAP_S && ns.conn == C_WF_BITMAP_S && |
1304 | mdev->state.conn == C_WF_BITMAP_S) | 1317 | device->state.conn == C_WF_BITMAP_S) |
1305 | drbd_queue_bitmap_io(mdev, &drbd_send_bitmap, NULL, | 1318 | drbd_queue_bitmap_io(device, &drbd_send_bitmap, NULL, |
1306 | "send_bitmap (WFBitMapS)", | 1319 | "send_bitmap (WFBitMapS)", |
1307 | BM_LOCKED_TEST_ALLOWED); | 1320 | BM_LOCKED_TEST_ALLOWED); |
1308 | 1321 | ||
@@ -1313,80 +1326,80 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1313 | && (ns.pdsk < D_INCONSISTENT || | 1326 | && (ns.pdsk < D_INCONSISTENT || |
1314 | ns.pdsk == D_UNKNOWN || | 1327 | ns.pdsk == D_UNKNOWN || |
1315 | ns.pdsk == D_OUTDATED)) { | 1328 | ns.pdsk == D_OUTDATED)) { |
1316 | if (get_ldev(mdev)) { | 1329 | if (get_ldev(device)) { |
1317 | if ((ns.role == R_PRIMARY || ns.peer == R_PRIMARY) && | 1330 | if ((ns.role == R_PRIMARY || ns.peer == R_PRIMARY) && |
1318 | mdev->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { | 1331 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { |
1319 | if (drbd_suspended(mdev)) { | 1332 | if (drbd_suspended(device)) { |
1320 | set_bit(NEW_CUR_UUID, &mdev->flags); | 1333 | set_bit(NEW_CUR_UUID, &device->flags); |
1321 | } else { | 1334 | } else { |
1322 | drbd_uuid_new_current(mdev); | 1335 | drbd_uuid_new_current(device); |
1323 | drbd_send_uuids(mdev); | 1336 | drbd_send_uuids(first_peer_device(device)); |
1324 | } | 1337 | } |
1325 | } | 1338 | } |
1326 | put_ldev(mdev); | 1339 | put_ldev(device); |
1327 | } | 1340 | } |
1328 | } | 1341 | } |
1329 | 1342 | ||
1330 | if (ns.pdsk < D_INCONSISTENT && get_ldev(mdev)) { | 1343 | if (ns.pdsk < D_INCONSISTENT && get_ldev(device)) { |
1331 | if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY && | 1344 | if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY && |
1332 | mdev->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { | 1345 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { |
1333 | drbd_uuid_new_current(mdev); | 1346 | drbd_uuid_new_current(device); |
1334 | drbd_send_uuids(mdev); | 1347 | drbd_send_uuids(first_peer_device(device)); |
1335 | } | 1348 | } |
1336 | /* D_DISKLESS Peer becomes secondary */ | 1349 | /* D_DISKLESS Peer becomes secondary */ |
1337 | if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY) | 1350 | if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY) |
1338 | /* We may still be Primary ourselves. | 1351 | /* We may still be Primary ourselves. |
1339 | * No harm done if the bitmap still changes, | 1352 | * No harm done if the bitmap still changes, |
1340 | * redirtied pages will follow later. */ | 1353 | * redirtied pages will follow later. */ |
1341 | drbd_bitmap_io_from_worker(mdev, &drbd_bm_write, | 1354 | drbd_bitmap_io_from_worker(device, &drbd_bm_write, |
1342 | "demote diskless peer", BM_LOCKED_SET_ALLOWED); | 1355 | "demote diskless peer", BM_LOCKED_SET_ALLOWED); |
1343 | put_ldev(mdev); | 1356 | put_ldev(device); |
1344 | } | 1357 | } |
1345 | 1358 | ||
1346 | /* Write out all changed bits on demote. | 1359 | /* Write out all changed bits on demote. |
1347 | * Though, no need to da that just yet | 1360 | * Though, no need to da that just yet |
1348 | * if there is a resync going on still */ | 1361 | * if there is a resync going on still */ |
1349 | if (os.role == R_PRIMARY && ns.role == R_SECONDARY && | 1362 | if (os.role == R_PRIMARY && ns.role == R_SECONDARY && |
1350 | mdev->state.conn <= C_CONNECTED && get_ldev(mdev)) { | 1363 | device->state.conn <= C_CONNECTED && get_ldev(device)) { |
1351 | /* No changes to the bitmap expected this time, so assert that, | 1364 | /* No changes to the bitmap expected this time, so assert that, |
1352 | * even though no harm was done if it did change. */ | 1365 | * even though no harm was done if it did change. */ |
1353 | drbd_bitmap_io_from_worker(mdev, &drbd_bm_write, | 1366 | drbd_bitmap_io_from_worker(device, &drbd_bm_write, |
1354 | "demote", BM_LOCKED_TEST_ALLOWED); | 1367 | "demote", BM_LOCKED_TEST_ALLOWED); |
1355 | put_ldev(mdev); | 1368 | put_ldev(device); |
1356 | } | 1369 | } |
1357 | 1370 | ||
1358 | /* Last part of the attaching process ... */ | 1371 | /* Last part of the attaching process ... */ |
1359 | if (ns.conn >= C_CONNECTED && | 1372 | if (ns.conn >= C_CONNECTED && |
1360 | os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) { | 1373 | os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) { |
1361 | drbd_send_sizes(mdev, 0, 0); /* to start sync... */ | 1374 | drbd_send_sizes(first_peer_device(device), 0, 0); /* to start sync... */ |
1362 | drbd_send_uuids(mdev); | 1375 | drbd_send_uuids(first_peer_device(device)); |
1363 | drbd_send_state(mdev, ns); | 1376 | drbd_send_state(first_peer_device(device), ns); |
1364 | } | 1377 | } |
1365 | 1378 | ||
1366 | /* We want to pause/continue resync, tell peer. */ | 1379 | /* We want to pause/continue resync, tell peer. */ |
1367 | if (ns.conn >= C_CONNECTED && | 1380 | if (ns.conn >= C_CONNECTED && |
1368 | ((os.aftr_isp != ns.aftr_isp) || | 1381 | ((os.aftr_isp != ns.aftr_isp) || |
1369 | (os.user_isp != ns.user_isp))) | 1382 | (os.user_isp != ns.user_isp))) |
1370 | drbd_send_state(mdev, ns); | 1383 | drbd_send_state(first_peer_device(device), ns); |
1371 | 1384 | ||
1372 | /* In case one of the isp bits got set, suspend other devices. */ | 1385 | /* In case one of the isp bits got set, suspend other devices. */ |
1373 | if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) && | 1386 | if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) && |
1374 | (ns.aftr_isp || ns.peer_isp || ns.user_isp)) | 1387 | (ns.aftr_isp || ns.peer_isp || ns.user_isp)) |
1375 | suspend_other_sg(mdev); | 1388 | suspend_other_sg(device); |
1376 | 1389 | ||
1377 | /* Make sure the peer gets informed about eventual state | 1390 | /* Make sure the peer gets informed about eventual state |
1378 | changes (ISP bits) while we were in WFReportParams. */ | 1391 | changes (ISP bits) while we were in WFReportParams. */ |
1379 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED) | 1392 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED) |
1380 | drbd_send_state(mdev, ns); | 1393 | drbd_send_state(first_peer_device(device), ns); |
1381 | 1394 | ||
1382 | if (os.conn != C_AHEAD && ns.conn == C_AHEAD) | 1395 | if (os.conn != C_AHEAD && ns.conn == C_AHEAD) |
1383 | drbd_send_state(mdev, ns); | 1396 | drbd_send_state(first_peer_device(device), ns); |
1384 | 1397 | ||
1385 | /* We are in the progress to start a full sync... */ | 1398 | /* We are in the progress to start a full sync... */ |
1386 | if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || | 1399 | if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || |
1387 | (os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S)) | 1400 | (os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S)) |
1388 | /* no other bitmap changes expected during this phase */ | 1401 | /* no other bitmap changes expected during this phase */ |
1389 | drbd_queue_bitmap_io(mdev, | 1402 | drbd_queue_bitmap_io(device, |
1390 | &drbd_bmio_set_n_write, &abw_start_sync, | 1403 | &drbd_bmio_set_n_write, &abw_start_sync, |
1391 | "set_n_write from StartingSync", BM_LOCKED_TEST_ALLOWED); | 1404 | "set_n_write from StartingSync", BM_LOCKED_TEST_ALLOWED); |
1392 | 1405 | ||
@@ -1399,15 +1412,15 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1399 | * our cleanup here with the transition to D_DISKLESS. | 1412 | * our cleanup here with the transition to D_DISKLESS. |
1400 | * But is is still not save to dreference ldev here, since | 1413 | * But is is still not save to dreference ldev here, since |
1401 | * we might come from an failed Attach before ldev was set. */ | 1414 | * we might come from an failed Attach before ldev was set. */ |
1402 | if (mdev->ldev) { | 1415 | if (device->ldev) { |
1403 | rcu_read_lock(); | 1416 | rcu_read_lock(); |
1404 | eh = rcu_dereference(mdev->ldev->disk_conf)->on_io_error; | 1417 | eh = rcu_dereference(device->ldev->disk_conf)->on_io_error; |
1405 | rcu_read_unlock(); | 1418 | rcu_read_unlock(); |
1406 | 1419 | ||
1407 | was_io_error = test_and_clear_bit(WAS_IO_ERROR, &mdev->flags); | 1420 | was_io_error = test_and_clear_bit(WAS_IO_ERROR, &device->flags); |
1408 | 1421 | ||
1409 | if (was_io_error && eh == EP_CALL_HELPER) | 1422 | if (was_io_error && eh == EP_CALL_HELPER) |
1410 | drbd_khelper(mdev, "local-io-error"); | 1423 | drbd_khelper(device, "local-io-error"); |
1411 | 1424 | ||
1412 | /* Immediately allow completion of all application IO, | 1425 | /* Immediately allow completion of all application IO, |
1413 | * that waits for completion from the local disk, | 1426 | * that waits for completion from the local disk, |
@@ -1422,76 +1435,76 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1422 | * So aborting local requests may cause crashes, | 1435 | * So aborting local requests may cause crashes, |
1423 | * or even worse, silent data corruption. | 1436 | * or even worse, silent data corruption. |
1424 | */ | 1437 | */ |
1425 | if (test_and_clear_bit(FORCE_DETACH, &mdev->flags)) | 1438 | if (test_and_clear_bit(FORCE_DETACH, &device->flags)) |
1426 | tl_abort_disk_io(mdev); | 1439 | tl_abort_disk_io(device); |
1427 | 1440 | ||
1428 | /* current state still has to be D_FAILED, | 1441 | /* current state still has to be D_FAILED, |
1429 | * there is only one way out: to D_DISKLESS, | 1442 | * there is only one way out: to D_DISKLESS, |
1430 | * and that may only happen after our put_ldev below. */ | 1443 | * and that may only happen after our put_ldev below. */ |
1431 | if (mdev->state.disk != D_FAILED) | 1444 | if (device->state.disk != D_FAILED) |
1432 | dev_err(DEV, | 1445 | drbd_err(device, |
1433 | "ASSERT FAILED: disk is %s during detach\n", | 1446 | "ASSERT FAILED: disk is %s during detach\n", |
1434 | drbd_disk_str(mdev->state.disk)); | 1447 | drbd_disk_str(device->state.disk)); |
1435 | 1448 | ||
1436 | if (ns.conn >= C_CONNECTED) | 1449 | if (ns.conn >= C_CONNECTED) |
1437 | drbd_send_state(mdev, ns); | 1450 | drbd_send_state(first_peer_device(device), ns); |
1438 | 1451 | ||
1439 | drbd_rs_cancel_all(mdev); | 1452 | drbd_rs_cancel_all(device); |
1440 | 1453 | ||
1441 | /* In case we want to get something to stable storage still, | 1454 | /* In case we want to get something to stable storage still, |
1442 | * this may be the last chance. | 1455 | * this may be the last chance. |
1443 | * Following put_ldev may transition to D_DISKLESS. */ | 1456 | * Following put_ldev may transition to D_DISKLESS. */ |
1444 | drbd_md_sync(mdev); | 1457 | drbd_md_sync(device); |
1445 | } | 1458 | } |
1446 | put_ldev(mdev); | 1459 | put_ldev(device); |
1447 | } | 1460 | } |
1448 | 1461 | ||
1449 | /* second half of local IO error, failure to attach, | 1462 | /* second half of local IO error, failure to attach, |
1450 | * or administrative detach, | 1463 | * or administrative detach, |
1451 | * after local_cnt references have reached zero again */ | 1464 | * after local_cnt references have reached zero again */ |
1452 | if (os.disk != D_DISKLESS && ns.disk == D_DISKLESS) { | 1465 | if (os.disk != D_DISKLESS && ns.disk == D_DISKLESS) { |
1453 | /* We must still be diskless, | 1466 | /* We must still be diskless, |
1454 | * re-attach has to be serialized with this! */ | 1467 | * re-attach has to be serialized with this! */ |
1455 | if (mdev->state.disk != D_DISKLESS) | 1468 | if (device->state.disk != D_DISKLESS) |
1456 | dev_err(DEV, | 1469 | drbd_err(device, |
1457 | "ASSERT FAILED: disk is %s while going diskless\n", | 1470 | "ASSERT FAILED: disk is %s while going diskless\n", |
1458 | drbd_disk_str(mdev->state.disk)); | 1471 | drbd_disk_str(device->state.disk)); |
1459 | 1472 | ||
1460 | if (ns.conn >= C_CONNECTED) | 1473 | if (ns.conn >= C_CONNECTED) |
1461 | drbd_send_state(mdev, ns); | 1474 | drbd_send_state(first_peer_device(device), ns); |
1462 | /* corresponding get_ldev in __drbd_set_state | 1475 | /* corresponding get_ldev in __drbd_set_state |
1463 | * this may finally trigger drbd_ldev_destroy. */ | 1476 | * this may finally trigger drbd_ldev_destroy. */ |
1464 | put_ldev(mdev); | 1477 | put_ldev(device); |
1465 | } | 1478 | } |
1466 | 1479 | ||
1467 | /* Notify peer that I had a local IO error, and did not detached.. */ | 1480 | /* Notify peer that I had a local IO error, and did not detached.. */ |
1468 | if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED) | 1481 | if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED) |
1469 | drbd_send_state(mdev, ns); | 1482 | drbd_send_state(first_peer_device(device), ns); |
1470 | 1483 | ||
1471 | /* Disks got bigger while they were detached */ | 1484 | /* Disks got bigger while they were detached */ |
1472 | if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING && | 1485 | if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING && |
1473 | test_and_clear_bit(RESYNC_AFTER_NEG, &mdev->flags)) { | 1486 | test_and_clear_bit(RESYNC_AFTER_NEG, &device->flags)) { |
1474 | if (ns.conn == C_CONNECTED) | 1487 | if (ns.conn == C_CONNECTED) |
1475 | resync_after_online_grow(mdev); | 1488 | resync_after_online_grow(device); |
1476 | } | 1489 | } |
1477 | 1490 | ||
1478 | /* A resync finished or aborted, wake paused devices... */ | 1491 | /* A resync finished or aborted, wake paused devices... */ |
1479 | if ((os.conn > C_CONNECTED && ns.conn <= C_CONNECTED) || | 1492 | if ((os.conn > C_CONNECTED && ns.conn <= C_CONNECTED) || |
1480 | (os.peer_isp && !ns.peer_isp) || | 1493 | (os.peer_isp && !ns.peer_isp) || |
1481 | (os.user_isp && !ns.user_isp)) | 1494 | (os.user_isp && !ns.user_isp)) |
1482 | resume_next_sg(mdev); | 1495 | resume_next_sg(device); |
1483 | 1496 | ||
1484 | /* sync target done with resync. Explicitly notify peer, even though | 1497 | /* sync target done with resync. Explicitly notify peer, even though |
1485 | * it should (at least for non-empty resyncs) already know itself. */ | 1498 | * it should (at least for non-empty resyncs) already know itself. */ |
1486 | if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED) | 1499 | if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED) |
1487 | drbd_send_state(mdev, ns); | 1500 | drbd_send_state(first_peer_device(device), ns); |
1488 | 1501 | ||
1489 | /* Verify finished, or reached stop sector. Peer did not know about | 1502 | /* Verify finished, or reached stop sector. Peer did not know about |
1490 | * the stop sector, and we may even have changed the stop sector during | 1503 | * the stop sector, and we may even have changed the stop sector during |
1491 | * verify to interrupt/stop early. Send the new state. */ | 1504 | * verify to interrupt/stop early. Send the new state. */ |
1492 | if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED | 1505 | if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED |
1493 | && verify_can_do_stop_sector(mdev)) | 1506 | && verify_can_do_stop_sector(device)) |
1494 | drbd_send_state(mdev, ns); | 1507 | drbd_send_state(first_peer_device(device), ns); |
1495 | 1508 | ||
1496 | /* This triggers bitmap writeout of potentially still unwritten pages | 1509 | /* This triggers bitmap writeout of potentially still unwritten pages |
1497 | * if the resync finished cleanly, or aborted because of peer disk | 1510 | * if the resync finished cleanly, or aborted because of peer disk |
@@ -1500,56 +1513,57 @@ static void after_state_ch(struct drbd_conf *mdev, union drbd_state os, | |||
1500 | * any bitmap writeout anymore. | 1513 | * any bitmap writeout anymore. |
1501 | * No harm done if some bits change during this phase. | 1514 | * No harm done if some bits change during this phase. |
1502 | */ | 1515 | */ |
1503 | if (os.conn > C_CONNECTED && ns.conn <= C_CONNECTED && get_ldev(mdev)) { | 1516 | if (os.conn > C_CONNECTED && ns.conn <= C_CONNECTED && get_ldev(device)) { |
1504 | drbd_queue_bitmap_io(mdev, &drbd_bm_write_copy_pages, NULL, | 1517 | drbd_queue_bitmap_io(device, &drbd_bm_write_copy_pages, NULL, |
1505 | "write from resync_finished", BM_LOCKED_CHANGE_ALLOWED); | 1518 | "write from resync_finished", BM_LOCKED_CHANGE_ALLOWED); |
1506 | put_ldev(mdev); | 1519 | put_ldev(device); |
1507 | } | 1520 | } |
1508 | 1521 | ||
1509 | if (ns.disk == D_DISKLESS && | 1522 | if (ns.disk == D_DISKLESS && |
1510 | ns.conn == C_STANDALONE && | 1523 | ns.conn == C_STANDALONE && |
1511 | ns.role == R_SECONDARY) { | 1524 | ns.role == R_SECONDARY) { |
1512 | if (os.aftr_isp != ns.aftr_isp) | 1525 | if (os.aftr_isp != ns.aftr_isp) |
1513 | resume_next_sg(mdev); | 1526 | resume_next_sg(device); |
1514 | } | 1527 | } |
1515 | 1528 | ||
1516 | drbd_md_sync(mdev); | 1529 | drbd_md_sync(device); |
1517 | } | 1530 | } |
1518 | 1531 | ||
1519 | struct after_conn_state_chg_work { | 1532 | struct after_conn_state_chg_work { |
1520 | struct drbd_work w; | 1533 | struct drbd_work w; |
1521 | enum drbd_conns oc; | 1534 | enum drbd_conns oc; |
1522 | union drbd_state ns_min; | 1535 | union drbd_state ns_min; |
1523 | union drbd_state ns_max; /* new, max state, over all mdevs */ | 1536 | union drbd_state ns_max; /* new, max state, over all devices */ |
1524 | enum chg_state_flags flags; | 1537 | enum chg_state_flags flags; |
1538 | struct drbd_connection *connection; | ||
1525 | }; | 1539 | }; |
1526 | 1540 | ||
1527 | static int w_after_conn_state_ch(struct drbd_work *w, int unused) | 1541 | static int w_after_conn_state_ch(struct drbd_work *w, int unused) |
1528 | { | 1542 | { |
1529 | struct after_conn_state_chg_work *acscw = | 1543 | struct after_conn_state_chg_work *acscw = |
1530 | container_of(w, struct after_conn_state_chg_work, w); | 1544 | container_of(w, struct after_conn_state_chg_work, w); |
1531 | struct drbd_tconn *tconn = w->tconn; | 1545 | struct drbd_connection *connection = acscw->connection; |
1532 | enum drbd_conns oc = acscw->oc; | 1546 | enum drbd_conns oc = acscw->oc; |
1533 | union drbd_state ns_max = acscw->ns_max; | 1547 | union drbd_state ns_max = acscw->ns_max; |
1534 | struct drbd_conf *mdev; | 1548 | struct drbd_peer_device *peer_device; |
1535 | int vnr; | 1549 | int vnr; |
1536 | 1550 | ||
1537 | kfree(acscw); | 1551 | kfree(acscw); |
1538 | 1552 | ||
1539 | /* Upon network configuration, we need to start the receiver */ | 1553 | /* Upon network configuration, we need to start the receiver */ |
1540 | if (oc == C_STANDALONE && ns_max.conn == C_UNCONNECTED) | 1554 | if (oc == C_STANDALONE && ns_max.conn == C_UNCONNECTED) |
1541 | drbd_thread_start(&tconn->receiver); | 1555 | drbd_thread_start(&connection->receiver); |
1542 | 1556 | ||
1543 | if (oc == C_DISCONNECTING && ns_max.conn == C_STANDALONE) { | 1557 | if (oc == C_DISCONNECTING && ns_max.conn == C_STANDALONE) { |
1544 | struct net_conf *old_conf; | 1558 | struct net_conf *old_conf; |
1545 | 1559 | ||
1546 | mutex_lock(&tconn->conf_update); | 1560 | mutex_lock(&connection->resource->conf_update); |
1547 | old_conf = tconn->net_conf; | 1561 | old_conf = connection->net_conf; |
1548 | tconn->my_addr_len = 0; | 1562 | connection->my_addr_len = 0; |
1549 | tconn->peer_addr_len = 0; | 1563 | connection->peer_addr_len = 0; |
1550 | rcu_assign_pointer(tconn->net_conf, NULL); | 1564 | rcu_assign_pointer(connection->net_conf, NULL); |
1551 | conn_free_crypto(tconn); | 1565 | conn_free_crypto(connection); |
1552 | mutex_unlock(&tconn->conf_update); | 1566 | mutex_unlock(&connection->resource->conf_update); |
1553 | 1567 | ||
1554 | synchronize_rcu(); | 1568 | synchronize_rcu(); |
1555 | kfree(old_conf); | 1569 | kfree(old_conf); |
@@ -1559,45 +1573,47 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused) | |||
1559 | /* case1: The outdate peer handler is successful: */ | 1573 | /* case1: The outdate peer handler is successful: */ |
1560 | if (ns_max.pdsk <= D_OUTDATED) { | 1574 | if (ns_max.pdsk <= D_OUTDATED) { |
1561 | rcu_read_lock(); | 1575 | rcu_read_lock(); |
1562 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1576 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1563 | if (test_bit(NEW_CUR_UUID, &mdev->flags)) { | 1577 | struct drbd_device *device = peer_device->device; |
1564 | drbd_uuid_new_current(mdev); | 1578 | if (test_bit(NEW_CUR_UUID, &device->flags)) { |
1565 | clear_bit(NEW_CUR_UUID, &mdev->flags); | 1579 | drbd_uuid_new_current(device); |
1580 | clear_bit(NEW_CUR_UUID, &device->flags); | ||
1566 | } | 1581 | } |
1567 | } | 1582 | } |
1568 | rcu_read_unlock(); | 1583 | rcu_read_unlock(); |
1569 | spin_lock_irq(&tconn->req_lock); | 1584 | spin_lock_irq(&connection->resource->req_lock); |
1570 | _tl_restart(tconn, CONNECTION_LOST_WHILE_PENDING); | 1585 | _tl_restart(connection, CONNECTION_LOST_WHILE_PENDING); |
1571 | _conn_request_state(tconn, | 1586 | _conn_request_state(connection, |
1572 | (union drbd_state) { { .susp_fen = 1 } }, | 1587 | (union drbd_state) { { .susp_fen = 1 } }, |
1573 | (union drbd_state) { { .susp_fen = 0 } }, | 1588 | (union drbd_state) { { .susp_fen = 0 } }, |
1574 | CS_VERBOSE); | 1589 | CS_VERBOSE); |
1575 | spin_unlock_irq(&tconn->req_lock); | 1590 | spin_unlock_irq(&connection->resource->req_lock); |
1576 | } | 1591 | } |
1577 | } | 1592 | } |
1578 | kref_put(&tconn->kref, &conn_destroy); | 1593 | kref_put(&connection->kref, drbd_destroy_connection); |
1579 | 1594 | ||
1580 | conn_md_sync(tconn); | 1595 | conn_md_sync(connection); |
1581 | 1596 | ||
1582 | return 0; | 1597 | return 0; |
1583 | } | 1598 | } |
1584 | 1599 | ||
1585 | void conn_old_common_state(struct drbd_tconn *tconn, union drbd_state *pcs, enum chg_state_flags *pf) | 1600 | void conn_old_common_state(struct drbd_connection *connection, union drbd_state *pcs, enum chg_state_flags *pf) |
1586 | { | 1601 | { |
1587 | enum chg_state_flags flags = ~0; | 1602 | enum chg_state_flags flags = ~0; |
1588 | struct drbd_conf *mdev; | 1603 | struct drbd_peer_device *peer_device; |
1589 | int vnr, first_vol = 1; | 1604 | int vnr, first_vol = 1; |
1590 | union drbd_dev_state os, cs = { | 1605 | union drbd_dev_state os, cs = { |
1591 | { .role = R_SECONDARY, | 1606 | { .role = R_SECONDARY, |
1592 | .peer = R_UNKNOWN, | 1607 | .peer = R_UNKNOWN, |
1593 | .conn = tconn->cstate, | 1608 | .conn = connection->cstate, |
1594 | .disk = D_DISKLESS, | 1609 | .disk = D_DISKLESS, |
1595 | .pdsk = D_UNKNOWN, | 1610 | .pdsk = D_UNKNOWN, |
1596 | } }; | 1611 | } }; |
1597 | 1612 | ||
1598 | rcu_read_lock(); | 1613 | rcu_read_lock(); |
1599 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1614 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1600 | os = mdev->state; | 1615 | struct drbd_device *device = peer_device->device; |
1616 | os = device->state; | ||
1601 | 1617 | ||
1602 | if (first_vol) { | 1618 | if (first_vol) { |
1603 | cs = os; | 1619 | cs = os; |
@@ -1628,18 +1644,19 @@ void conn_old_common_state(struct drbd_tconn *tconn, union drbd_state *pcs, enum | |||
1628 | } | 1644 | } |
1629 | 1645 | ||
1630 | static enum drbd_state_rv | 1646 | static enum drbd_state_rv |
1631 | conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 1647 | conn_is_valid_transition(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
1632 | enum chg_state_flags flags) | 1648 | enum chg_state_flags flags) |
1633 | { | 1649 | { |
1634 | enum drbd_state_rv rv = SS_SUCCESS; | 1650 | enum drbd_state_rv rv = SS_SUCCESS; |
1635 | union drbd_state ns, os; | 1651 | union drbd_state ns, os; |
1636 | struct drbd_conf *mdev; | 1652 | struct drbd_peer_device *peer_device; |
1637 | int vnr; | 1653 | int vnr; |
1638 | 1654 | ||
1639 | rcu_read_lock(); | 1655 | rcu_read_lock(); |
1640 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1656 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1641 | os = drbd_read_state(mdev); | 1657 | struct drbd_device *device = peer_device->device; |
1642 | ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL); | 1658 | os = drbd_read_state(device); |
1659 | ns = sanitize_state(device, apply_mask_val(os, mask, val), NULL); | ||
1643 | 1660 | ||
1644 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) | 1661 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) |
1645 | ns.disk = os.disk; | 1662 | ns.disk = os.disk; |
@@ -1648,30 +1665,29 @@ conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union | |||
1648 | continue; | 1665 | continue; |
1649 | 1666 | ||
1650 | rv = is_valid_transition(os, ns); | 1667 | rv = is_valid_transition(os, ns); |
1651 | if (rv < SS_SUCCESS) | ||
1652 | break; | ||
1653 | 1668 | ||
1654 | if (!(flags & CS_HARD)) { | 1669 | if (rv >= SS_SUCCESS && !(flags & CS_HARD)) { |
1655 | rv = is_valid_state(mdev, ns); | 1670 | rv = is_valid_state(device, ns); |
1656 | if (rv < SS_SUCCESS) { | 1671 | if (rv < SS_SUCCESS) { |
1657 | if (is_valid_state(mdev, os) == rv) | 1672 | if (is_valid_state(device, os) == rv) |
1658 | rv = is_valid_soft_transition(os, ns, tconn); | 1673 | rv = is_valid_soft_transition(os, ns, connection); |
1659 | } else | 1674 | } else |
1660 | rv = is_valid_soft_transition(os, ns, tconn); | 1675 | rv = is_valid_soft_transition(os, ns, connection); |
1661 | } | 1676 | } |
1662 | if (rv < SS_SUCCESS) | 1677 | |
1678 | if (rv < SS_SUCCESS) { | ||
1679 | if (flags & CS_VERBOSE) | ||
1680 | print_st_err(device, os, ns, rv); | ||
1663 | break; | 1681 | break; |
1682 | } | ||
1664 | } | 1683 | } |
1665 | rcu_read_unlock(); | 1684 | rcu_read_unlock(); |
1666 | 1685 | ||
1667 | if (rv < SS_SUCCESS && flags & CS_VERBOSE) | ||
1668 | print_st_err(mdev, os, ns, rv); | ||
1669 | |||
1670 | return rv; | 1686 | return rv; |
1671 | } | 1687 | } |
1672 | 1688 | ||
1673 | void | 1689 | void |
1674 | conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 1690 | conn_set_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
1675 | union drbd_state *pns_min, union drbd_state *pns_max, enum chg_state_flags flags) | 1691 | union drbd_state *pns_min, union drbd_state *pns_max, enum chg_state_flags flags) |
1676 | { | 1692 | { |
1677 | union drbd_state ns, os, ns_max = { }; | 1693 | union drbd_state ns, os, ns_max = { }; |
@@ -1682,7 +1698,7 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state | |||
1682 | .disk = D_MASK, | 1698 | .disk = D_MASK, |
1683 | .pdsk = D_MASK | 1699 | .pdsk = D_MASK |
1684 | } }; | 1700 | } }; |
1685 | struct drbd_conf *mdev; | 1701 | struct drbd_peer_device *peer_device; |
1686 | enum drbd_state_rv rv; | 1702 | enum drbd_state_rv rv; |
1687 | int vnr, number_of_volumes = 0; | 1703 | int vnr, number_of_volumes = 0; |
1688 | 1704 | ||
@@ -1690,27 +1706,28 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state | |||
1690 | /* remember last connect time so request_timer_fn() won't | 1706 | /* remember last connect time so request_timer_fn() won't |
1691 | * kill newly established sessions while we are still trying to thaw | 1707 | * kill newly established sessions while we are still trying to thaw |
1692 | * previously frozen IO */ | 1708 | * previously frozen IO */ |
1693 | if (tconn->cstate != C_WF_REPORT_PARAMS && val.conn == C_WF_REPORT_PARAMS) | 1709 | if (connection->cstate != C_WF_REPORT_PARAMS && val.conn == C_WF_REPORT_PARAMS) |
1694 | tconn->last_reconnect_jif = jiffies; | 1710 | connection->last_reconnect_jif = jiffies; |
1695 | 1711 | ||
1696 | tconn->cstate = val.conn; | 1712 | connection->cstate = val.conn; |
1697 | } | 1713 | } |
1698 | 1714 | ||
1699 | rcu_read_lock(); | 1715 | rcu_read_lock(); |
1700 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1716 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1717 | struct drbd_device *device = peer_device->device; | ||
1701 | number_of_volumes++; | 1718 | number_of_volumes++; |
1702 | os = drbd_read_state(mdev); | 1719 | os = drbd_read_state(device); |
1703 | ns = apply_mask_val(os, mask, val); | 1720 | ns = apply_mask_val(os, mask, val); |
1704 | ns = sanitize_state(mdev, ns, NULL); | 1721 | ns = sanitize_state(device, ns, NULL); |
1705 | 1722 | ||
1706 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) | 1723 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) |
1707 | ns.disk = os.disk; | 1724 | ns.disk = os.disk; |
1708 | 1725 | ||
1709 | rv = __drbd_set_state(mdev, ns, flags, NULL); | 1726 | rv = __drbd_set_state(device, ns, flags, NULL); |
1710 | if (rv < SS_SUCCESS) | 1727 | if (rv < SS_SUCCESS) |
1711 | BUG(); | 1728 | BUG(); |
1712 | 1729 | ||
1713 | ns.i = mdev->state.i; | 1730 | ns.i = device->state.i; |
1714 | ns_max.role = max_role(ns.role, ns_max.role); | 1731 | ns_max.role = max_role(ns.role, ns_max.role); |
1715 | ns_max.peer = max_role(ns.peer, ns_max.peer); | 1732 | ns_max.peer = max_role(ns.peer, ns_max.peer); |
1716 | ns_max.conn = max_t(enum drbd_conns, ns.conn, ns_max.conn); | 1733 | ns_max.conn = max_t(enum drbd_conns, ns.conn, ns_max.conn); |
@@ -1735,39 +1752,39 @@ conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state | |||
1735 | } }; | 1752 | } }; |
1736 | } | 1753 | } |
1737 | 1754 | ||
1738 | ns_min.susp = ns_max.susp = tconn->susp; | 1755 | ns_min.susp = ns_max.susp = connection->resource->susp; |
1739 | ns_min.susp_nod = ns_max.susp_nod = tconn->susp_nod; | 1756 | ns_min.susp_nod = ns_max.susp_nod = connection->resource->susp_nod; |
1740 | ns_min.susp_fen = ns_max.susp_fen = tconn->susp_fen; | 1757 | ns_min.susp_fen = ns_max.susp_fen = connection->resource->susp_fen; |
1741 | 1758 | ||
1742 | *pns_min = ns_min; | 1759 | *pns_min = ns_min; |
1743 | *pns_max = ns_max; | 1760 | *pns_max = ns_max; |
1744 | } | 1761 | } |
1745 | 1762 | ||
1746 | static enum drbd_state_rv | 1763 | static enum drbd_state_rv |
1747 | _conn_rq_cond(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val) | 1764 | _conn_rq_cond(struct drbd_connection *connection, union drbd_state mask, union drbd_state val) |
1748 | { | 1765 | { |
1749 | enum drbd_state_rv rv; | 1766 | enum drbd_state_rv rv; |
1750 | 1767 | ||
1751 | if (test_and_clear_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags)) | 1768 | if (test_and_clear_bit(CONN_WD_ST_CHG_OKAY, &connection->flags)) |
1752 | return SS_CW_SUCCESS; | 1769 | return SS_CW_SUCCESS; |
1753 | 1770 | ||
1754 | if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags)) | 1771 | if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &connection->flags)) |
1755 | return SS_CW_FAILED_BY_PEER; | 1772 | return SS_CW_FAILED_BY_PEER; |
1756 | 1773 | ||
1757 | rv = conn_is_valid_transition(tconn, mask, val, 0); | 1774 | rv = conn_is_valid_transition(connection, mask, val, 0); |
1758 | if (rv == SS_SUCCESS && tconn->cstate == C_WF_REPORT_PARAMS) | 1775 | if (rv == SS_SUCCESS && connection->cstate == C_WF_REPORT_PARAMS) |
1759 | rv = SS_UNKNOWN_ERROR; /* continue waiting */ | 1776 | rv = SS_UNKNOWN_ERROR; /* continue waiting */ |
1760 | 1777 | ||
1761 | return rv; | 1778 | return rv; |
1762 | } | 1779 | } |
1763 | 1780 | ||
1764 | enum drbd_state_rv | 1781 | enum drbd_state_rv |
1765 | _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 1782 | _conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
1766 | enum chg_state_flags flags) | 1783 | enum chg_state_flags flags) |
1767 | { | 1784 | { |
1768 | enum drbd_state_rv rv = SS_SUCCESS; | 1785 | enum drbd_state_rv rv = SS_SUCCESS; |
1769 | struct after_conn_state_chg_work *acscw; | 1786 | struct after_conn_state_chg_work *acscw; |
1770 | enum drbd_conns oc = tconn->cstate; | 1787 | enum drbd_conns oc = connection->cstate; |
1771 | union drbd_state ns_max, ns_min, os; | 1788 | union drbd_state ns_max, ns_min, os; |
1772 | bool have_mutex = false; | 1789 | bool have_mutex = false; |
1773 | 1790 | ||
@@ -1777,7 +1794,7 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_ | |||
1777 | goto abort; | 1794 | goto abort; |
1778 | } | 1795 | } |
1779 | 1796 | ||
1780 | rv = conn_is_valid_transition(tconn, mask, val, flags); | 1797 | rv = conn_is_valid_transition(connection, mask, val, flags); |
1781 | if (rv < SS_SUCCESS) | 1798 | if (rv < SS_SUCCESS) |
1782 | goto abort; | 1799 | goto abort; |
1783 | 1800 | ||
@@ -1787,38 +1804,38 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_ | |||
1787 | /* This will be a cluster-wide state change. | 1804 | /* This will be a cluster-wide state change. |
1788 | * Need to give up the spinlock, grab the mutex, | 1805 | * Need to give up the spinlock, grab the mutex, |
1789 | * then send the state change request, ... */ | 1806 | * then send the state change request, ... */ |
1790 | spin_unlock_irq(&tconn->req_lock); | 1807 | spin_unlock_irq(&connection->resource->req_lock); |
1791 | mutex_lock(&tconn->cstate_mutex); | 1808 | mutex_lock(&connection->cstate_mutex); |
1792 | have_mutex = true; | 1809 | have_mutex = true; |
1793 | 1810 | ||
1794 | set_bit(CONN_WD_ST_CHG_REQ, &tconn->flags); | 1811 | set_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
1795 | if (conn_send_state_req(tconn, mask, val)) { | 1812 | if (conn_send_state_req(connection, mask, val)) { |
1796 | /* sending failed. */ | 1813 | /* sending failed. */ |
1797 | clear_bit(CONN_WD_ST_CHG_REQ, &tconn->flags); | 1814 | clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
1798 | rv = SS_CW_FAILED_BY_PEER; | 1815 | rv = SS_CW_FAILED_BY_PEER; |
1799 | /* need to re-aquire the spin lock, though */ | 1816 | /* need to re-aquire the spin lock, though */ |
1800 | goto abort_unlocked; | 1817 | goto abort_unlocked; |
1801 | } | 1818 | } |
1802 | 1819 | ||
1803 | if (val.conn == C_DISCONNECTING) | 1820 | if (val.conn == C_DISCONNECTING) |
1804 | set_bit(DISCONNECT_SENT, &tconn->flags); | 1821 | set_bit(DISCONNECT_SENT, &connection->flags); |
1805 | 1822 | ||
1806 | /* ... and re-aquire the spinlock. | 1823 | /* ... and re-aquire the spinlock. |
1807 | * If _conn_rq_cond() returned >= SS_SUCCESS, we must call | 1824 | * If _conn_rq_cond() returned >= SS_SUCCESS, we must call |
1808 | * conn_set_state() within the same spinlock. */ | 1825 | * conn_set_state() within the same spinlock. */ |
1809 | spin_lock_irq(&tconn->req_lock); | 1826 | spin_lock_irq(&connection->resource->req_lock); |
1810 | wait_event_lock_irq(tconn->ping_wait, | 1827 | wait_event_lock_irq(connection->ping_wait, |
1811 | (rv = _conn_rq_cond(tconn, mask, val)), | 1828 | (rv = _conn_rq_cond(connection, mask, val)), |
1812 | tconn->req_lock); | 1829 | connection->resource->req_lock); |
1813 | clear_bit(CONN_WD_ST_CHG_REQ, &tconn->flags); | 1830 | clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
1814 | if (rv < SS_SUCCESS) | 1831 | if (rv < SS_SUCCESS) |
1815 | goto abort; | 1832 | goto abort; |
1816 | } | 1833 | } |
1817 | 1834 | ||
1818 | conn_old_common_state(tconn, &os, &flags); | 1835 | conn_old_common_state(connection, &os, &flags); |
1819 | flags |= CS_DC_SUSP; | 1836 | flags |= CS_DC_SUSP; |
1820 | conn_set_state(tconn, mask, val, &ns_min, &ns_max, flags); | 1837 | conn_set_state(connection, mask, val, &ns_min, &ns_max, flags); |
1821 | conn_pr_state_change(tconn, os, ns_max, flags); | 1838 | conn_pr_state_change(connection, os, ns_max, flags); |
1822 | 1839 | ||
1823 | acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC); | 1840 | acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC); |
1824 | if (acscw) { | 1841 | if (acscw) { |
@@ -1827,39 +1844,39 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_ | |||
1827 | acscw->ns_max = ns_max; | 1844 | acscw->ns_max = ns_max; |
1828 | acscw->flags = flags; | 1845 | acscw->flags = flags; |
1829 | acscw->w.cb = w_after_conn_state_ch; | 1846 | acscw->w.cb = w_after_conn_state_ch; |
1830 | kref_get(&tconn->kref); | 1847 | kref_get(&connection->kref); |
1831 | acscw->w.tconn = tconn; | 1848 | acscw->connection = connection; |
1832 | drbd_queue_work(&tconn->sender_work, &acscw->w); | 1849 | drbd_queue_work(&connection->sender_work, &acscw->w); |
1833 | } else { | 1850 | } else { |
1834 | conn_err(tconn, "Could not kmalloc an acscw\n"); | 1851 | drbd_err(connection, "Could not kmalloc an acscw\n"); |
1835 | } | 1852 | } |
1836 | 1853 | ||
1837 | abort: | 1854 | abort: |
1838 | if (have_mutex) { | 1855 | if (have_mutex) { |
1839 | /* mutex_unlock() "... must not be used in interrupt context.", | 1856 | /* mutex_unlock() "... must not be used in interrupt context.", |
1840 | * so give up the spinlock, then re-aquire it */ | 1857 | * so give up the spinlock, then re-aquire it */ |
1841 | spin_unlock_irq(&tconn->req_lock); | 1858 | spin_unlock_irq(&connection->resource->req_lock); |
1842 | abort_unlocked: | 1859 | abort_unlocked: |
1843 | mutex_unlock(&tconn->cstate_mutex); | 1860 | mutex_unlock(&connection->cstate_mutex); |
1844 | spin_lock_irq(&tconn->req_lock); | 1861 | spin_lock_irq(&connection->resource->req_lock); |
1845 | } | 1862 | } |
1846 | if (rv < SS_SUCCESS && flags & CS_VERBOSE) { | 1863 | if (rv < SS_SUCCESS && flags & CS_VERBOSE) { |
1847 | conn_err(tconn, "State change failed: %s\n", drbd_set_st_err_str(rv)); | 1864 | drbd_err(connection, "State change failed: %s\n", drbd_set_st_err_str(rv)); |
1848 | conn_err(tconn, " mask = 0x%x val = 0x%x\n", mask.i, val.i); | 1865 | drbd_err(connection, " mask = 0x%x val = 0x%x\n", mask.i, val.i); |
1849 | conn_err(tconn, " old_conn:%s wanted_conn:%s\n", drbd_conn_str(oc), drbd_conn_str(val.conn)); | 1866 | drbd_err(connection, " old_conn:%s wanted_conn:%s\n", drbd_conn_str(oc), drbd_conn_str(val.conn)); |
1850 | } | 1867 | } |
1851 | return rv; | 1868 | return rv; |
1852 | } | 1869 | } |
1853 | 1870 | ||
1854 | enum drbd_state_rv | 1871 | enum drbd_state_rv |
1855 | conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 1872 | conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
1856 | enum chg_state_flags flags) | 1873 | enum chg_state_flags flags) |
1857 | { | 1874 | { |
1858 | enum drbd_state_rv rv; | 1875 | enum drbd_state_rv rv; |
1859 | 1876 | ||
1860 | spin_lock_irq(&tconn->req_lock); | 1877 | spin_lock_irq(&connection->resource->req_lock); |
1861 | rv = _conn_request_state(tconn, mask, val, flags); | 1878 | rv = _conn_request_state(connection, mask, val, flags); |
1862 | spin_unlock_irq(&tconn->req_lock); | 1879 | spin_unlock_irq(&connection->resource->req_lock); |
1863 | 1880 | ||
1864 | return rv; | 1881 | return rv; |
1865 | } | 1882 | } |
diff --git a/drivers/block/drbd/drbd_state.h b/drivers/block/drbd/drbd_state.h index a3c361bbc4b6..cc41605ba21c 100644 --- a/drivers/block/drbd/drbd_state.h +++ b/drivers/block/drbd/drbd_state.h | |||
@@ -1,8 +1,8 @@ | |||
1 | #ifndef DRBD_STATE_H | 1 | #ifndef DRBD_STATE_H |
2 | #define DRBD_STATE_H | 2 | #define DRBD_STATE_H |
3 | 3 | ||
4 | struct drbd_conf; | 4 | struct drbd_device; |
5 | struct drbd_tconn; | 5 | struct drbd_connection; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * DOC: DRBD State macros | 8 | * DOC: DRBD State macros |
@@ -107,36 +107,36 @@ union drbd_dev_state { | |||
107 | unsigned int i; | 107 | unsigned int i; |
108 | }; | 108 | }; |
109 | 109 | ||
110 | extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev, | 110 | extern enum drbd_state_rv drbd_change_state(struct drbd_device *device, |
111 | enum chg_state_flags f, | 111 | enum chg_state_flags f, |
112 | union drbd_state mask, | 112 | union drbd_state mask, |
113 | union drbd_state val); | 113 | union drbd_state val); |
114 | extern void drbd_force_state(struct drbd_conf *, union drbd_state, | 114 | extern void drbd_force_state(struct drbd_device *, union drbd_state, |
115 | union drbd_state); | 115 | union drbd_state); |
116 | extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *, | 116 | extern enum drbd_state_rv _drbd_request_state(struct drbd_device *, |
117 | union drbd_state, | 117 | union drbd_state, |
118 | union drbd_state, | 118 | union drbd_state, |
119 | enum chg_state_flags); | 119 | enum chg_state_flags); |
120 | extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state, | 120 | extern enum drbd_state_rv __drbd_set_state(struct drbd_device *, union drbd_state, |
121 | enum chg_state_flags, | 121 | enum chg_state_flags, |
122 | struct completion *done); | 122 | struct completion *done); |
123 | extern void print_st_err(struct drbd_conf *, union drbd_state, | 123 | extern void print_st_err(struct drbd_device *, union drbd_state, |
124 | union drbd_state, int); | 124 | union drbd_state, int); |
125 | 125 | ||
126 | enum drbd_state_rv | 126 | enum drbd_state_rv |
127 | _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 127 | _conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
128 | enum chg_state_flags flags); | 128 | enum chg_state_flags flags); |
129 | 129 | ||
130 | enum drbd_state_rv | 130 | enum drbd_state_rv |
131 | conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val, | 131 | conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
132 | enum chg_state_flags flags); | 132 | enum chg_state_flags flags); |
133 | 133 | ||
134 | extern void drbd_resume_al(struct drbd_conf *mdev); | 134 | extern void drbd_resume_al(struct drbd_device *device); |
135 | extern bool conn_all_vols_unconf(struct drbd_tconn *tconn); | 135 | extern bool conn_all_vols_unconf(struct drbd_connection *connection); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * drbd_request_state() - Reqest a state change | 138 | * drbd_request_state() - Reqest a state change |
139 | * @mdev: DRBD device. | 139 | * @device: DRBD device. |
140 | * @mask: mask of state bits to change. | 140 | * @mask: mask of state bits to change. |
141 | * @val: value of new state bits. | 141 | * @val: value of new state bits. |
142 | * | 142 | * |
@@ -144,18 +144,18 @@ extern bool conn_all_vols_unconf(struct drbd_tconn *tconn); | |||
144 | * quite verbose in case the state change is not possible, and all those | 144 | * quite verbose in case the state change is not possible, and all those |
145 | * state changes are globally serialized. | 145 | * state changes are globally serialized. |
146 | */ | 146 | */ |
147 | static inline int drbd_request_state(struct drbd_conf *mdev, | 147 | static inline int drbd_request_state(struct drbd_device *device, |
148 | union drbd_state mask, | 148 | union drbd_state mask, |
149 | union drbd_state val) | 149 | union drbd_state val) |
150 | { | 150 | { |
151 | return _drbd_request_state(mdev, mask, val, CS_VERBOSE + CS_ORDERED); | 151 | return _drbd_request_state(device, mask, val, CS_VERBOSE + CS_ORDERED); |
152 | } | 152 | } |
153 | 153 | ||
154 | enum drbd_role conn_highest_role(struct drbd_tconn *tconn); | 154 | enum drbd_role conn_highest_role(struct drbd_connection *connection); |
155 | enum drbd_role conn_highest_peer(struct drbd_tconn *tconn); | 155 | enum drbd_role conn_highest_peer(struct drbd_connection *connection); |
156 | enum drbd_disk_state conn_highest_disk(struct drbd_tconn *tconn); | 156 | enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection); |
157 | enum drbd_disk_state conn_lowest_disk(struct drbd_tconn *tconn); | 157 | enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection); |
158 | enum drbd_disk_state conn_highest_pdsk(struct drbd_tconn *tconn); | 158 | enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection); |
159 | enum drbd_conns conn_lowest_conn(struct drbd_tconn *tconn); | 159 | enum drbd_conns conn_lowest_conn(struct drbd_connection *connection); |
160 | 160 | ||
161 | #endif | 161 | #endif |
diff --git a/drivers/block/drbd/drbd_strings.c b/drivers/block/drbd/drbd_strings.c index 58e08ff2b2ce..80b0f63c7075 100644 --- a/drivers/block/drbd/drbd_strings.c +++ b/drivers/block/drbd/drbd_strings.c | |||
@@ -24,6 +24,7 @@ | |||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/drbd.h> | 26 | #include <linux/drbd.h> |
27 | #include "drbd_strings.h" | ||
27 | 28 | ||
28 | static const char *drbd_conn_s_names[] = { | 29 | static const char *drbd_conn_s_names[] = { |
29 | [C_STANDALONE] = "StandAlone", | 30 | [C_STANDALONE] = "StandAlone", |
diff --git a/drivers/block/drbd/drbd_strings.h b/drivers/block/drbd/drbd_strings.h new file mode 100644 index 000000000000..f9923cc88afb --- /dev/null +++ b/drivers/block/drbd/drbd_strings.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef __DRBD_STRINGS_H | ||
2 | #define __DRBD_STRINGS_H | ||
3 | |||
4 | extern const char *drbd_conn_str(enum drbd_conns); | ||
5 | extern const char *drbd_role_str(enum drbd_role); | ||
6 | extern const char *drbd_disk_str(enum drbd_disk_state); | ||
7 | extern const char *drbd_set_st_err_str(enum drbd_state_rv); | ||
8 | |||
9 | #endif /* __DRBD_STRINGS_H */ | ||
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c index 84d3175d493a..2c4ce42c3657 100644 --- a/drivers/block/drbd/drbd_worker.c +++ b/drivers/block/drbd/drbd_worker.c | |||
@@ -21,7 +21,7 @@ | |||
21 | along with drbd; see the file COPYING. If not, write to | 21 | along with drbd; see the file COPYING. If not, write to |
22 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/drbd.h> | 27 | #include <linux/drbd.h> |
@@ -36,10 +36,11 @@ | |||
36 | #include <linux/scatterlist.h> | 36 | #include <linux/scatterlist.h> |
37 | 37 | ||
38 | #include "drbd_int.h" | 38 | #include "drbd_int.h" |
39 | #include "drbd_protocol.h" | ||
39 | #include "drbd_req.h" | 40 | #include "drbd_req.h" |
40 | 41 | ||
41 | static int w_make_ov_request(struct drbd_work *w, int cancel); | 42 | static int make_ov_request(struct drbd_device *, int); |
42 | 43 | static int make_resync_request(struct drbd_device *, int); | |
43 | 44 | ||
44 | /* endio handlers: | 45 | /* endio handlers: |
45 | * drbd_md_io_complete (defined here) | 46 | * drbd_md_io_complete (defined here) |
@@ -67,10 +68,10 @@ rwlock_t global_state_lock; | |||
67 | void drbd_md_io_complete(struct bio *bio, int error) | 68 | void drbd_md_io_complete(struct bio *bio, int error) |
68 | { | 69 | { |
69 | struct drbd_md_io *md_io; | 70 | struct drbd_md_io *md_io; |
70 | struct drbd_conf *mdev; | 71 | struct drbd_device *device; |
71 | 72 | ||
72 | md_io = (struct drbd_md_io *)bio->bi_private; | 73 | md_io = (struct drbd_md_io *)bio->bi_private; |
73 | mdev = container_of(md_io, struct drbd_conf, md_io); | 74 | device = container_of(md_io, struct drbd_device, md_io); |
74 | 75 | ||
75 | md_io->error = error; | 76 | md_io->error = error; |
76 | 77 | ||
@@ -83,35 +84,36 @@ void drbd_md_io_complete(struct bio *bio, int error) | |||
83 | * Make sure we first drop the reference, and only then signal | 84 | * Make sure we first drop the reference, and only then signal |
84 | * completion, or we may (in drbd_al_read_log()) cycle so fast into the | 85 | * completion, or we may (in drbd_al_read_log()) cycle so fast into the |
85 | * next drbd_md_sync_page_io(), that we trigger the | 86 | * next drbd_md_sync_page_io(), that we trigger the |
86 | * ASSERT(atomic_read(&mdev->md_io_in_use) == 1) there. | 87 | * ASSERT(atomic_read(&device->md_io_in_use) == 1) there. |
87 | */ | 88 | */ |
88 | drbd_md_put_buffer(mdev); | 89 | drbd_md_put_buffer(device); |
89 | md_io->done = 1; | 90 | md_io->done = 1; |
90 | wake_up(&mdev->misc_wait); | 91 | wake_up(&device->misc_wait); |
91 | bio_put(bio); | 92 | bio_put(bio); |
92 | if (mdev->ldev) /* special case: drbd_md_read() during drbd_adm_attach() */ | 93 | if (device->ldev) /* special case: drbd_md_read() during drbd_adm_attach() */ |
93 | put_ldev(mdev); | 94 | put_ldev(device); |
94 | } | 95 | } |
95 | 96 | ||
96 | /* reads on behalf of the partner, | 97 | /* reads on behalf of the partner, |
97 | * "submitted" by the receiver | 98 | * "submitted" by the receiver |
98 | */ | 99 | */ |
99 | void drbd_endio_read_sec_final(struct drbd_peer_request *peer_req) __releases(local) | 100 | static void drbd_endio_read_sec_final(struct drbd_peer_request *peer_req) __releases(local) |
100 | { | 101 | { |
101 | unsigned long flags = 0; | 102 | unsigned long flags = 0; |
102 | struct drbd_conf *mdev = peer_req->w.mdev; | 103 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
104 | struct drbd_device *device = peer_device->device; | ||
103 | 105 | ||
104 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 106 | spin_lock_irqsave(&device->resource->req_lock, flags); |
105 | mdev->read_cnt += peer_req->i.size >> 9; | 107 | device->read_cnt += peer_req->i.size >> 9; |
106 | list_del(&peer_req->w.list); | 108 | list_del(&peer_req->w.list); |
107 | if (list_empty(&mdev->read_ee)) | 109 | if (list_empty(&device->read_ee)) |
108 | wake_up(&mdev->ee_wait); | 110 | wake_up(&device->ee_wait); |
109 | if (test_bit(__EE_WAS_ERROR, &peer_req->flags)) | 111 | if (test_bit(__EE_WAS_ERROR, &peer_req->flags)) |
110 | __drbd_chk_io_error(mdev, DRBD_READ_ERROR); | 112 | __drbd_chk_io_error(device, DRBD_READ_ERROR); |
111 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 113 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
112 | 114 | ||
113 | drbd_queue_work(&mdev->tconn->sender_work, &peer_req->w); | 115 | drbd_queue_work(&peer_device->connection->sender_work, &peer_req->w); |
114 | put_ldev(mdev); | 116 | put_ldev(device); |
115 | } | 117 | } |
116 | 118 | ||
117 | /* writes on behalf of the partner, or resync writes, | 119 | /* writes on behalf of the partner, or resync writes, |
@@ -119,7 +121,8 @@ void drbd_endio_read_sec_final(struct drbd_peer_request *peer_req) __releases(lo | |||
119 | static void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __releases(local) | 121 | static void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __releases(local) |
120 | { | 122 | { |
121 | unsigned long flags = 0; | 123 | unsigned long flags = 0; |
122 | struct drbd_conf *mdev = peer_req->w.mdev; | 124 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
125 | struct drbd_device *device = peer_device->device; | ||
123 | struct drbd_interval i; | 126 | struct drbd_interval i; |
124 | int do_wake; | 127 | int do_wake; |
125 | u64 block_id; | 128 | u64 block_id; |
@@ -133,35 +136,35 @@ static void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __rel | |||
133 | do_al_complete_io = peer_req->flags & EE_CALL_AL_COMPLETE_IO; | 136 | do_al_complete_io = peer_req->flags & EE_CALL_AL_COMPLETE_IO; |
134 | block_id = peer_req->block_id; | 137 | block_id = peer_req->block_id; |
135 | 138 | ||
136 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 139 | spin_lock_irqsave(&device->resource->req_lock, flags); |
137 | mdev->writ_cnt += peer_req->i.size >> 9; | 140 | device->writ_cnt += peer_req->i.size >> 9; |
138 | list_move_tail(&peer_req->w.list, &mdev->done_ee); | 141 | list_move_tail(&peer_req->w.list, &device->done_ee); |
139 | 142 | ||
140 | /* | 143 | /* |
141 | * Do not remove from the write_requests tree here: we did not send the | 144 | * Do not remove from the write_requests tree here: we did not send the |
142 | * Ack yet and did not wake possibly waiting conflicting requests. | 145 | * Ack yet and did not wake possibly waiting conflicting requests. |
143 | * Removed from the tree from "drbd_process_done_ee" within the | 146 | * Removed from the tree from "drbd_process_done_ee" within the |
144 | * appropriate w.cb (e_end_block/e_end_resync_block) or from | 147 | * appropriate dw.cb (e_end_block/e_end_resync_block) or from |
145 | * _drbd_clear_done_ee. | 148 | * _drbd_clear_done_ee. |
146 | */ | 149 | */ |
147 | 150 | ||
148 | do_wake = list_empty(block_id == ID_SYNCER ? &mdev->sync_ee : &mdev->active_ee); | 151 | do_wake = list_empty(block_id == ID_SYNCER ? &device->sync_ee : &device->active_ee); |
149 | 152 | ||
150 | if (test_bit(__EE_WAS_ERROR, &peer_req->flags)) | 153 | if (test_bit(__EE_WAS_ERROR, &peer_req->flags)) |
151 | __drbd_chk_io_error(mdev, DRBD_WRITE_ERROR); | 154 | __drbd_chk_io_error(device, DRBD_WRITE_ERROR); |
152 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 155 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
153 | 156 | ||
154 | if (block_id == ID_SYNCER) | 157 | if (block_id == ID_SYNCER) |
155 | drbd_rs_complete_io(mdev, i.sector); | 158 | drbd_rs_complete_io(device, i.sector); |
156 | 159 | ||
157 | if (do_wake) | 160 | if (do_wake) |
158 | wake_up(&mdev->ee_wait); | 161 | wake_up(&device->ee_wait); |
159 | 162 | ||
160 | if (do_al_complete_io) | 163 | if (do_al_complete_io) |
161 | drbd_al_complete_io(mdev, &i); | 164 | drbd_al_complete_io(device, &i); |
162 | 165 | ||
163 | wake_asender(mdev->tconn); | 166 | wake_asender(peer_device->connection); |
164 | put_ldev(mdev); | 167 | put_ldev(device); |
165 | } | 168 | } |
166 | 169 | ||
167 | /* writes on behalf of the partner, or resync writes, | 170 | /* writes on behalf of the partner, or resync writes, |
@@ -170,17 +173,17 @@ static void drbd_endio_write_sec_final(struct drbd_peer_request *peer_req) __rel | |||
170 | void drbd_peer_request_endio(struct bio *bio, int error) | 173 | void drbd_peer_request_endio(struct bio *bio, int error) |
171 | { | 174 | { |
172 | struct drbd_peer_request *peer_req = bio->bi_private; | 175 | struct drbd_peer_request *peer_req = bio->bi_private; |
173 | struct drbd_conf *mdev = peer_req->w.mdev; | 176 | struct drbd_device *device = peer_req->peer_device->device; |
174 | int uptodate = bio_flagged(bio, BIO_UPTODATE); | 177 | int uptodate = bio_flagged(bio, BIO_UPTODATE); |
175 | int is_write = bio_data_dir(bio) == WRITE; | 178 | int is_write = bio_data_dir(bio) == WRITE; |
176 | 179 | ||
177 | if (error && __ratelimit(&drbd_ratelimit_state)) | 180 | if (error && __ratelimit(&drbd_ratelimit_state)) |
178 | dev_warn(DEV, "%s: error=%d s=%llus\n", | 181 | drbd_warn(device, "%s: error=%d s=%llus\n", |
179 | is_write ? "write" : "read", error, | 182 | is_write ? "write" : "read", error, |
180 | (unsigned long long)peer_req->i.sector); | 183 | (unsigned long long)peer_req->i.sector); |
181 | if (!error && !uptodate) { | 184 | if (!error && !uptodate) { |
182 | if (__ratelimit(&drbd_ratelimit_state)) | 185 | if (__ratelimit(&drbd_ratelimit_state)) |
183 | dev_warn(DEV, "%s: setting error to -EIO s=%llus\n", | 186 | drbd_warn(device, "%s: setting error to -EIO s=%llus\n", |
184 | is_write ? "write" : "read", | 187 | is_write ? "write" : "read", |
185 | (unsigned long long)peer_req->i.sector); | 188 | (unsigned long long)peer_req->i.sector); |
186 | /* strange behavior of some lower level drivers... | 189 | /* strange behavior of some lower level drivers... |
@@ -207,13 +210,13 @@ void drbd_request_endio(struct bio *bio, int error) | |||
207 | { | 210 | { |
208 | unsigned long flags; | 211 | unsigned long flags; |
209 | struct drbd_request *req = bio->bi_private; | 212 | struct drbd_request *req = bio->bi_private; |
210 | struct drbd_conf *mdev = req->w.mdev; | 213 | struct drbd_device *device = req->device; |
211 | struct bio_and_error m; | 214 | struct bio_and_error m; |
212 | enum drbd_req_event what; | 215 | enum drbd_req_event what; |
213 | int uptodate = bio_flagged(bio, BIO_UPTODATE); | 216 | int uptodate = bio_flagged(bio, BIO_UPTODATE); |
214 | 217 | ||
215 | if (!error && !uptodate) { | 218 | if (!error && !uptodate) { |
216 | dev_warn(DEV, "p %s: setting error to -EIO\n", | 219 | drbd_warn(device, "p %s: setting error to -EIO\n", |
217 | bio_data_dir(bio) == WRITE ? "write" : "read"); | 220 | bio_data_dir(bio) == WRITE ? "write" : "read"); |
218 | /* strange behavior of some lower level drivers... | 221 | /* strange behavior of some lower level drivers... |
219 | * fail the request by clearing the uptodate flag, | 222 | * fail the request by clearing the uptodate flag, |
@@ -252,7 +255,7 @@ void drbd_request_endio(struct bio *bio, int error) | |||
252 | */ | 255 | */ |
253 | if (unlikely(req->rq_state & RQ_LOCAL_ABORTED)) { | 256 | if (unlikely(req->rq_state & RQ_LOCAL_ABORTED)) { |
254 | if (__ratelimit(&drbd_ratelimit_state)) | 257 | if (__ratelimit(&drbd_ratelimit_state)) |
255 | dev_emerg(DEV, "delayed completion of aborted local request; disk-timeout may be too aggressive\n"); | 258 | drbd_emerg(device, "delayed completion of aborted local request; disk-timeout may be too aggressive\n"); |
256 | 259 | ||
257 | if (!error) | 260 | if (!error) |
258 | panic("possible random memory corruption caused by delayed completion of aborted local request\n"); | 261 | panic("possible random memory corruption caused by delayed completion of aborted local request\n"); |
@@ -272,17 +275,16 @@ void drbd_request_endio(struct bio *bio, int error) | |||
272 | req->private_bio = ERR_PTR(error); | 275 | req->private_bio = ERR_PTR(error); |
273 | 276 | ||
274 | /* not req_mod(), we need irqsave here! */ | 277 | /* not req_mod(), we need irqsave here! */ |
275 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); | 278 | spin_lock_irqsave(&device->resource->req_lock, flags); |
276 | __req_mod(req, what, &m); | 279 | __req_mod(req, what, &m); |
277 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); | 280 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
278 | put_ldev(mdev); | 281 | put_ldev(device); |
279 | 282 | ||
280 | if (m.bio) | 283 | if (m.bio) |
281 | complete_master_bio(mdev, &m); | 284 | complete_master_bio(device, &m); |
282 | } | 285 | } |
283 | 286 | ||
284 | void drbd_csum_ee(struct drbd_conf *mdev, struct crypto_hash *tfm, | 287 | void drbd_csum_ee(struct crypto_hash *tfm, struct drbd_peer_request *peer_req, void *digest) |
285 | struct drbd_peer_request *peer_req, void *digest) | ||
286 | { | 288 | { |
287 | struct hash_desc desc; | 289 | struct hash_desc desc; |
288 | struct scatterlist sg; | 290 | struct scatterlist sg; |
@@ -309,7 +311,7 @@ void drbd_csum_ee(struct drbd_conf *mdev, struct crypto_hash *tfm, | |||
309 | crypto_hash_final(&desc, digest); | 311 | crypto_hash_final(&desc, digest); |
310 | } | 312 | } |
311 | 313 | ||
312 | void drbd_csum_bio(struct drbd_conf *mdev, struct crypto_hash *tfm, struct bio *bio, void *digest) | 314 | void drbd_csum_bio(struct crypto_hash *tfm, struct bio *bio, void *digest) |
313 | { | 315 | { |
314 | struct hash_desc desc; | 316 | struct hash_desc desc; |
315 | struct scatterlist sg; | 317 | struct scatterlist sg; |
@@ -333,7 +335,8 @@ void drbd_csum_bio(struct drbd_conf *mdev, struct crypto_hash *tfm, struct bio * | |||
333 | static int w_e_send_csum(struct drbd_work *w, int cancel) | 335 | static int w_e_send_csum(struct drbd_work *w, int cancel) |
334 | { | 336 | { |
335 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 337 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
336 | struct drbd_conf *mdev = w->mdev; | 338 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
339 | struct drbd_device *device = peer_device->device; | ||
337 | int digest_size; | 340 | int digest_size; |
338 | void *digest; | 341 | void *digest; |
339 | int err = 0; | 342 | int err = 0; |
@@ -344,89 +347,92 @@ static int w_e_send_csum(struct drbd_work *w, int cancel) | |||
344 | if (unlikely((peer_req->flags & EE_WAS_ERROR) != 0)) | 347 | if (unlikely((peer_req->flags & EE_WAS_ERROR) != 0)) |
345 | goto out; | 348 | goto out; |
346 | 349 | ||
347 | digest_size = crypto_hash_digestsize(mdev->tconn->csums_tfm); | 350 | digest_size = crypto_hash_digestsize(peer_device->connection->csums_tfm); |
348 | digest = kmalloc(digest_size, GFP_NOIO); | 351 | digest = kmalloc(digest_size, GFP_NOIO); |
349 | if (digest) { | 352 | if (digest) { |
350 | sector_t sector = peer_req->i.sector; | 353 | sector_t sector = peer_req->i.sector; |
351 | unsigned int size = peer_req->i.size; | 354 | unsigned int size = peer_req->i.size; |
352 | drbd_csum_ee(mdev, mdev->tconn->csums_tfm, peer_req, digest); | 355 | drbd_csum_ee(peer_device->connection->csums_tfm, peer_req, digest); |
353 | /* Free peer_req and pages before send. | 356 | /* Free peer_req and pages before send. |
354 | * In case we block on congestion, we could otherwise run into | 357 | * In case we block on congestion, we could otherwise run into |
355 | * some distributed deadlock, if the other side blocks on | 358 | * some distributed deadlock, if the other side blocks on |
356 | * congestion as well, because our receiver blocks in | 359 | * congestion as well, because our receiver blocks in |
357 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ | 360 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ |
358 | drbd_free_peer_req(mdev, peer_req); | 361 | drbd_free_peer_req(device, peer_req); |
359 | peer_req = NULL; | 362 | peer_req = NULL; |
360 | inc_rs_pending(mdev); | 363 | inc_rs_pending(device); |
361 | err = drbd_send_drequest_csum(mdev, sector, size, | 364 | err = drbd_send_drequest_csum(peer_device, sector, size, |
362 | digest, digest_size, | 365 | digest, digest_size, |
363 | P_CSUM_RS_REQUEST); | 366 | P_CSUM_RS_REQUEST); |
364 | kfree(digest); | 367 | kfree(digest); |
365 | } else { | 368 | } else { |
366 | dev_err(DEV, "kmalloc() of digest failed.\n"); | 369 | drbd_err(device, "kmalloc() of digest failed.\n"); |
367 | err = -ENOMEM; | 370 | err = -ENOMEM; |
368 | } | 371 | } |
369 | 372 | ||
370 | out: | 373 | out: |
371 | if (peer_req) | 374 | if (peer_req) |
372 | drbd_free_peer_req(mdev, peer_req); | 375 | drbd_free_peer_req(device, peer_req); |
373 | 376 | ||
374 | if (unlikely(err)) | 377 | if (unlikely(err)) |
375 | dev_err(DEV, "drbd_send_drequest(..., csum) failed\n"); | 378 | drbd_err(device, "drbd_send_drequest(..., csum) failed\n"); |
376 | return err; | 379 | return err; |
377 | } | 380 | } |
378 | 381 | ||
379 | #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) | 382 | #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) |
380 | 383 | ||
381 | static int read_for_csum(struct drbd_conf *mdev, sector_t sector, int size) | 384 | static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector, int size) |
382 | { | 385 | { |
386 | struct drbd_device *device = peer_device->device; | ||
383 | struct drbd_peer_request *peer_req; | 387 | struct drbd_peer_request *peer_req; |
384 | 388 | ||
385 | if (!get_ldev(mdev)) | 389 | if (!get_ldev(device)) |
386 | return -EIO; | 390 | return -EIO; |
387 | 391 | ||
388 | if (drbd_rs_should_slow_down(mdev, sector)) | 392 | if (drbd_rs_should_slow_down(device, sector)) |
389 | goto defer; | 393 | goto defer; |
390 | 394 | ||
391 | /* GFP_TRY, because if there is no memory available right now, this may | 395 | /* GFP_TRY, because if there is no memory available right now, this may |
392 | * be rescheduled for later. It is "only" background resync, after all. */ | 396 | * be rescheduled for later. It is "only" background resync, after all. */ |
393 | peer_req = drbd_alloc_peer_req(mdev, ID_SYNCER /* unused */, sector, | 397 | peer_req = drbd_alloc_peer_req(peer_device, ID_SYNCER /* unused */, sector, |
394 | size, GFP_TRY); | 398 | size, GFP_TRY); |
395 | if (!peer_req) | 399 | if (!peer_req) |
396 | goto defer; | 400 | goto defer; |
397 | 401 | ||
398 | peer_req->w.cb = w_e_send_csum; | 402 | peer_req->w.cb = w_e_send_csum; |
399 | spin_lock_irq(&mdev->tconn->req_lock); | 403 | spin_lock_irq(&device->resource->req_lock); |
400 | list_add(&peer_req->w.list, &mdev->read_ee); | 404 | list_add(&peer_req->w.list, &device->read_ee); |
401 | spin_unlock_irq(&mdev->tconn->req_lock); | 405 | spin_unlock_irq(&device->resource->req_lock); |
402 | 406 | ||
403 | atomic_add(size >> 9, &mdev->rs_sect_ev); | 407 | atomic_add(size >> 9, &device->rs_sect_ev); |
404 | if (drbd_submit_peer_request(mdev, peer_req, READ, DRBD_FAULT_RS_RD) == 0) | 408 | if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0) |
405 | return 0; | 409 | return 0; |
406 | 410 | ||
407 | /* If it failed because of ENOMEM, retry should help. If it failed | 411 | /* If it failed because of ENOMEM, retry should help. If it failed |
408 | * because bio_add_page failed (probably broken lower level driver), | 412 | * because bio_add_page failed (probably broken lower level driver), |
409 | * retry may or may not help. | 413 | * retry may or may not help. |
410 | * If it does not, you may need to force disconnect. */ | 414 | * If it does not, you may need to force disconnect. */ |
411 | spin_lock_irq(&mdev->tconn->req_lock); | 415 | spin_lock_irq(&device->resource->req_lock); |
412 | list_del(&peer_req->w.list); | 416 | list_del(&peer_req->w.list); |
413 | spin_unlock_irq(&mdev->tconn->req_lock); | 417 | spin_unlock_irq(&device->resource->req_lock); |
414 | 418 | ||
415 | drbd_free_peer_req(mdev, peer_req); | 419 | drbd_free_peer_req(device, peer_req); |
416 | defer: | 420 | defer: |
417 | put_ldev(mdev); | 421 | put_ldev(device); |
418 | return -EAGAIN; | 422 | return -EAGAIN; |
419 | } | 423 | } |
420 | 424 | ||
421 | int w_resync_timer(struct drbd_work *w, int cancel) | 425 | int w_resync_timer(struct drbd_work *w, int cancel) |
422 | { | 426 | { |
423 | struct drbd_conf *mdev = w->mdev; | 427 | struct drbd_device *device = |
424 | switch (mdev->state.conn) { | 428 | container_of(w, struct drbd_device, resync_work); |
429 | |||
430 | switch (device->state.conn) { | ||
425 | case C_VERIFY_S: | 431 | case C_VERIFY_S: |
426 | w_make_ov_request(w, cancel); | 432 | make_ov_request(device, cancel); |
427 | break; | 433 | break; |
428 | case C_SYNC_TARGET: | 434 | case C_SYNC_TARGET: |
429 | w_make_resync_request(w, cancel); | 435 | make_resync_request(device, cancel); |
430 | break; | 436 | break; |
431 | } | 437 | } |
432 | 438 | ||
@@ -435,10 +441,11 @@ int w_resync_timer(struct drbd_work *w, int cancel) | |||
435 | 441 | ||
436 | void resync_timer_fn(unsigned long data) | 442 | void resync_timer_fn(unsigned long data) |
437 | { | 443 | { |
438 | struct drbd_conf *mdev = (struct drbd_conf *) data; | 444 | struct drbd_device *device = (struct drbd_device *) data; |
439 | 445 | ||
440 | if (list_empty(&mdev->resync_work.list)) | 446 | if (list_empty(&device->resync_work.list)) |
441 | drbd_queue_work(&mdev->tconn->sender_work, &mdev->resync_work); | 447 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
448 | &device->resync_work); | ||
442 | } | 449 | } |
443 | 450 | ||
444 | static void fifo_set(struct fifo_buffer *fb, int value) | 451 | static void fifo_set(struct fifo_buffer *fb, int value) |
@@ -485,7 +492,7 @@ struct fifo_buffer *fifo_alloc(int fifo_size) | |||
485 | return fb; | 492 | return fb; |
486 | } | 493 | } |
487 | 494 | ||
488 | static int drbd_rs_controller(struct drbd_conf *mdev) | 495 | static int drbd_rs_controller(struct drbd_device *device) |
489 | { | 496 | { |
490 | struct disk_conf *dc; | 497 | struct disk_conf *dc; |
491 | unsigned int sect_in; /* Number of sectors that came in since the last turn */ | 498 | unsigned int sect_in; /* Number of sectors that came in since the last turn */ |
@@ -498,22 +505,22 @@ static int drbd_rs_controller(struct drbd_conf *mdev) | |||
498 | int max_sect; | 505 | int max_sect; |
499 | struct fifo_buffer *plan; | 506 | struct fifo_buffer *plan; |
500 | 507 | ||
501 | sect_in = atomic_xchg(&mdev->rs_sect_in, 0); /* Number of sectors that came in */ | 508 | sect_in = atomic_xchg(&device->rs_sect_in, 0); /* Number of sectors that came in */ |
502 | mdev->rs_in_flight -= sect_in; | 509 | device->rs_in_flight -= sect_in; |
503 | 510 | ||
504 | dc = rcu_dereference(mdev->ldev->disk_conf); | 511 | dc = rcu_dereference(device->ldev->disk_conf); |
505 | plan = rcu_dereference(mdev->rs_plan_s); | 512 | plan = rcu_dereference(device->rs_plan_s); |
506 | 513 | ||
507 | steps = plan->size; /* (dc->c_plan_ahead * 10 * SLEEP_TIME) / HZ; */ | 514 | steps = plan->size; /* (dc->c_plan_ahead * 10 * SLEEP_TIME) / HZ; */ |
508 | 515 | ||
509 | if (mdev->rs_in_flight + sect_in == 0) { /* At start of resync */ | 516 | if (device->rs_in_flight + sect_in == 0) { /* At start of resync */ |
510 | want = ((dc->resync_rate * 2 * SLEEP_TIME) / HZ) * steps; | 517 | want = ((dc->resync_rate * 2 * SLEEP_TIME) / HZ) * steps; |
511 | } else { /* normal path */ | 518 | } else { /* normal path */ |
512 | want = dc->c_fill_target ? dc->c_fill_target : | 519 | want = dc->c_fill_target ? dc->c_fill_target : |
513 | sect_in * dc->c_delay_target * HZ / (SLEEP_TIME * 10); | 520 | sect_in * dc->c_delay_target * HZ / (SLEEP_TIME * 10); |
514 | } | 521 | } |
515 | 522 | ||
516 | correction = want - mdev->rs_in_flight - plan->total; | 523 | correction = want - device->rs_in_flight - plan->total; |
517 | 524 | ||
518 | /* Plan ahead */ | 525 | /* Plan ahead */ |
519 | cps = correction / steps; | 526 | cps = correction / steps; |
@@ -533,25 +540,25 @@ static int drbd_rs_controller(struct drbd_conf *mdev) | |||
533 | req_sect = max_sect; | 540 | req_sect = max_sect; |
534 | 541 | ||
535 | /* | 542 | /* |
536 | dev_warn(DEV, "si=%u if=%d wa=%u co=%d st=%d cps=%d pl=%d cc=%d rs=%d\n", | 543 | drbd_warn(device, "si=%u if=%d wa=%u co=%d st=%d cps=%d pl=%d cc=%d rs=%d\n", |
537 | sect_in, mdev->rs_in_flight, want, correction, | 544 | sect_in, device->rs_in_flight, want, correction, |
538 | steps, cps, mdev->rs_planed, curr_corr, req_sect); | 545 | steps, cps, device->rs_planed, curr_corr, req_sect); |
539 | */ | 546 | */ |
540 | 547 | ||
541 | return req_sect; | 548 | return req_sect; |
542 | } | 549 | } |
543 | 550 | ||
544 | static int drbd_rs_number_requests(struct drbd_conf *mdev) | 551 | static int drbd_rs_number_requests(struct drbd_device *device) |
545 | { | 552 | { |
546 | int number; | 553 | int number; |
547 | 554 | ||
548 | rcu_read_lock(); | 555 | rcu_read_lock(); |
549 | if (rcu_dereference(mdev->rs_plan_s)->size) { | 556 | if (rcu_dereference(device->rs_plan_s)->size) { |
550 | number = drbd_rs_controller(mdev) >> (BM_BLOCK_SHIFT - 9); | 557 | number = drbd_rs_controller(device) >> (BM_BLOCK_SHIFT - 9); |
551 | mdev->c_sync_rate = number * HZ * (BM_BLOCK_SIZE / 1024) / SLEEP_TIME; | 558 | device->c_sync_rate = number * HZ * (BM_BLOCK_SIZE / 1024) / SLEEP_TIME; |
552 | } else { | 559 | } else { |
553 | mdev->c_sync_rate = rcu_dereference(mdev->ldev->disk_conf)->resync_rate; | 560 | device->c_sync_rate = rcu_dereference(device->ldev->disk_conf)->resync_rate; |
554 | number = SLEEP_TIME * mdev->c_sync_rate / ((BM_BLOCK_SIZE / 1024) * HZ); | 561 | number = SLEEP_TIME * device->c_sync_rate / ((BM_BLOCK_SIZE / 1024) * HZ); |
555 | } | 562 | } |
556 | rcu_read_unlock(); | 563 | rcu_read_unlock(); |
557 | 564 | ||
@@ -560,12 +567,11 @@ static int drbd_rs_number_requests(struct drbd_conf *mdev) | |||
560 | return number; | 567 | return number; |
561 | } | 568 | } |
562 | 569 | ||
563 | int w_make_resync_request(struct drbd_work *w, int cancel) | 570 | static int make_resync_request(struct drbd_device *device, int cancel) |
564 | { | 571 | { |
565 | struct drbd_conf *mdev = w->mdev; | ||
566 | unsigned long bit; | 572 | unsigned long bit; |
567 | sector_t sector; | 573 | sector_t sector; |
568 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); | 574 | const sector_t capacity = drbd_get_capacity(device->this_bdev); |
569 | int max_bio_size; | 575 | int max_bio_size; |
570 | int number, rollback_i, size; | 576 | int number, rollback_i, size; |
571 | int align, queued, sndbuf; | 577 | int align, queued, sndbuf; |
@@ -574,61 +580,61 @@ int w_make_resync_request(struct drbd_work *w, int cancel) | |||
574 | if (unlikely(cancel)) | 580 | if (unlikely(cancel)) |
575 | return 0; | 581 | return 0; |
576 | 582 | ||
577 | if (mdev->rs_total == 0) { | 583 | if (device->rs_total == 0) { |
578 | /* empty resync? */ | 584 | /* empty resync? */ |
579 | drbd_resync_finished(mdev); | 585 | drbd_resync_finished(device); |
580 | return 0; | 586 | return 0; |
581 | } | 587 | } |
582 | 588 | ||
583 | if (!get_ldev(mdev)) { | 589 | if (!get_ldev(device)) { |
584 | /* Since we only need to access mdev->rsync a | 590 | /* Since we only need to access device->rsync a |
585 | get_ldev_if_state(mdev,D_FAILED) would be sufficient, but | 591 | get_ldev_if_state(device,D_FAILED) would be sufficient, but |
586 | to continue resync with a broken disk makes no sense at | 592 | to continue resync with a broken disk makes no sense at |
587 | all */ | 593 | all */ |
588 | dev_err(DEV, "Disk broke down during resync!\n"); | 594 | drbd_err(device, "Disk broke down during resync!\n"); |
589 | return 0; | 595 | return 0; |
590 | } | 596 | } |
591 | 597 | ||
592 | max_bio_size = queue_max_hw_sectors(mdev->rq_queue) << 9; | 598 | max_bio_size = queue_max_hw_sectors(device->rq_queue) << 9; |
593 | number = drbd_rs_number_requests(mdev); | 599 | number = drbd_rs_number_requests(device); |
594 | if (number == 0) | 600 | if (number == 0) |
595 | goto requeue; | 601 | goto requeue; |
596 | 602 | ||
597 | for (i = 0; i < number; i++) { | 603 | for (i = 0; i < number; i++) { |
598 | /* Stop generating RS requests, when half of the send buffer is filled */ | 604 | /* Stop generating RS requests, when half of the send buffer is filled */ |
599 | mutex_lock(&mdev->tconn->data.mutex); | 605 | mutex_lock(&first_peer_device(device)->connection->data.mutex); |
600 | if (mdev->tconn->data.socket) { | 606 | if (first_peer_device(device)->connection->data.socket) { |
601 | queued = mdev->tconn->data.socket->sk->sk_wmem_queued; | 607 | queued = first_peer_device(device)->connection->data.socket->sk->sk_wmem_queued; |
602 | sndbuf = mdev->tconn->data.socket->sk->sk_sndbuf; | 608 | sndbuf = first_peer_device(device)->connection->data.socket->sk->sk_sndbuf; |
603 | } else { | 609 | } else { |
604 | queued = 1; | 610 | queued = 1; |
605 | sndbuf = 0; | 611 | sndbuf = 0; |
606 | } | 612 | } |
607 | mutex_unlock(&mdev->tconn->data.mutex); | 613 | mutex_unlock(&first_peer_device(device)->connection->data.mutex); |
608 | if (queued > sndbuf / 2) | 614 | if (queued > sndbuf / 2) |
609 | goto requeue; | 615 | goto requeue; |
610 | 616 | ||
611 | next_sector: | 617 | next_sector: |
612 | size = BM_BLOCK_SIZE; | 618 | size = BM_BLOCK_SIZE; |
613 | bit = drbd_bm_find_next(mdev, mdev->bm_resync_fo); | 619 | bit = drbd_bm_find_next(device, device->bm_resync_fo); |
614 | 620 | ||
615 | if (bit == DRBD_END_OF_BITMAP) { | 621 | if (bit == DRBD_END_OF_BITMAP) { |
616 | mdev->bm_resync_fo = drbd_bm_bits(mdev); | 622 | device->bm_resync_fo = drbd_bm_bits(device); |
617 | put_ldev(mdev); | 623 | put_ldev(device); |
618 | return 0; | 624 | return 0; |
619 | } | 625 | } |
620 | 626 | ||
621 | sector = BM_BIT_TO_SECT(bit); | 627 | sector = BM_BIT_TO_SECT(bit); |
622 | 628 | ||
623 | if (drbd_rs_should_slow_down(mdev, sector) || | 629 | if (drbd_rs_should_slow_down(device, sector) || |
624 | drbd_try_rs_begin_io(mdev, sector)) { | 630 | drbd_try_rs_begin_io(device, sector)) { |
625 | mdev->bm_resync_fo = bit; | 631 | device->bm_resync_fo = bit; |
626 | goto requeue; | 632 | goto requeue; |
627 | } | 633 | } |
628 | mdev->bm_resync_fo = bit + 1; | 634 | device->bm_resync_fo = bit + 1; |
629 | 635 | ||
630 | if (unlikely(drbd_bm_test_bit(mdev, bit) == 0)) { | 636 | if (unlikely(drbd_bm_test_bit(device, bit) == 0)) { |
631 | drbd_rs_complete_io(mdev, sector); | 637 | drbd_rs_complete_io(device, sector); |
632 | goto next_sector; | 638 | goto next_sector; |
633 | } | 639 | } |
634 | 640 | ||
@@ -657,7 +663,7 @@ next_sector: | |||
657 | * obscure reason; ( b == 0 ) would get the out-of-band | 663 | * obscure reason; ( b == 0 ) would get the out-of-band |
658 | * only accidentally right because of the "oddly sized" | 664 | * only accidentally right because of the "oddly sized" |
659 | * adjustment below */ | 665 | * adjustment below */ |
660 | if (drbd_bm_test_bit(mdev, bit+1) != 1) | 666 | if (drbd_bm_test_bit(device, bit+1) != 1) |
661 | break; | 667 | break; |
662 | bit++; | 668 | bit++; |
663 | size += BM_BLOCK_SIZE; | 669 | size += BM_BLOCK_SIZE; |
@@ -668,20 +674,21 @@ next_sector: | |||
668 | /* if we merged some, | 674 | /* if we merged some, |
669 | * reset the offset to start the next drbd_bm_find_next from */ | 675 | * reset the offset to start the next drbd_bm_find_next from */ |
670 | if (size > BM_BLOCK_SIZE) | 676 | if (size > BM_BLOCK_SIZE) |
671 | mdev->bm_resync_fo = bit + 1; | 677 | device->bm_resync_fo = bit + 1; |
672 | #endif | 678 | #endif |
673 | 679 | ||
674 | /* adjust very last sectors, in case we are oddly sized */ | 680 | /* adjust very last sectors, in case we are oddly sized */ |
675 | if (sector + (size>>9) > capacity) | 681 | if (sector + (size>>9) > capacity) |
676 | size = (capacity-sector)<<9; | 682 | size = (capacity-sector)<<9; |
677 | if (mdev->tconn->agreed_pro_version >= 89 && mdev->tconn->csums_tfm) { | 683 | if (first_peer_device(device)->connection->agreed_pro_version >= 89 && |
678 | switch (read_for_csum(mdev, sector, size)) { | 684 | first_peer_device(device)->connection->csums_tfm) { |
685 | switch (read_for_csum(first_peer_device(device), sector, size)) { | ||
679 | case -EIO: /* Disk failure */ | 686 | case -EIO: /* Disk failure */ |
680 | put_ldev(mdev); | 687 | put_ldev(device); |
681 | return -EIO; | 688 | return -EIO; |
682 | case -EAGAIN: /* allocation failed, or ldev busy */ | 689 | case -EAGAIN: /* allocation failed, or ldev busy */ |
683 | drbd_rs_complete_io(mdev, sector); | 690 | drbd_rs_complete_io(device, sector); |
684 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); | 691 | device->bm_resync_fo = BM_SECT_TO_BIT(sector); |
685 | i = rollback_i; | 692 | i = rollback_i; |
686 | goto requeue; | 693 | goto requeue; |
687 | case 0: | 694 | case 0: |
@@ -693,50 +700,49 @@ next_sector: | |||
693 | } else { | 700 | } else { |
694 | int err; | 701 | int err; |
695 | 702 | ||
696 | inc_rs_pending(mdev); | 703 | inc_rs_pending(device); |
697 | err = drbd_send_drequest(mdev, P_RS_DATA_REQUEST, | 704 | err = drbd_send_drequest(first_peer_device(device), P_RS_DATA_REQUEST, |
698 | sector, size, ID_SYNCER); | 705 | sector, size, ID_SYNCER); |
699 | if (err) { | 706 | if (err) { |
700 | dev_err(DEV, "drbd_send_drequest() failed, aborting...\n"); | 707 | drbd_err(device, "drbd_send_drequest() failed, aborting...\n"); |
701 | dec_rs_pending(mdev); | 708 | dec_rs_pending(device); |
702 | put_ldev(mdev); | 709 | put_ldev(device); |
703 | return err; | 710 | return err; |
704 | } | 711 | } |
705 | } | 712 | } |
706 | } | 713 | } |
707 | 714 | ||
708 | if (mdev->bm_resync_fo >= drbd_bm_bits(mdev)) { | 715 | if (device->bm_resync_fo >= drbd_bm_bits(device)) { |
709 | /* last syncer _request_ was sent, | 716 | /* last syncer _request_ was sent, |
710 | * but the P_RS_DATA_REPLY not yet received. sync will end (and | 717 | * but the P_RS_DATA_REPLY not yet received. sync will end (and |
711 | * next sync group will resume), as soon as we receive the last | 718 | * next sync group will resume), as soon as we receive the last |
712 | * resync data block, and the last bit is cleared. | 719 | * resync data block, and the last bit is cleared. |
713 | * until then resync "work" is "inactive" ... | 720 | * until then resync "work" is "inactive" ... |
714 | */ | 721 | */ |
715 | put_ldev(mdev); | 722 | put_ldev(device); |
716 | return 0; | 723 | return 0; |
717 | } | 724 | } |
718 | 725 | ||
719 | requeue: | 726 | requeue: |
720 | mdev->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9)); | 727 | device->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9)); |
721 | mod_timer(&mdev->resync_timer, jiffies + SLEEP_TIME); | 728 | mod_timer(&device->resync_timer, jiffies + SLEEP_TIME); |
722 | put_ldev(mdev); | 729 | put_ldev(device); |
723 | return 0; | 730 | return 0; |
724 | } | 731 | } |
725 | 732 | ||
726 | static int w_make_ov_request(struct drbd_work *w, int cancel) | 733 | static int make_ov_request(struct drbd_device *device, int cancel) |
727 | { | 734 | { |
728 | struct drbd_conf *mdev = w->mdev; | ||
729 | int number, i, size; | 735 | int number, i, size; |
730 | sector_t sector; | 736 | sector_t sector; |
731 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); | 737 | const sector_t capacity = drbd_get_capacity(device->this_bdev); |
732 | bool stop_sector_reached = false; | 738 | bool stop_sector_reached = false; |
733 | 739 | ||
734 | if (unlikely(cancel)) | 740 | if (unlikely(cancel)) |
735 | return 1; | 741 | return 1; |
736 | 742 | ||
737 | number = drbd_rs_number_requests(mdev); | 743 | number = drbd_rs_number_requests(device); |
738 | 744 | ||
739 | sector = mdev->ov_position; | 745 | sector = device->ov_position; |
740 | for (i = 0; i < number; i++) { | 746 | for (i = 0; i < number; i++) { |
741 | if (sector >= capacity) | 747 | if (sector >= capacity) |
742 | return 1; | 748 | return 1; |
@@ -745,116 +751,121 @@ static int w_make_ov_request(struct drbd_work *w, int cancel) | |||
745 | * w_e_end_ov_reply(). | 751 | * w_e_end_ov_reply(). |
746 | * We need to send at least one request out. */ | 752 | * We need to send at least one request out. */ |
747 | stop_sector_reached = i > 0 | 753 | stop_sector_reached = i > 0 |
748 | && verify_can_do_stop_sector(mdev) | 754 | && verify_can_do_stop_sector(device) |
749 | && sector >= mdev->ov_stop_sector; | 755 | && sector >= device->ov_stop_sector; |
750 | if (stop_sector_reached) | 756 | if (stop_sector_reached) |
751 | break; | 757 | break; |
752 | 758 | ||
753 | size = BM_BLOCK_SIZE; | 759 | size = BM_BLOCK_SIZE; |
754 | 760 | ||
755 | if (drbd_rs_should_slow_down(mdev, sector) || | 761 | if (drbd_rs_should_slow_down(device, sector) || |
756 | drbd_try_rs_begin_io(mdev, sector)) { | 762 | drbd_try_rs_begin_io(device, sector)) { |
757 | mdev->ov_position = sector; | 763 | device->ov_position = sector; |
758 | goto requeue; | 764 | goto requeue; |
759 | } | 765 | } |
760 | 766 | ||
761 | if (sector + (size>>9) > capacity) | 767 | if (sector + (size>>9) > capacity) |
762 | size = (capacity-sector)<<9; | 768 | size = (capacity-sector)<<9; |
763 | 769 | ||
764 | inc_rs_pending(mdev); | 770 | inc_rs_pending(device); |
765 | if (drbd_send_ov_request(mdev, sector, size)) { | 771 | if (drbd_send_ov_request(first_peer_device(device), sector, size)) { |
766 | dec_rs_pending(mdev); | 772 | dec_rs_pending(device); |
767 | return 0; | 773 | return 0; |
768 | } | 774 | } |
769 | sector += BM_SECT_PER_BIT; | 775 | sector += BM_SECT_PER_BIT; |
770 | } | 776 | } |
771 | mdev->ov_position = sector; | 777 | device->ov_position = sector; |
772 | 778 | ||
773 | requeue: | 779 | requeue: |
774 | mdev->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9)); | 780 | device->rs_in_flight += (i << (BM_BLOCK_SHIFT - 9)); |
775 | if (i == 0 || !stop_sector_reached) | 781 | if (i == 0 || !stop_sector_reached) |
776 | mod_timer(&mdev->resync_timer, jiffies + SLEEP_TIME); | 782 | mod_timer(&device->resync_timer, jiffies + SLEEP_TIME); |
777 | return 1; | 783 | return 1; |
778 | } | 784 | } |
779 | 785 | ||
780 | int w_ov_finished(struct drbd_work *w, int cancel) | 786 | int w_ov_finished(struct drbd_work *w, int cancel) |
781 | { | 787 | { |
782 | struct drbd_conf *mdev = w->mdev; | 788 | struct drbd_device_work *dw = |
783 | kfree(w); | 789 | container_of(w, struct drbd_device_work, w); |
784 | ov_out_of_sync_print(mdev); | 790 | struct drbd_device *device = dw->device; |
785 | drbd_resync_finished(mdev); | 791 | kfree(dw); |
792 | ov_out_of_sync_print(device); | ||
793 | drbd_resync_finished(device); | ||
786 | 794 | ||
787 | return 0; | 795 | return 0; |
788 | } | 796 | } |
789 | 797 | ||
790 | static int w_resync_finished(struct drbd_work *w, int cancel) | 798 | static int w_resync_finished(struct drbd_work *w, int cancel) |
791 | { | 799 | { |
792 | struct drbd_conf *mdev = w->mdev; | 800 | struct drbd_device_work *dw = |
793 | kfree(w); | 801 | container_of(w, struct drbd_device_work, w); |
802 | struct drbd_device *device = dw->device; | ||
803 | kfree(dw); | ||
794 | 804 | ||
795 | drbd_resync_finished(mdev); | 805 | drbd_resync_finished(device); |
796 | 806 | ||
797 | return 0; | 807 | return 0; |
798 | } | 808 | } |
799 | 809 | ||
800 | static void ping_peer(struct drbd_conf *mdev) | 810 | static void ping_peer(struct drbd_device *device) |
801 | { | 811 | { |
802 | struct drbd_tconn *tconn = mdev->tconn; | 812 | struct drbd_connection *connection = first_peer_device(device)->connection; |
803 | 813 | ||
804 | clear_bit(GOT_PING_ACK, &tconn->flags); | 814 | clear_bit(GOT_PING_ACK, &connection->flags); |
805 | request_ping(tconn); | 815 | request_ping(connection); |
806 | wait_event(tconn->ping_wait, | 816 | wait_event(connection->ping_wait, |
807 | test_bit(GOT_PING_ACK, &tconn->flags) || mdev->state.conn < C_CONNECTED); | 817 | test_bit(GOT_PING_ACK, &connection->flags) || device->state.conn < C_CONNECTED); |
808 | } | 818 | } |
809 | 819 | ||
810 | int drbd_resync_finished(struct drbd_conf *mdev) | 820 | int drbd_resync_finished(struct drbd_device *device) |
811 | { | 821 | { |
812 | unsigned long db, dt, dbdt; | 822 | unsigned long db, dt, dbdt; |
813 | unsigned long n_oos; | 823 | unsigned long n_oos; |
814 | union drbd_state os, ns; | 824 | union drbd_state os, ns; |
815 | struct drbd_work *w; | 825 | struct drbd_device_work *dw; |
816 | char *khelper_cmd = NULL; | 826 | char *khelper_cmd = NULL; |
817 | int verify_done = 0; | 827 | int verify_done = 0; |
818 | 828 | ||
819 | /* Remove all elements from the resync LRU. Since future actions | 829 | /* Remove all elements from the resync LRU. Since future actions |
820 | * might set bits in the (main) bitmap, then the entries in the | 830 | * might set bits in the (main) bitmap, then the entries in the |
821 | * resync LRU would be wrong. */ | 831 | * resync LRU would be wrong. */ |
822 | if (drbd_rs_del_all(mdev)) { | 832 | if (drbd_rs_del_all(device)) { |
823 | /* In case this is not possible now, most probably because | 833 | /* In case this is not possible now, most probably because |
824 | * there are P_RS_DATA_REPLY Packets lingering on the worker's | 834 | * there are P_RS_DATA_REPLY Packets lingering on the worker's |
825 | * queue (or even the read operations for those packets | 835 | * queue (or even the read operations for those packets |
826 | * is not finished by now). Retry in 100ms. */ | 836 | * is not finished by now). Retry in 100ms. */ |
827 | 837 | ||
828 | schedule_timeout_interruptible(HZ / 10); | 838 | schedule_timeout_interruptible(HZ / 10); |
829 | w = kmalloc(sizeof(struct drbd_work), GFP_ATOMIC); | 839 | dw = kmalloc(sizeof(struct drbd_device_work), GFP_ATOMIC); |
830 | if (w) { | 840 | if (dw) { |
831 | w->cb = w_resync_finished; | 841 | dw->w.cb = w_resync_finished; |
832 | w->mdev = mdev; | 842 | dw->device = device; |
833 | drbd_queue_work(&mdev->tconn->sender_work, w); | 843 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
844 | &dw->w); | ||
834 | return 1; | 845 | return 1; |
835 | } | 846 | } |
836 | dev_err(DEV, "Warn failed to drbd_rs_del_all() and to kmalloc(w).\n"); | 847 | drbd_err(device, "Warn failed to drbd_rs_del_all() and to kmalloc(dw).\n"); |
837 | } | 848 | } |
838 | 849 | ||
839 | dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ; | 850 | dt = (jiffies - device->rs_start - device->rs_paused) / HZ; |
840 | if (dt <= 0) | 851 | if (dt <= 0) |
841 | dt = 1; | 852 | dt = 1; |
842 | 853 | ||
843 | db = mdev->rs_total; | 854 | db = device->rs_total; |
844 | /* adjust for verify start and stop sectors, respective reached position */ | 855 | /* adjust for verify start and stop sectors, respective reached position */ |
845 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) | 856 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
846 | db -= mdev->ov_left; | 857 | db -= device->ov_left; |
847 | 858 | ||
848 | dbdt = Bit2KB(db/dt); | 859 | dbdt = Bit2KB(db/dt); |
849 | mdev->rs_paused /= HZ; | 860 | device->rs_paused /= HZ; |
850 | 861 | ||
851 | if (!get_ldev(mdev)) | 862 | if (!get_ldev(device)) |
852 | goto out; | 863 | goto out; |
853 | 864 | ||
854 | ping_peer(mdev); | 865 | ping_peer(device); |
855 | 866 | ||
856 | spin_lock_irq(&mdev->tconn->req_lock); | 867 | spin_lock_irq(&device->resource->req_lock); |
857 | os = drbd_read_state(mdev); | 868 | os = drbd_read_state(device); |
858 | 869 | ||
859 | verify_done = (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T); | 870 | verify_done = (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T); |
860 | 871 | ||
@@ -866,41 +877,41 @@ int drbd_resync_finished(struct drbd_conf *mdev) | |||
866 | ns = os; | 877 | ns = os; |
867 | ns.conn = C_CONNECTED; | 878 | ns.conn = C_CONNECTED; |
868 | 879 | ||
869 | dev_info(DEV, "%s done (total %lu sec; paused %lu sec; %lu K/sec)\n", | 880 | drbd_info(device, "%s done (total %lu sec; paused %lu sec; %lu K/sec)\n", |
870 | verify_done ? "Online verify" : "Resync", | 881 | verify_done ? "Online verify" : "Resync", |
871 | dt + mdev->rs_paused, mdev->rs_paused, dbdt); | 882 | dt + device->rs_paused, device->rs_paused, dbdt); |
872 | 883 | ||
873 | n_oos = drbd_bm_total_weight(mdev); | 884 | n_oos = drbd_bm_total_weight(device); |
874 | 885 | ||
875 | if (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) { | 886 | if (os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) { |
876 | if (n_oos) { | 887 | if (n_oos) { |
877 | dev_alert(DEV, "Online verify found %lu %dk block out of sync!\n", | 888 | drbd_alert(device, "Online verify found %lu %dk block out of sync!\n", |
878 | n_oos, Bit2KB(1)); | 889 | n_oos, Bit2KB(1)); |
879 | khelper_cmd = "out-of-sync"; | 890 | khelper_cmd = "out-of-sync"; |
880 | } | 891 | } |
881 | } else { | 892 | } else { |
882 | D_ASSERT((n_oos - mdev->rs_failed) == 0); | 893 | D_ASSERT(device, (n_oos - device->rs_failed) == 0); |
883 | 894 | ||
884 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) | 895 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) |
885 | khelper_cmd = "after-resync-target"; | 896 | khelper_cmd = "after-resync-target"; |
886 | 897 | ||
887 | if (mdev->tconn->csums_tfm && mdev->rs_total) { | 898 | if (first_peer_device(device)->connection->csums_tfm && device->rs_total) { |
888 | const unsigned long s = mdev->rs_same_csum; | 899 | const unsigned long s = device->rs_same_csum; |
889 | const unsigned long t = mdev->rs_total; | 900 | const unsigned long t = device->rs_total; |
890 | const int ratio = | 901 | const int ratio = |
891 | (t == 0) ? 0 : | 902 | (t == 0) ? 0 : |
892 | (t < 100000) ? ((s*100)/t) : (s/(t/100)); | 903 | (t < 100000) ? ((s*100)/t) : (s/(t/100)); |
893 | dev_info(DEV, "%u %% had equal checksums, eliminated: %luK; " | 904 | drbd_info(device, "%u %% had equal checksums, eliminated: %luK; " |
894 | "transferred %luK total %luK\n", | 905 | "transferred %luK total %luK\n", |
895 | ratio, | 906 | ratio, |
896 | Bit2KB(mdev->rs_same_csum), | 907 | Bit2KB(device->rs_same_csum), |
897 | Bit2KB(mdev->rs_total - mdev->rs_same_csum), | 908 | Bit2KB(device->rs_total - device->rs_same_csum), |
898 | Bit2KB(mdev->rs_total)); | 909 | Bit2KB(device->rs_total)); |
899 | } | 910 | } |
900 | } | 911 | } |
901 | 912 | ||
902 | if (mdev->rs_failed) { | 913 | if (device->rs_failed) { |
903 | dev_info(DEV, " %lu failed blocks\n", mdev->rs_failed); | 914 | drbd_info(device, " %lu failed blocks\n", device->rs_failed); |
904 | 915 | ||
905 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) { | 916 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) { |
906 | ns.disk = D_INCONSISTENT; | 917 | ns.disk = D_INCONSISTENT; |
@@ -914,179 +925,181 @@ int drbd_resync_finished(struct drbd_conf *mdev) | |||
914 | ns.pdsk = D_UP_TO_DATE; | 925 | ns.pdsk = D_UP_TO_DATE; |
915 | 926 | ||
916 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) { | 927 | if (os.conn == C_SYNC_TARGET || os.conn == C_PAUSED_SYNC_T) { |
917 | if (mdev->p_uuid) { | 928 | if (device->p_uuid) { |
918 | int i; | 929 | int i; |
919 | for (i = UI_BITMAP ; i <= UI_HISTORY_END ; i++) | 930 | for (i = UI_BITMAP ; i <= UI_HISTORY_END ; i++) |
920 | _drbd_uuid_set(mdev, i, mdev->p_uuid[i]); | 931 | _drbd_uuid_set(device, i, device->p_uuid[i]); |
921 | drbd_uuid_set(mdev, UI_BITMAP, mdev->ldev->md.uuid[UI_CURRENT]); | 932 | drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_CURRENT]); |
922 | _drbd_uuid_set(mdev, UI_CURRENT, mdev->p_uuid[UI_CURRENT]); | 933 | _drbd_uuid_set(device, UI_CURRENT, device->p_uuid[UI_CURRENT]); |
923 | } else { | 934 | } else { |
924 | dev_err(DEV, "mdev->p_uuid is NULL! BUG\n"); | 935 | drbd_err(device, "device->p_uuid is NULL! BUG\n"); |
925 | } | 936 | } |
926 | } | 937 | } |
927 | 938 | ||
928 | if (!(os.conn == C_VERIFY_S || os.conn == C_VERIFY_T)) { | 939 | if (!(os.conn == C_VERIFY_S || os.conn == C_VERIFY_T)) { |
929 | /* for verify runs, we don't update uuids here, | 940 | /* for verify runs, we don't update uuids here, |
930 | * so there would be nothing to report. */ | 941 | * so there would be nothing to report. */ |
931 | drbd_uuid_set_bm(mdev, 0UL); | 942 | drbd_uuid_set_bm(device, 0UL); |
932 | drbd_print_uuids(mdev, "updated UUIDs"); | 943 | drbd_print_uuids(device, "updated UUIDs"); |
933 | if (mdev->p_uuid) { | 944 | if (device->p_uuid) { |
934 | /* Now the two UUID sets are equal, update what we | 945 | /* Now the two UUID sets are equal, update what we |
935 | * know of the peer. */ | 946 | * know of the peer. */ |
936 | int i; | 947 | int i; |
937 | for (i = UI_CURRENT ; i <= UI_HISTORY_END ; i++) | 948 | for (i = UI_CURRENT ; i <= UI_HISTORY_END ; i++) |
938 | mdev->p_uuid[i] = mdev->ldev->md.uuid[i]; | 949 | device->p_uuid[i] = device->ldev->md.uuid[i]; |
939 | } | 950 | } |
940 | } | 951 | } |
941 | } | 952 | } |
942 | 953 | ||
943 | _drbd_set_state(mdev, ns, CS_VERBOSE, NULL); | 954 | _drbd_set_state(device, ns, CS_VERBOSE, NULL); |
944 | out_unlock: | 955 | out_unlock: |
945 | spin_unlock_irq(&mdev->tconn->req_lock); | 956 | spin_unlock_irq(&device->resource->req_lock); |
946 | put_ldev(mdev); | 957 | put_ldev(device); |
947 | out: | 958 | out: |
948 | mdev->rs_total = 0; | 959 | device->rs_total = 0; |
949 | mdev->rs_failed = 0; | 960 | device->rs_failed = 0; |
950 | mdev->rs_paused = 0; | 961 | device->rs_paused = 0; |
951 | 962 | ||
952 | /* reset start sector, if we reached end of device */ | 963 | /* reset start sector, if we reached end of device */ |
953 | if (verify_done && mdev->ov_left == 0) | 964 | if (verify_done && device->ov_left == 0) |
954 | mdev->ov_start_sector = 0; | 965 | device->ov_start_sector = 0; |
955 | 966 | ||
956 | drbd_md_sync(mdev); | 967 | drbd_md_sync(device); |
957 | 968 | ||
958 | if (khelper_cmd) | 969 | if (khelper_cmd) |
959 | drbd_khelper(mdev, khelper_cmd); | 970 | drbd_khelper(device, khelper_cmd); |
960 | 971 | ||
961 | return 1; | 972 | return 1; |
962 | } | 973 | } |
963 | 974 | ||
964 | /* helper */ | 975 | /* helper */ |
965 | static void move_to_net_ee_or_free(struct drbd_conf *mdev, struct drbd_peer_request *peer_req) | 976 | static void move_to_net_ee_or_free(struct drbd_device *device, struct drbd_peer_request *peer_req) |
966 | { | 977 | { |
967 | if (drbd_peer_req_has_active_page(peer_req)) { | 978 | if (drbd_peer_req_has_active_page(peer_req)) { |
968 | /* This might happen if sendpage() has not finished */ | 979 | /* This might happen if sendpage() has not finished */ |
969 | int i = (peer_req->i.size + PAGE_SIZE -1) >> PAGE_SHIFT; | 980 | int i = (peer_req->i.size + PAGE_SIZE -1) >> PAGE_SHIFT; |
970 | atomic_add(i, &mdev->pp_in_use_by_net); | 981 | atomic_add(i, &device->pp_in_use_by_net); |
971 | atomic_sub(i, &mdev->pp_in_use); | 982 | atomic_sub(i, &device->pp_in_use); |
972 | spin_lock_irq(&mdev->tconn->req_lock); | 983 | spin_lock_irq(&device->resource->req_lock); |
973 | list_add_tail(&peer_req->w.list, &mdev->net_ee); | 984 | list_add_tail(&peer_req->w.list, &device->net_ee); |
974 | spin_unlock_irq(&mdev->tconn->req_lock); | 985 | spin_unlock_irq(&device->resource->req_lock); |
975 | wake_up(&drbd_pp_wait); | 986 | wake_up(&drbd_pp_wait); |
976 | } else | 987 | } else |
977 | drbd_free_peer_req(mdev, peer_req); | 988 | drbd_free_peer_req(device, peer_req); |
978 | } | 989 | } |
979 | 990 | ||
980 | /** | 991 | /** |
981 | * w_e_end_data_req() - Worker callback, to send a P_DATA_REPLY packet in response to a P_DATA_REQUEST | 992 | * w_e_end_data_req() - Worker callback, to send a P_DATA_REPLY packet in response to a P_DATA_REQUEST |
982 | * @mdev: DRBD device. | 993 | * @device: DRBD device. |
983 | * @w: work object. | 994 | * @w: work object. |
984 | * @cancel: The connection will be closed anyways | 995 | * @cancel: The connection will be closed anyways |
985 | */ | 996 | */ |
986 | int w_e_end_data_req(struct drbd_work *w, int cancel) | 997 | int w_e_end_data_req(struct drbd_work *w, int cancel) |
987 | { | 998 | { |
988 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 999 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
989 | struct drbd_conf *mdev = w->mdev; | 1000 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1001 | struct drbd_device *device = peer_device->device; | ||
990 | int err; | 1002 | int err; |
991 | 1003 | ||
992 | if (unlikely(cancel)) { | 1004 | if (unlikely(cancel)) { |
993 | drbd_free_peer_req(mdev, peer_req); | 1005 | drbd_free_peer_req(device, peer_req); |
994 | dec_unacked(mdev); | 1006 | dec_unacked(device); |
995 | return 0; | 1007 | return 0; |
996 | } | 1008 | } |
997 | 1009 | ||
998 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { | 1010 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
999 | err = drbd_send_block(mdev, P_DATA_REPLY, peer_req); | 1011 | err = drbd_send_block(peer_device, P_DATA_REPLY, peer_req); |
1000 | } else { | 1012 | } else { |
1001 | if (__ratelimit(&drbd_ratelimit_state)) | 1013 | if (__ratelimit(&drbd_ratelimit_state)) |
1002 | dev_err(DEV, "Sending NegDReply. sector=%llus.\n", | 1014 | drbd_err(device, "Sending NegDReply. sector=%llus.\n", |
1003 | (unsigned long long)peer_req->i.sector); | 1015 | (unsigned long long)peer_req->i.sector); |
1004 | 1016 | ||
1005 | err = drbd_send_ack(mdev, P_NEG_DREPLY, peer_req); | 1017 | err = drbd_send_ack(peer_device, P_NEG_DREPLY, peer_req); |
1006 | } | 1018 | } |
1007 | 1019 | ||
1008 | dec_unacked(mdev); | 1020 | dec_unacked(device); |
1009 | 1021 | ||
1010 | move_to_net_ee_or_free(mdev, peer_req); | 1022 | move_to_net_ee_or_free(device, peer_req); |
1011 | 1023 | ||
1012 | if (unlikely(err)) | 1024 | if (unlikely(err)) |
1013 | dev_err(DEV, "drbd_send_block() failed\n"); | 1025 | drbd_err(device, "drbd_send_block() failed\n"); |
1014 | return err; | 1026 | return err; |
1015 | } | 1027 | } |
1016 | 1028 | ||
1017 | /** | 1029 | /** |
1018 | * w_e_end_rsdata_req() - Worker callback to send a P_RS_DATA_REPLY packet in response to a P_RS_DATA_REQUEST | 1030 | * w_e_end_rsdata_req() - Worker callback to send a P_RS_DATA_REPLY packet in response to a P_RS_DATA_REQUEST |
1019 | * @mdev: DRBD device. | ||
1020 | * @w: work object. | 1031 | * @w: work object. |
1021 | * @cancel: The connection will be closed anyways | 1032 | * @cancel: The connection will be closed anyways |
1022 | */ | 1033 | */ |
1023 | int w_e_end_rsdata_req(struct drbd_work *w, int cancel) | 1034 | int w_e_end_rsdata_req(struct drbd_work *w, int cancel) |
1024 | { | 1035 | { |
1025 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 1036 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
1026 | struct drbd_conf *mdev = w->mdev; | 1037 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1038 | struct drbd_device *device = peer_device->device; | ||
1027 | int err; | 1039 | int err; |
1028 | 1040 | ||
1029 | if (unlikely(cancel)) { | 1041 | if (unlikely(cancel)) { |
1030 | drbd_free_peer_req(mdev, peer_req); | 1042 | drbd_free_peer_req(device, peer_req); |
1031 | dec_unacked(mdev); | 1043 | dec_unacked(device); |
1032 | return 0; | 1044 | return 0; |
1033 | } | 1045 | } |
1034 | 1046 | ||
1035 | if (get_ldev_if_state(mdev, D_FAILED)) { | 1047 | if (get_ldev_if_state(device, D_FAILED)) { |
1036 | drbd_rs_complete_io(mdev, peer_req->i.sector); | 1048 | drbd_rs_complete_io(device, peer_req->i.sector); |
1037 | put_ldev(mdev); | 1049 | put_ldev(device); |
1038 | } | 1050 | } |
1039 | 1051 | ||
1040 | if (mdev->state.conn == C_AHEAD) { | 1052 | if (device->state.conn == C_AHEAD) { |
1041 | err = drbd_send_ack(mdev, P_RS_CANCEL, peer_req); | 1053 | err = drbd_send_ack(peer_device, P_RS_CANCEL, peer_req); |
1042 | } else if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { | 1054 | } else if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
1043 | if (likely(mdev->state.pdsk >= D_INCONSISTENT)) { | 1055 | if (likely(device->state.pdsk >= D_INCONSISTENT)) { |
1044 | inc_rs_pending(mdev); | 1056 | inc_rs_pending(device); |
1045 | err = drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); | 1057 | err = drbd_send_block(peer_device, P_RS_DATA_REPLY, peer_req); |
1046 | } else { | 1058 | } else { |
1047 | if (__ratelimit(&drbd_ratelimit_state)) | 1059 | if (__ratelimit(&drbd_ratelimit_state)) |
1048 | dev_err(DEV, "Not sending RSDataReply, " | 1060 | drbd_err(device, "Not sending RSDataReply, " |
1049 | "partner DISKLESS!\n"); | 1061 | "partner DISKLESS!\n"); |
1050 | err = 0; | 1062 | err = 0; |
1051 | } | 1063 | } |
1052 | } else { | 1064 | } else { |
1053 | if (__ratelimit(&drbd_ratelimit_state)) | 1065 | if (__ratelimit(&drbd_ratelimit_state)) |
1054 | dev_err(DEV, "Sending NegRSDReply. sector %llus.\n", | 1066 | drbd_err(device, "Sending NegRSDReply. sector %llus.\n", |
1055 | (unsigned long long)peer_req->i.sector); | 1067 | (unsigned long long)peer_req->i.sector); |
1056 | 1068 | ||
1057 | err = drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); | 1069 | err = drbd_send_ack(peer_device, P_NEG_RS_DREPLY, peer_req); |
1058 | 1070 | ||
1059 | /* update resync data with failure */ | 1071 | /* update resync data with failure */ |
1060 | drbd_rs_failed_io(mdev, peer_req->i.sector, peer_req->i.size); | 1072 | drbd_rs_failed_io(device, peer_req->i.sector, peer_req->i.size); |
1061 | } | 1073 | } |
1062 | 1074 | ||
1063 | dec_unacked(mdev); | 1075 | dec_unacked(device); |
1064 | 1076 | ||
1065 | move_to_net_ee_or_free(mdev, peer_req); | 1077 | move_to_net_ee_or_free(device, peer_req); |
1066 | 1078 | ||
1067 | if (unlikely(err)) | 1079 | if (unlikely(err)) |
1068 | dev_err(DEV, "drbd_send_block() failed\n"); | 1080 | drbd_err(device, "drbd_send_block() failed\n"); |
1069 | return err; | 1081 | return err; |
1070 | } | 1082 | } |
1071 | 1083 | ||
1072 | int w_e_end_csum_rs_req(struct drbd_work *w, int cancel) | 1084 | int w_e_end_csum_rs_req(struct drbd_work *w, int cancel) |
1073 | { | 1085 | { |
1074 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 1086 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
1075 | struct drbd_conf *mdev = w->mdev; | 1087 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1088 | struct drbd_device *device = peer_device->device; | ||
1076 | struct digest_info *di; | 1089 | struct digest_info *di; |
1077 | int digest_size; | 1090 | int digest_size; |
1078 | void *digest = NULL; | 1091 | void *digest = NULL; |
1079 | int err, eq = 0; | 1092 | int err, eq = 0; |
1080 | 1093 | ||
1081 | if (unlikely(cancel)) { | 1094 | if (unlikely(cancel)) { |
1082 | drbd_free_peer_req(mdev, peer_req); | 1095 | drbd_free_peer_req(device, peer_req); |
1083 | dec_unacked(mdev); | 1096 | dec_unacked(device); |
1084 | return 0; | 1097 | return 0; |
1085 | } | 1098 | } |
1086 | 1099 | ||
1087 | if (get_ldev(mdev)) { | 1100 | if (get_ldev(device)) { |
1088 | drbd_rs_complete_io(mdev, peer_req->i.sector); | 1101 | drbd_rs_complete_io(device, peer_req->i.sector); |
1089 | put_ldev(mdev); | 1102 | put_ldev(device); |
1090 | } | 1103 | } |
1091 | 1104 | ||
1092 | di = peer_req->digest; | 1105 | di = peer_req->digest; |
@@ -1095,47 +1108,48 @@ int w_e_end_csum_rs_req(struct drbd_work *w, int cancel) | |||
1095 | /* quick hack to try to avoid a race against reconfiguration. | 1108 | /* quick hack to try to avoid a race against reconfiguration. |
1096 | * a real fix would be much more involved, | 1109 | * a real fix would be much more involved, |
1097 | * introducing more locking mechanisms */ | 1110 | * introducing more locking mechanisms */ |
1098 | if (mdev->tconn->csums_tfm) { | 1111 | if (peer_device->connection->csums_tfm) { |
1099 | digest_size = crypto_hash_digestsize(mdev->tconn->csums_tfm); | 1112 | digest_size = crypto_hash_digestsize(peer_device->connection->csums_tfm); |
1100 | D_ASSERT(digest_size == di->digest_size); | 1113 | D_ASSERT(device, digest_size == di->digest_size); |
1101 | digest = kmalloc(digest_size, GFP_NOIO); | 1114 | digest = kmalloc(digest_size, GFP_NOIO); |
1102 | } | 1115 | } |
1103 | if (digest) { | 1116 | if (digest) { |
1104 | drbd_csum_ee(mdev, mdev->tconn->csums_tfm, peer_req, digest); | 1117 | drbd_csum_ee(peer_device->connection->csums_tfm, peer_req, digest); |
1105 | eq = !memcmp(digest, di->digest, digest_size); | 1118 | eq = !memcmp(digest, di->digest, digest_size); |
1106 | kfree(digest); | 1119 | kfree(digest); |
1107 | } | 1120 | } |
1108 | 1121 | ||
1109 | if (eq) { | 1122 | if (eq) { |
1110 | drbd_set_in_sync(mdev, peer_req->i.sector, peer_req->i.size); | 1123 | drbd_set_in_sync(device, peer_req->i.sector, peer_req->i.size); |
1111 | /* rs_same_csums unit is BM_BLOCK_SIZE */ | 1124 | /* rs_same_csums unit is BM_BLOCK_SIZE */ |
1112 | mdev->rs_same_csum += peer_req->i.size >> BM_BLOCK_SHIFT; | 1125 | device->rs_same_csum += peer_req->i.size >> BM_BLOCK_SHIFT; |
1113 | err = drbd_send_ack(mdev, P_RS_IS_IN_SYNC, peer_req); | 1126 | err = drbd_send_ack(peer_device, P_RS_IS_IN_SYNC, peer_req); |
1114 | } else { | 1127 | } else { |
1115 | inc_rs_pending(mdev); | 1128 | inc_rs_pending(device); |
1116 | peer_req->block_id = ID_SYNCER; /* By setting block_id, digest pointer becomes invalid! */ | 1129 | peer_req->block_id = ID_SYNCER; /* By setting block_id, digest pointer becomes invalid! */ |
1117 | peer_req->flags &= ~EE_HAS_DIGEST; /* This peer request no longer has a digest pointer */ | 1130 | peer_req->flags &= ~EE_HAS_DIGEST; /* This peer request no longer has a digest pointer */ |
1118 | kfree(di); | 1131 | kfree(di); |
1119 | err = drbd_send_block(mdev, P_RS_DATA_REPLY, peer_req); | 1132 | err = drbd_send_block(peer_device, P_RS_DATA_REPLY, peer_req); |
1120 | } | 1133 | } |
1121 | } else { | 1134 | } else { |
1122 | err = drbd_send_ack(mdev, P_NEG_RS_DREPLY, peer_req); | 1135 | err = drbd_send_ack(peer_device, P_NEG_RS_DREPLY, peer_req); |
1123 | if (__ratelimit(&drbd_ratelimit_state)) | 1136 | if (__ratelimit(&drbd_ratelimit_state)) |
1124 | dev_err(DEV, "Sending NegDReply. I guess it gets messy.\n"); | 1137 | drbd_err(device, "Sending NegDReply. I guess it gets messy.\n"); |
1125 | } | 1138 | } |
1126 | 1139 | ||
1127 | dec_unacked(mdev); | 1140 | dec_unacked(device); |
1128 | move_to_net_ee_or_free(mdev, peer_req); | 1141 | move_to_net_ee_or_free(device, peer_req); |
1129 | 1142 | ||
1130 | if (unlikely(err)) | 1143 | if (unlikely(err)) |
1131 | dev_err(DEV, "drbd_send_block/ack() failed\n"); | 1144 | drbd_err(device, "drbd_send_block/ack() failed\n"); |
1132 | return err; | 1145 | return err; |
1133 | } | 1146 | } |
1134 | 1147 | ||
1135 | int w_e_end_ov_req(struct drbd_work *w, int cancel) | 1148 | int w_e_end_ov_req(struct drbd_work *w, int cancel) |
1136 | { | 1149 | { |
1137 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 1150 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
1138 | struct drbd_conf *mdev = w->mdev; | 1151 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1152 | struct drbd_device *device = peer_device->device; | ||
1139 | sector_t sector = peer_req->i.sector; | 1153 | sector_t sector = peer_req->i.sector; |
1140 | unsigned int size = peer_req->i.size; | 1154 | unsigned int size = peer_req->i.size; |
1141 | int digest_size; | 1155 | int digest_size; |
@@ -1145,7 +1159,7 @@ int w_e_end_ov_req(struct drbd_work *w, int cancel) | |||
1145 | if (unlikely(cancel)) | 1159 | if (unlikely(cancel)) |
1146 | goto out; | 1160 | goto out; |
1147 | 1161 | ||
1148 | digest_size = crypto_hash_digestsize(mdev->tconn->verify_tfm); | 1162 | digest_size = crypto_hash_digestsize(peer_device->connection->verify_tfm); |
1149 | digest = kmalloc(digest_size, GFP_NOIO); | 1163 | digest = kmalloc(digest_size, GFP_NOIO); |
1150 | if (!digest) { | 1164 | if (!digest) { |
1151 | err = 1; /* terminate the connection in case the allocation failed */ | 1165 | err = 1; /* terminate the connection in case the allocation failed */ |
@@ -1153,7 +1167,7 @@ int w_e_end_ov_req(struct drbd_work *w, int cancel) | |||
1153 | } | 1167 | } |
1154 | 1168 | ||
1155 | if (likely(!(peer_req->flags & EE_WAS_ERROR))) | 1169 | if (likely(!(peer_req->flags & EE_WAS_ERROR))) |
1156 | drbd_csum_ee(mdev, mdev->tconn->verify_tfm, peer_req, digest); | 1170 | drbd_csum_ee(peer_device->connection->verify_tfm, peer_req, digest); |
1157 | else | 1171 | else |
1158 | memset(digest, 0, digest_size); | 1172 | memset(digest, 0, digest_size); |
1159 | 1173 | ||
@@ -1162,36 +1176,37 @@ int w_e_end_ov_req(struct drbd_work *w, int cancel) | |||
1162 | * some distributed deadlock, if the other side blocks on | 1176 | * some distributed deadlock, if the other side blocks on |
1163 | * congestion as well, because our receiver blocks in | 1177 | * congestion as well, because our receiver blocks in |
1164 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ | 1178 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ |
1165 | drbd_free_peer_req(mdev, peer_req); | 1179 | drbd_free_peer_req(device, peer_req); |
1166 | peer_req = NULL; | 1180 | peer_req = NULL; |
1167 | inc_rs_pending(mdev); | 1181 | inc_rs_pending(device); |
1168 | err = drbd_send_drequest_csum(mdev, sector, size, digest, digest_size, P_OV_REPLY); | 1182 | err = drbd_send_drequest_csum(peer_device, sector, size, digest, digest_size, P_OV_REPLY); |
1169 | if (err) | 1183 | if (err) |
1170 | dec_rs_pending(mdev); | 1184 | dec_rs_pending(device); |
1171 | kfree(digest); | 1185 | kfree(digest); |
1172 | 1186 | ||
1173 | out: | 1187 | out: |
1174 | if (peer_req) | 1188 | if (peer_req) |
1175 | drbd_free_peer_req(mdev, peer_req); | 1189 | drbd_free_peer_req(device, peer_req); |
1176 | dec_unacked(mdev); | 1190 | dec_unacked(device); |
1177 | return err; | 1191 | return err; |
1178 | } | 1192 | } |
1179 | 1193 | ||
1180 | void drbd_ov_out_of_sync_found(struct drbd_conf *mdev, sector_t sector, int size) | 1194 | void drbd_ov_out_of_sync_found(struct drbd_device *device, sector_t sector, int size) |
1181 | { | 1195 | { |
1182 | if (mdev->ov_last_oos_start + mdev->ov_last_oos_size == sector) { | 1196 | if (device->ov_last_oos_start + device->ov_last_oos_size == sector) { |
1183 | mdev->ov_last_oos_size += size>>9; | 1197 | device->ov_last_oos_size += size>>9; |
1184 | } else { | 1198 | } else { |
1185 | mdev->ov_last_oos_start = sector; | 1199 | device->ov_last_oos_start = sector; |
1186 | mdev->ov_last_oos_size = size>>9; | 1200 | device->ov_last_oos_size = size>>9; |
1187 | } | 1201 | } |
1188 | drbd_set_out_of_sync(mdev, sector, size); | 1202 | drbd_set_out_of_sync(device, sector, size); |
1189 | } | 1203 | } |
1190 | 1204 | ||
1191 | int w_e_end_ov_reply(struct drbd_work *w, int cancel) | 1205 | int w_e_end_ov_reply(struct drbd_work *w, int cancel) |
1192 | { | 1206 | { |
1193 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); | 1207 | struct drbd_peer_request *peer_req = container_of(w, struct drbd_peer_request, w); |
1194 | struct drbd_conf *mdev = w->mdev; | 1208 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
1209 | struct drbd_device *device = peer_device->device; | ||
1195 | struct digest_info *di; | 1210 | struct digest_info *di; |
1196 | void *digest; | 1211 | void *digest; |
1197 | sector_t sector = peer_req->i.sector; | 1212 | sector_t sector = peer_req->i.sector; |
@@ -1201,27 +1216,27 @@ int w_e_end_ov_reply(struct drbd_work *w, int cancel) | |||
1201 | bool stop_sector_reached = false; | 1216 | bool stop_sector_reached = false; |
1202 | 1217 | ||
1203 | if (unlikely(cancel)) { | 1218 | if (unlikely(cancel)) { |
1204 | drbd_free_peer_req(mdev, peer_req); | 1219 | drbd_free_peer_req(device, peer_req); |
1205 | dec_unacked(mdev); | 1220 | dec_unacked(device); |
1206 | return 0; | 1221 | return 0; |
1207 | } | 1222 | } |
1208 | 1223 | ||
1209 | /* after "cancel", because after drbd_disconnect/drbd_rs_cancel_all | 1224 | /* after "cancel", because after drbd_disconnect/drbd_rs_cancel_all |
1210 | * the resync lru has been cleaned up already */ | 1225 | * the resync lru has been cleaned up already */ |
1211 | if (get_ldev(mdev)) { | 1226 | if (get_ldev(device)) { |
1212 | drbd_rs_complete_io(mdev, peer_req->i.sector); | 1227 | drbd_rs_complete_io(device, peer_req->i.sector); |
1213 | put_ldev(mdev); | 1228 | put_ldev(device); |
1214 | } | 1229 | } |
1215 | 1230 | ||
1216 | di = peer_req->digest; | 1231 | di = peer_req->digest; |
1217 | 1232 | ||
1218 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { | 1233 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
1219 | digest_size = crypto_hash_digestsize(mdev->tconn->verify_tfm); | 1234 | digest_size = crypto_hash_digestsize(peer_device->connection->verify_tfm); |
1220 | digest = kmalloc(digest_size, GFP_NOIO); | 1235 | digest = kmalloc(digest_size, GFP_NOIO); |
1221 | if (digest) { | 1236 | if (digest) { |
1222 | drbd_csum_ee(mdev, mdev->tconn->verify_tfm, peer_req, digest); | 1237 | drbd_csum_ee(peer_device->connection->verify_tfm, peer_req, digest); |
1223 | 1238 | ||
1224 | D_ASSERT(digest_size == di->digest_size); | 1239 | D_ASSERT(device, digest_size == di->digest_size); |
1225 | eq = !memcmp(digest, di->digest, digest_size); | 1240 | eq = !memcmp(digest, di->digest, digest_size); |
1226 | kfree(digest); | 1241 | kfree(digest); |
1227 | } | 1242 | } |
@@ -1232,102 +1247,95 @@ int w_e_end_ov_reply(struct drbd_work *w, int cancel) | |||
1232 | * some distributed deadlock, if the other side blocks on | 1247 | * some distributed deadlock, if the other side blocks on |
1233 | * congestion as well, because our receiver blocks in | 1248 | * congestion as well, because our receiver blocks in |
1234 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ | 1249 | * drbd_alloc_pages due to pp_in_use > max_buffers. */ |
1235 | drbd_free_peer_req(mdev, peer_req); | 1250 | drbd_free_peer_req(device, peer_req); |
1236 | if (!eq) | 1251 | if (!eq) |
1237 | drbd_ov_out_of_sync_found(mdev, sector, size); | 1252 | drbd_ov_out_of_sync_found(device, sector, size); |
1238 | else | 1253 | else |
1239 | ov_out_of_sync_print(mdev); | 1254 | ov_out_of_sync_print(device); |
1240 | 1255 | ||
1241 | err = drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, | 1256 | err = drbd_send_ack_ex(peer_device, P_OV_RESULT, sector, size, |
1242 | eq ? ID_IN_SYNC : ID_OUT_OF_SYNC); | 1257 | eq ? ID_IN_SYNC : ID_OUT_OF_SYNC); |
1243 | 1258 | ||
1244 | dec_unacked(mdev); | 1259 | dec_unacked(device); |
1245 | 1260 | ||
1246 | --mdev->ov_left; | 1261 | --device->ov_left; |
1247 | 1262 | ||
1248 | /* let's advance progress step marks only for every other megabyte */ | 1263 | /* let's advance progress step marks only for every other megabyte */ |
1249 | if ((mdev->ov_left & 0x200) == 0x200) | 1264 | if ((device->ov_left & 0x200) == 0x200) |
1250 | drbd_advance_rs_marks(mdev, mdev->ov_left); | 1265 | drbd_advance_rs_marks(device, device->ov_left); |
1251 | 1266 | ||
1252 | stop_sector_reached = verify_can_do_stop_sector(mdev) && | 1267 | stop_sector_reached = verify_can_do_stop_sector(device) && |
1253 | (sector + (size>>9)) >= mdev->ov_stop_sector; | 1268 | (sector + (size>>9)) >= device->ov_stop_sector; |
1254 | 1269 | ||
1255 | if (mdev->ov_left == 0 || stop_sector_reached) { | 1270 | if (device->ov_left == 0 || stop_sector_reached) { |
1256 | ov_out_of_sync_print(mdev); | 1271 | ov_out_of_sync_print(device); |
1257 | drbd_resync_finished(mdev); | 1272 | drbd_resync_finished(device); |
1258 | } | 1273 | } |
1259 | 1274 | ||
1260 | return err; | 1275 | return err; |
1261 | } | 1276 | } |
1262 | 1277 | ||
1263 | int w_prev_work_done(struct drbd_work *w, int cancel) | ||
1264 | { | ||
1265 | struct drbd_wq_barrier *b = container_of(w, struct drbd_wq_barrier, w); | ||
1266 | |||
1267 | complete(&b->done); | ||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | /* FIXME | 1278 | /* FIXME |
1272 | * We need to track the number of pending barrier acks, | 1279 | * We need to track the number of pending barrier acks, |
1273 | * and to be able to wait for them. | 1280 | * and to be able to wait for them. |
1274 | * See also comment in drbd_adm_attach before drbd_suspend_io. | 1281 | * See also comment in drbd_adm_attach before drbd_suspend_io. |
1275 | */ | 1282 | */ |
1276 | int drbd_send_barrier(struct drbd_tconn *tconn) | 1283 | static int drbd_send_barrier(struct drbd_connection *connection) |
1277 | { | 1284 | { |
1278 | struct p_barrier *p; | 1285 | struct p_barrier *p; |
1279 | struct drbd_socket *sock; | 1286 | struct drbd_socket *sock; |
1280 | 1287 | ||
1281 | sock = &tconn->data; | 1288 | sock = &connection->data; |
1282 | p = conn_prepare_command(tconn, sock); | 1289 | p = conn_prepare_command(connection, sock); |
1283 | if (!p) | 1290 | if (!p) |
1284 | return -EIO; | 1291 | return -EIO; |
1285 | p->barrier = tconn->send.current_epoch_nr; | 1292 | p->barrier = connection->send.current_epoch_nr; |
1286 | p->pad = 0; | 1293 | p->pad = 0; |
1287 | tconn->send.current_epoch_writes = 0; | 1294 | connection->send.current_epoch_writes = 0; |
1288 | 1295 | ||
1289 | return conn_send_command(tconn, sock, P_BARRIER, sizeof(*p), NULL, 0); | 1296 | return conn_send_command(connection, sock, P_BARRIER, sizeof(*p), NULL, 0); |
1290 | } | 1297 | } |
1291 | 1298 | ||
1292 | int w_send_write_hint(struct drbd_work *w, int cancel) | 1299 | int w_send_write_hint(struct drbd_work *w, int cancel) |
1293 | { | 1300 | { |
1294 | struct drbd_conf *mdev = w->mdev; | 1301 | struct drbd_device *device = |
1302 | container_of(w, struct drbd_device, unplug_work); | ||
1295 | struct drbd_socket *sock; | 1303 | struct drbd_socket *sock; |
1296 | 1304 | ||
1297 | if (cancel) | 1305 | if (cancel) |
1298 | return 0; | 1306 | return 0; |
1299 | sock = &mdev->tconn->data; | 1307 | sock = &first_peer_device(device)->connection->data; |
1300 | if (!drbd_prepare_command(mdev, sock)) | 1308 | if (!drbd_prepare_command(first_peer_device(device), sock)) |
1301 | return -EIO; | 1309 | return -EIO; |
1302 | return drbd_send_command(mdev, sock, P_UNPLUG_REMOTE, 0, NULL, 0); | 1310 | return drbd_send_command(first_peer_device(device), sock, P_UNPLUG_REMOTE, 0, NULL, 0); |
1303 | } | 1311 | } |
1304 | 1312 | ||
1305 | static void re_init_if_first_write(struct drbd_tconn *tconn, unsigned int epoch) | 1313 | static void re_init_if_first_write(struct drbd_connection *connection, unsigned int epoch) |
1306 | { | 1314 | { |
1307 | if (!tconn->send.seen_any_write_yet) { | 1315 | if (!connection->send.seen_any_write_yet) { |
1308 | tconn->send.seen_any_write_yet = true; | 1316 | connection->send.seen_any_write_yet = true; |
1309 | tconn->send.current_epoch_nr = epoch; | 1317 | connection->send.current_epoch_nr = epoch; |
1310 | tconn->send.current_epoch_writes = 0; | 1318 | connection->send.current_epoch_writes = 0; |
1311 | } | 1319 | } |
1312 | } | 1320 | } |
1313 | 1321 | ||
1314 | static void maybe_send_barrier(struct drbd_tconn *tconn, unsigned int epoch) | 1322 | static void maybe_send_barrier(struct drbd_connection *connection, unsigned int epoch) |
1315 | { | 1323 | { |
1316 | /* re-init if first write on this connection */ | 1324 | /* re-init if first write on this connection */ |
1317 | if (!tconn->send.seen_any_write_yet) | 1325 | if (!connection->send.seen_any_write_yet) |
1318 | return; | 1326 | return; |
1319 | if (tconn->send.current_epoch_nr != epoch) { | 1327 | if (connection->send.current_epoch_nr != epoch) { |
1320 | if (tconn->send.current_epoch_writes) | 1328 | if (connection->send.current_epoch_writes) |
1321 | drbd_send_barrier(tconn); | 1329 | drbd_send_barrier(connection); |
1322 | tconn->send.current_epoch_nr = epoch; | 1330 | connection->send.current_epoch_nr = epoch; |
1323 | } | 1331 | } |
1324 | } | 1332 | } |
1325 | 1333 | ||
1326 | int w_send_out_of_sync(struct drbd_work *w, int cancel) | 1334 | int w_send_out_of_sync(struct drbd_work *w, int cancel) |
1327 | { | 1335 | { |
1328 | struct drbd_request *req = container_of(w, struct drbd_request, w); | 1336 | struct drbd_request *req = container_of(w, struct drbd_request, w); |
1329 | struct drbd_conf *mdev = w->mdev; | 1337 | struct drbd_device *device = req->device; |
1330 | struct drbd_tconn *tconn = mdev->tconn; | 1338 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1331 | int err; | 1339 | int err; |
1332 | 1340 | ||
1333 | if (unlikely(cancel)) { | 1341 | if (unlikely(cancel)) { |
@@ -1335,13 +1343,13 @@ int w_send_out_of_sync(struct drbd_work *w, int cancel) | |||
1335 | return 0; | 1343 | return 0; |
1336 | } | 1344 | } |
1337 | 1345 | ||
1338 | /* this time, no tconn->send.current_epoch_writes++; | 1346 | /* this time, no connection->send.current_epoch_writes++; |
1339 | * If it was sent, it was the closing barrier for the last | 1347 | * If it was sent, it was the closing barrier for the last |
1340 | * replicated epoch, before we went into AHEAD mode. | 1348 | * replicated epoch, before we went into AHEAD mode. |
1341 | * No more barriers will be sent, until we leave AHEAD mode again. */ | 1349 | * No more barriers will be sent, until we leave AHEAD mode again. */ |
1342 | maybe_send_barrier(tconn, req->epoch); | 1350 | maybe_send_barrier(connection, req->epoch); |
1343 | 1351 | ||
1344 | err = drbd_send_out_of_sync(mdev, req); | 1352 | err = drbd_send_out_of_sync(first_peer_device(device), req); |
1345 | req_mod(req, OOS_HANDED_TO_NETWORK); | 1353 | req_mod(req, OOS_HANDED_TO_NETWORK); |
1346 | 1354 | ||
1347 | return err; | 1355 | return err; |
@@ -1349,15 +1357,14 @@ int w_send_out_of_sync(struct drbd_work *w, int cancel) | |||
1349 | 1357 | ||
1350 | /** | 1358 | /** |
1351 | * w_send_dblock() - Worker callback to send a P_DATA packet in order to mirror a write request | 1359 | * w_send_dblock() - Worker callback to send a P_DATA packet in order to mirror a write request |
1352 | * @mdev: DRBD device. | ||
1353 | * @w: work object. | 1360 | * @w: work object. |
1354 | * @cancel: The connection will be closed anyways | 1361 | * @cancel: The connection will be closed anyways |
1355 | */ | 1362 | */ |
1356 | int w_send_dblock(struct drbd_work *w, int cancel) | 1363 | int w_send_dblock(struct drbd_work *w, int cancel) |
1357 | { | 1364 | { |
1358 | struct drbd_request *req = container_of(w, struct drbd_request, w); | 1365 | struct drbd_request *req = container_of(w, struct drbd_request, w); |
1359 | struct drbd_conf *mdev = w->mdev; | 1366 | struct drbd_device *device = req->device; |
1360 | struct drbd_tconn *tconn = mdev->tconn; | 1367 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1361 | int err; | 1368 | int err; |
1362 | 1369 | ||
1363 | if (unlikely(cancel)) { | 1370 | if (unlikely(cancel)) { |
@@ -1365,11 +1372,11 @@ int w_send_dblock(struct drbd_work *w, int cancel) | |||
1365 | return 0; | 1372 | return 0; |
1366 | } | 1373 | } |
1367 | 1374 | ||
1368 | re_init_if_first_write(tconn, req->epoch); | 1375 | re_init_if_first_write(connection, req->epoch); |
1369 | maybe_send_barrier(tconn, req->epoch); | 1376 | maybe_send_barrier(connection, req->epoch); |
1370 | tconn->send.current_epoch_writes++; | 1377 | connection->send.current_epoch_writes++; |
1371 | 1378 | ||
1372 | err = drbd_send_dblock(mdev, req); | 1379 | err = drbd_send_dblock(first_peer_device(device), req); |
1373 | req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); | 1380 | req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); |
1374 | 1381 | ||
1375 | return err; | 1382 | return err; |
@@ -1377,15 +1384,14 @@ int w_send_dblock(struct drbd_work *w, int cancel) | |||
1377 | 1384 | ||
1378 | /** | 1385 | /** |
1379 | * w_send_read_req() - Worker callback to send a read request (P_DATA_REQUEST) packet | 1386 | * w_send_read_req() - Worker callback to send a read request (P_DATA_REQUEST) packet |
1380 | * @mdev: DRBD device. | ||
1381 | * @w: work object. | 1387 | * @w: work object. |
1382 | * @cancel: The connection will be closed anyways | 1388 | * @cancel: The connection will be closed anyways |
1383 | */ | 1389 | */ |
1384 | int w_send_read_req(struct drbd_work *w, int cancel) | 1390 | int w_send_read_req(struct drbd_work *w, int cancel) |
1385 | { | 1391 | { |
1386 | struct drbd_request *req = container_of(w, struct drbd_request, w); | 1392 | struct drbd_request *req = container_of(w, struct drbd_request, w); |
1387 | struct drbd_conf *mdev = w->mdev; | 1393 | struct drbd_device *device = req->device; |
1388 | struct drbd_tconn *tconn = mdev->tconn; | 1394 | struct drbd_connection *connection = first_peer_device(device)->connection; |
1389 | int err; | 1395 | int err; |
1390 | 1396 | ||
1391 | if (unlikely(cancel)) { | 1397 | if (unlikely(cancel)) { |
@@ -1395,9 +1401,9 @@ int w_send_read_req(struct drbd_work *w, int cancel) | |||
1395 | 1401 | ||
1396 | /* Even read requests may close a write epoch, | 1402 | /* Even read requests may close a write epoch, |
1397 | * if there was any yet. */ | 1403 | * if there was any yet. */ |
1398 | maybe_send_barrier(tconn, req->epoch); | 1404 | maybe_send_barrier(connection, req->epoch); |
1399 | 1405 | ||
1400 | err = drbd_send_drequest(mdev, P_DATA_REQUEST, req->i.sector, req->i.size, | 1406 | err = drbd_send_drequest(first_peer_device(device), P_DATA_REQUEST, req->i.sector, req->i.size, |
1401 | (unsigned long)req); | 1407 | (unsigned long)req); |
1402 | 1408 | ||
1403 | req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); | 1409 | req_mod(req, err ? SEND_FAILED : HANDED_OVER_TO_NETWORK); |
@@ -1408,21 +1414,21 @@ int w_send_read_req(struct drbd_work *w, int cancel) | |||
1408 | int w_restart_disk_io(struct drbd_work *w, int cancel) | 1414 | int w_restart_disk_io(struct drbd_work *w, int cancel) |
1409 | { | 1415 | { |
1410 | struct drbd_request *req = container_of(w, struct drbd_request, w); | 1416 | struct drbd_request *req = container_of(w, struct drbd_request, w); |
1411 | struct drbd_conf *mdev = w->mdev; | 1417 | struct drbd_device *device = req->device; |
1412 | 1418 | ||
1413 | if (bio_data_dir(req->master_bio) == WRITE && req->rq_state & RQ_IN_ACT_LOG) | 1419 | if (bio_data_dir(req->master_bio) == WRITE && req->rq_state & RQ_IN_ACT_LOG) |
1414 | drbd_al_begin_io(mdev, &req->i, false); | 1420 | drbd_al_begin_io(device, &req->i, false); |
1415 | 1421 | ||
1416 | drbd_req_make_private_bio(req, req->master_bio); | 1422 | drbd_req_make_private_bio(req, req->master_bio); |
1417 | req->private_bio->bi_bdev = mdev->ldev->backing_bdev; | 1423 | req->private_bio->bi_bdev = device->ldev->backing_bdev; |
1418 | generic_make_request(req->private_bio); | 1424 | generic_make_request(req->private_bio); |
1419 | 1425 | ||
1420 | return 0; | 1426 | return 0; |
1421 | } | 1427 | } |
1422 | 1428 | ||
1423 | static int _drbd_may_sync_now(struct drbd_conf *mdev) | 1429 | static int _drbd_may_sync_now(struct drbd_device *device) |
1424 | { | 1430 | { |
1425 | struct drbd_conf *odev = mdev; | 1431 | struct drbd_device *odev = device; |
1426 | int resync_after; | 1432 | int resync_after; |
1427 | 1433 | ||
1428 | while (1) { | 1434 | while (1) { |
@@ -1433,7 +1439,7 @@ static int _drbd_may_sync_now(struct drbd_conf *mdev) | |||
1433 | rcu_read_unlock(); | 1439 | rcu_read_unlock(); |
1434 | if (resync_after == -1) | 1440 | if (resync_after == -1) |
1435 | return 1; | 1441 | return 1; |
1436 | odev = minor_to_mdev(resync_after); | 1442 | odev = minor_to_device(resync_after); |
1437 | if (!odev) | 1443 | if (!odev) |
1438 | return 1; | 1444 | return 1; |
1439 | if ((odev->state.conn >= C_SYNC_SOURCE && | 1445 | if ((odev->state.conn >= C_SYNC_SOURCE && |
@@ -1446,17 +1452,17 @@ static int _drbd_may_sync_now(struct drbd_conf *mdev) | |||
1446 | 1452 | ||
1447 | /** | 1453 | /** |
1448 | * _drbd_pause_after() - Pause resync on all devices that may not resync now | 1454 | * _drbd_pause_after() - Pause resync on all devices that may not resync now |
1449 | * @mdev: DRBD device. | 1455 | * @device: DRBD device. |
1450 | * | 1456 | * |
1451 | * Called from process context only (admin command and after_state_ch). | 1457 | * Called from process context only (admin command and after_state_ch). |
1452 | */ | 1458 | */ |
1453 | static int _drbd_pause_after(struct drbd_conf *mdev) | 1459 | static int _drbd_pause_after(struct drbd_device *device) |
1454 | { | 1460 | { |
1455 | struct drbd_conf *odev; | 1461 | struct drbd_device *odev; |
1456 | int i, rv = 0; | 1462 | int i, rv = 0; |
1457 | 1463 | ||
1458 | rcu_read_lock(); | 1464 | rcu_read_lock(); |
1459 | idr_for_each_entry(&minors, odev, i) { | 1465 | idr_for_each_entry(&drbd_devices, odev, i) { |
1460 | if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) | 1466 | if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) |
1461 | continue; | 1467 | continue; |
1462 | if (!_drbd_may_sync_now(odev)) | 1468 | if (!_drbd_may_sync_now(odev)) |
@@ -1470,17 +1476,17 @@ static int _drbd_pause_after(struct drbd_conf *mdev) | |||
1470 | 1476 | ||
1471 | /** | 1477 | /** |
1472 | * _drbd_resume_next() - Resume resync on all devices that may resync now | 1478 | * _drbd_resume_next() - Resume resync on all devices that may resync now |
1473 | * @mdev: DRBD device. | 1479 | * @device: DRBD device. |
1474 | * | 1480 | * |
1475 | * Called from process context only (admin command and worker). | 1481 | * Called from process context only (admin command and worker). |
1476 | */ | 1482 | */ |
1477 | static int _drbd_resume_next(struct drbd_conf *mdev) | 1483 | static int _drbd_resume_next(struct drbd_device *device) |
1478 | { | 1484 | { |
1479 | struct drbd_conf *odev; | 1485 | struct drbd_device *odev; |
1480 | int i, rv = 0; | 1486 | int i, rv = 0; |
1481 | 1487 | ||
1482 | rcu_read_lock(); | 1488 | rcu_read_lock(); |
1483 | idr_for_each_entry(&minors, odev, i) { | 1489 | idr_for_each_entry(&drbd_devices, odev, i) { |
1484 | if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) | 1490 | if (odev->state.conn == C_STANDALONE && odev->state.disk == D_DISKLESS) |
1485 | continue; | 1491 | continue; |
1486 | if (odev->state.aftr_isp) { | 1492 | if (odev->state.aftr_isp) { |
@@ -1494,24 +1500,24 @@ static int _drbd_resume_next(struct drbd_conf *mdev) | |||
1494 | return rv; | 1500 | return rv; |
1495 | } | 1501 | } |
1496 | 1502 | ||
1497 | void resume_next_sg(struct drbd_conf *mdev) | 1503 | void resume_next_sg(struct drbd_device *device) |
1498 | { | 1504 | { |
1499 | write_lock_irq(&global_state_lock); | 1505 | write_lock_irq(&global_state_lock); |
1500 | _drbd_resume_next(mdev); | 1506 | _drbd_resume_next(device); |
1501 | write_unlock_irq(&global_state_lock); | 1507 | write_unlock_irq(&global_state_lock); |
1502 | } | 1508 | } |
1503 | 1509 | ||
1504 | void suspend_other_sg(struct drbd_conf *mdev) | 1510 | void suspend_other_sg(struct drbd_device *device) |
1505 | { | 1511 | { |
1506 | write_lock_irq(&global_state_lock); | 1512 | write_lock_irq(&global_state_lock); |
1507 | _drbd_pause_after(mdev); | 1513 | _drbd_pause_after(device); |
1508 | write_unlock_irq(&global_state_lock); | 1514 | write_unlock_irq(&global_state_lock); |
1509 | } | 1515 | } |
1510 | 1516 | ||
1511 | /* caller must hold global_state_lock */ | 1517 | /* caller must hold global_state_lock */ |
1512 | enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor) | 1518 | enum drbd_ret_code drbd_resync_after_valid(struct drbd_device *device, int o_minor) |
1513 | { | 1519 | { |
1514 | struct drbd_conf *odev; | 1520 | struct drbd_device *odev; |
1515 | int resync_after; | 1521 | int resync_after; |
1516 | 1522 | ||
1517 | if (o_minor == -1) | 1523 | if (o_minor == -1) |
@@ -1520,9 +1526,9 @@ enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor) | |||
1520 | return ERR_RESYNC_AFTER; | 1526 | return ERR_RESYNC_AFTER; |
1521 | 1527 | ||
1522 | /* check for loops */ | 1528 | /* check for loops */ |
1523 | odev = minor_to_mdev(o_minor); | 1529 | odev = minor_to_device(o_minor); |
1524 | while (1) { | 1530 | while (1) { |
1525 | if (odev == mdev) | 1531 | if (odev == device) |
1526 | return ERR_RESYNC_AFTER_CYCLE; | 1532 | return ERR_RESYNC_AFTER_CYCLE; |
1527 | 1533 | ||
1528 | /* You are free to depend on diskless, non-existing, | 1534 | /* You are free to depend on diskless, non-existing, |
@@ -1542,35 +1548,35 @@ enum drbd_ret_code drbd_resync_after_valid(struct drbd_conf *mdev, int o_minor) | |||
1542 | return NO_ERROR; | 1548 | return NO_ERROR; |
1543 | 1549 | ||
1544 | /* follow the dependency chain */ | 1550 | /* follow the dependency chain */ |
1545 | odev = minor_to_mdev(resync_after); | 1551 | odev = minor_to_device(resync_after); |
1546 | } | 1552 | } |
1547 | } | 1553 | } |
1548 | 1554 | ||
1549 | /* caller must hold global_state_lock */ | 1555 | /* caller must hold global_state_lock */ |
1550 | void drbd_resync_after_changed(struct drbd_conf *mdev) | 1556 | void drbd_resync_after_changed(struct drbd_device *device) |
1551 | { | 1557 | { |
1552 | int changes; | 1558 | int changes; |
1553 | 1559 | ||
1554 | do { | 1560 | do { |
1555 | changes = _drbd_pause_after(mdev); | 1561 | changes = _drbd_pause_after(device); |
1556 | changes |= _drbd_resume_next(mdev); | 1562 | changes |= _drbd_resume_next(device); |
1557 | } while (changes); | 1563 | } while (changes); |
1558 | } | 1564 | } |
1559 | 1565 | ||
1560 | void drbd_rs_controller_reset(struct drbd_conf *mdev) | 1566 | void drbd_rs_controller_reset(struct drbd_device *device) |
1561 | { | 1567 | { |
1562 | struct fifo_buffer *plan; | 1568 | struct fifo_buffer *plan; |
1563 | 1569 | ||
1564 | atomic_set(&mdev->rs_sect_in, 0); | 1570 | atomic_set(&device->rs_sect_in, 0); |
1565 | atomic_set(&mdev->rs_sect_ev, 0); | 1571 | atomic_set(&device->rs_sect_ev, 0); |
1566 | mdev->rs_in_flight = 0; | 1572 | device->rs_in_flight = 0; |
1567 | 1573 | ||
1568 | /* Updating the RCU protected object in place is necessary since | 1574 | /* Updating the RCU protected object in place is necessary since |
1569 | this function gets called from atomic context. | 1575 | this function gets called from atomic context. |
1570 | It is valid since all other updates also lead to an completely | 1576 | It is valid since all other updates also lead to an completely |
1571 | empty fifo */ | 1577 | empty fifo */ |
1572 | rcu_read_lock(); | 1578 | rcu_read_lock(); |
1573 | plan = rcu_dereference(mdev->rs_plan_s); | 1579 | plan = rcu_dereference(device->rs_plan_s); |
1574 | plan->total = 0; | 1580 | plan->total = 0; |
1575 | fifo_set(plan, 0); | 1581 | fifo_set(plan, 0); |
1576 | rcu_read_unlock(); | 1582 | rcu_read_unlock(); |
@@ -1578,101 +1584,104 @@ void drbd_rs_controller_reset(struct drbd_conf *mdev) | |||
1578 | 1584 | ||
1579 | void start_resync_timer_fn(unsigned long data) | 1585 | void start_resync_timer_fn(unsigned long data) |
1580 | { | 1586 | { |
1581 | struct drbd_conf *mdev = (struct drbd_conf *) data; | 1587 | struct drbd_device *device = (struct drbd_device *) data; |
1582 | 1588 | ||
1583 | drbd_queue_work(&mdev->tconn->sender_work, &mdev->start_resync_work); | 1589 | drbd_queue_work(&first_peer_device(device)->connection->sender_work, |
1590 | &device->start_resync_work); | ||
1584 | } | 1591 | } |
1585 | 1592 | ||
1586 | int w_start_resync(struct drbd_work *w, int cancel) | 1593 | int w_start_resync(struct drbd_work *w, int cancel) |
1587 | { | 1594 | { |
1588 | struct drbd_conf *mdev = w->mdev; | 1595 | struct drbd_device *device = |
1596 | container_of(w, struct drbd_device, start_resync_work); | ||
1589 | 1597 | ||
1590 | if (atomic_read(&mdev->unacked_cnt) || atomic_read(&mdev->rs_pending_cnt)) { | 1598 | if (atomic_read(&device->unacked_cnt) || atomic_read(&device->rs_pending_cnt)) { |
1591 | dev_warn(DEV, "w_start_resync later...\n"); | 1599 | drbd_warn(device, "w_start_resync later...\n"); |
1592 | mdev->start_resync_timer.expires = jiffies + HZ/10; | 1600 | device->start_resync_timer.expires = jiffies + HZ/10; |
1593 | add_timer(&mdev->start_resync_timer); | 1601 | add_timer(&device->start_resync_timer); |
1594 | return 0; | 1602 | return 0; |
1595 | } | 1603 | } |
1596 | 1604 | ||
1597 | drbd_start_resync(mdev, C_SYNC_SOURCE); | 1605 | drbd_start_resync(device, C_SYNC_SOURCE); |
1598 | clear_bit(AHEAD_TO_SYNC_SOURCE, &mdev->flags); | 1606 | clear_bit(AHEAD_TO_SYNC_SOURCE, &device->flags); |
1599 | return 0; | 1607 | return 0; |
1600 | } | 1608 | } |
1601 | 1609 | ||
1602 | /** | 1610 | /** |
1603 | * drbd_start_resync() - Start the resync process | 1611 | * drbd_start_resync() - Start the resync process |
1604 | * @mdev: DRBD device. | 1612 | * @device: DRBD device. |
1605 | * @side: Either C_SYNC_SOURCE or C_SYNC_TARGET | 1613 | * @side: Either C_SYNC_SOURCE or C_SYNC_TARGET |
1606 | * | 1614 | * |
1607 | * This function might bring you directly into one of the | 1615 | * This function might bring you directly into one of the |
1608 | * C_PAUSED_SYNC_* states. | 1616 | * C_PAUSED_SYNC_* states. |
1609 | */ | 1617 | */ |
1610 | void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side) | 1618 | void drbd_start_resync(struct drbd_device *device, enum drbd_conns side) |
1611 | { | 1619 | { |
1612 | union drbd_state ns; | 1620 | union drbd_state ns; |
1613 | int r; | 1621 | int r; |
1614 | 1622 | ||
1615 | if (mdev->state.conn >= C_SYNC_SOURCE && mdev->state.conn < C_AHEAD) { | 1623 | if (device->state.conn >= C_SYNC_SOURCE && device->state.conn < C_AHEAD) { |
1616 | dev_err(DEV, "Resync already running!\n"); | 1624 | drbd_err(device, "Resync already running!\n"); |
1617 | return; | 1625 | return; |
1618 | } | 1626 | } |
1619 | 1627 | ||
1620 | if (!test_bit(B_RS_H_DONE, &mdev->flags)) { | 1628 | if (!test_bit(B_RS_H_DONE, &device->flags)) { |
1621 | if (side == C_SYNC_TARGET) { | 1629 | if (side == C_SYNC_TARGET) { |
1622 | /* Since application IO was locked out during C_WF_BITMAP_T and | 1630 | /* Since application IO was locked out during C_WF_BITMAP_T and |
1623 | C_WF_SYNC_UUID we are still unmodified. Before going to C_SYNC_TARGET | 1631 | C_WF_SYNC_UUID we are still unmodified. Before going to C_SYNC_TARGET |
1624 | we check that we might make the data inconsistent. */ | 1632 | we check that we might make the data inconsistent. */ |
1625 | r = drbd_khelper(mdev, "before-resync-target"); | 1633 | r = drbd_khelper(device, "before-resync-target"); |
1626 | r = (r >> 8) & 0xff; | 1634 | r = (r >> 8) & 0xff; |
1627 | if (r > 0) { | 1635 | if (r > 0) { |
1628 | dev_info(DEV, "before-resync-target handler returned %d, " | 1636 | drbd_info(device, "before-resync-target handler returned %d, " |
1629 | "dropping connection.\n", r); | 1637 | "dropping connection.\n", r); |
1630 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 1638 | conn_request_state(first_peer_device(device)->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
1631 | return; | 1639 | return; |
1632 | } | 1640 | } |
1633 | } else /* C_SYNC_SOURCE */ { | 1641 | } else /* C_SYNC_SOURCE */ { |
1634 | r = drbd_khelper(mdev, "before-resync-source"); | 1642 | r = drbd_khelper(device, "before-resync-source"); |
1635 | r = (r >> 8) & 0xff; | 1643 | r = (r >> 8) & 0xff; |
1636 | if (r > 0) { | 1644 | if (r > 0) { |
1637 | if (r == 3) { | 1645 | if (r == 3) { |
1638 | dev_info(DEV, "before-resync-source handler returned %d, " | 1646 | drbd_info(device, "before-resync-source handler returned %d, " |
1639 | "ignoring. Old userland tools?", r); | 1647 | "ignoring. Old userland tools?", r); |
1640 | } else { | 1648 | } else { |
1641 | dev_info(DEV, "before-resync-source handler returned %d, " | 1649 | drbd_info(device, "before-resync-source handler returned %d, " |
1642 | "dropping connection.\n", r); | 1650 | "dropping connection.\n", r); |
1643 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); | 1651 | conn_request_state(first_peer_device(device)->connection, |
1652 | NS(conn, C_DISCONNECTING), CS_HARD); | ||
1644 | return; | 1653 | return; |
1645 | } | 1654 | } |
1646 | } | 1655 | } |
1647 | } | 1656 | } |
1648 | } | 1657 | } |
1649 | 1658 | ||
1650 | if (current == mdev->tconn->worker.task) { | 1659 | if (current == first_peer_device(device)->connection->worker.task) { |
1651 | /* The worker should not sleep waiting for state_mutex, | 1660 | /* The worker should not sleep waiting for state_mutex, |
1652 | that can take long */ | 1661 | that can take long */ |
1653 | if (!mutex_trylock(mdev->state_mutex)) { | 1662 | if (!mutex_trylock(device->state_mutex)) { |
1654 | set_bit(B_RS_H_DONE, &mdev->flags); | 1663 | set_bit(B_RS_H_DONE, &device->flags); |
1655 | mdev->start_resync_timer.expires = jiffies + HZ/5; | 1664 | device->start_resync_timer.expires = jiffies + HZ/5; |
1656 | add_timer(&mdev->start_resync_timer); | 1665 | add_timer(&device->start_resync_timer); |
1657 | return; | 1666 | return; |
1658 | } | 1667 | } |
1659 | } else { | 1668 | } else { |
1660 | mutex_lock(mdev->state_mutex); | 1669 | mutex_lock(device->state_mutex); |
1661 | } | 1670 | } |
1662 | clear_bit(B_RS_H_DONE, &mdev->flags); | 1671 | clear_bit(B_RS_H_DONE, &device->flags); |
1663 | 1672 | ||
1664 | write_lock_irq(&global_state_lock); | 1673 | write_lock_irq(&global_state_lock); |
1665 | /* Did some connection breakage or IO error race with us? */ | 1674 | /* Did some connection breakage or IO error race with us? */ |
1666 | if (mdev->state.conn < C_CONNECTED | 1675 | if (device->state.conn < C_CONNECTED |
1667 | || !get_ldev_if_state(mdev, D_NEGOTIATING)) { | 1676 | || !get_ldev_if_state(device, D_NEGOTIATING)) { |
1668 | write_unlock_irq(&global_state_lock); | 1677 | write_unlock_irq(&global_state_lock); |
1669 | mutex_unlock(mdev->state_mutex); | 1678 | mutex_unlock(device->state_mutex); |
1670 | return; | 1679 | return; |
1671 | } | 1680 | } |
1672 | 1681 | ||
1673 | ns = drbd_read_state(mdev); | 1682 | ns = drbd_read_state(device); |
1674 | 1683 | ||
1675 | ns.aftr_isp = !_drbd_may_sync_now(mdev); | 1684 | ns.aftr_isp = !_drbd_may_sync_now(device); |
1676 | 1685 | ||
1677 | ns.conn = side; | 1686 | ns.conn = side; |
1678 | 1687 | ||
@@ -1681,43 +1690,43 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side) | |||
1681 | else /* side == C_SYNC_SOURCE */ | 1690 | else /* side == C_SYNC_SOURCE */ |
1682 | ns.pdsk = D_INCONSISTENT; | 1691 | ns.pdsk = D_INCONSISTENT; |
1683 | 1692 | ||
1684 | r = __drbd_set_state(mdev, ns, CS_VERBOSE, NULL); | 1693 | r = __drbd_set_state(device, ns, CS_VERBOSE, NULL); |
1685 | ns = drbd_read_state(mdev); | 1694 | ns = drbd_read_state(device); |
1686 | 1695 | ||
1687 | if (ns.conn < C_CONNECTED) | 1696 | if (ns.conn < C_CONNECTED) |
1688 | r = SS_UNKNOWN_ERROR; | 1697 | r = SS_UNKNOWN_ERROR; |
1689 | 1698 | ||
1690 | if (r == SS_SUCCESS) { | 1699 | if (r == SS_SUCCESS) { |
1691 | unsigned long tw = drbd_bm_total_weight(mdev); | 1700 | unsigned long tw = drbd_bm_total_weight(device); |
1692 | unsigned long now = jiffies; | 1701 | unsigned long now = jiffies; |
1693 | int i; | 1702 | int i; |
1694 | 1703 | ||
1695 | mdev->rs_failed = 0; | 1704 | device->rs_failed = 0; |
1696 | mdev->rs_paused = 0; | 1705 | device->rs_paused = 0; |
1697 | mdev->rs_same_csum = 0; | 1706 | device->rs_same_csum = 0; |
1698 | mdev->rs_last_events = 0; | 1707 | device->rs_last_events = 0; |
1699 | mdev->rs_last_sect_ev = 0; | 1708 | device->rs_last_sect_ev = 0; |
1700 | mdev->rs_total = tw; | 1709 | device->rs_total = tw; |
1701 | mdev->rs_start = now; | 1710 | device->rs_start = now; |
1702 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { | 1711 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
1703 | mdev->rs_mark_left[i] = tw; | 1712 | device->rs_mark_left[i] = tw; |
1704 | mdev->rs_mark_time[i] = now; | 1713 | device->rs_mark_time[i] = now; |
1705 | } | 1714 | } |
1706 | _drbd_pause_after(mdev); | 1715 | _drbd_pause_after(device); |
1707 | } | 1716 | } |
1708 | write_unlock_irq(&global_state_lock); | 1717 | write_unlock_irq(&global_state_lock); |
1709 | 1718 | ||
1710 | if (r == SS_SUCCESS) { | 1719 | if (r == SS_SUCCESS) { |
1711 | /* reset rs_last_bcast when a resync or verify is started, | 1720 | /* reset rs_last_bcast when a resync or verify is started, |
1712 | * to deal with potential jiffies wrap. */ | 1721 | * to deal with potential jiffies wrap. */ |
1713 | mdev->rs_last_bcast = jiffies - HZ; | 1722 | device->rs_last_bcast = jiffies - HZ; |
1714 | 1723 | ||
1715 | dev_info(DEV, "Began resync as %s (will sync %lu KB [%lu bits set]).\n", | 1724 | drbd_info(device, "Began resync as %s (will sync %lu KB [%lu bits set]).\n", |
1716 | drbd_conn_str(ns.conn), | 1725 | drbd_conn_str(ns.conn), |
1717 | (unsigned long) mdev->rs_total << (BM_BLOCK_SHIFT-10), | 1726 | (unsigned long) device->rs_total << (BM_BLOCK_SHIFT-10), |
1718 | (unsigned long) mdev->rs_total); | 1727 | (unsigned long) device->rs_total); |
1719 | if (side == C_SYNC_TARGET) | 1728 | if (side == C_SYNC_TARGET) |
1720 | mdev->bm_resync_fo = 0; | 1729 | device->bm_resync_fo = 0; |
1721 | 1730 | ||
1722 | /* Since protocol 96, we must serialize drbd_gen_and_send_sync_uuid | 1731 | /* Since protocol 96, we must serialize drbd_gen_and_send_sync_uuid |
1723 | * with w_send_oos, or the sync target will get confused as to | 1732 | * with w_send_oos, or the sync target will get confused as to |
@@ -1726,10 +1735,12 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side) | |||
1726 | * drbd_resync_finished from here in that case. | 1735 | * drbd_resync_finished from here in that case. |
1727 | * We drbd_gen_and_send_sync_uuid here for protocol < 96, | 1736 | * We drbd_gen_and_send_sync_uuid here for protocol < 96, |
1728 | * and from after_state_ch otherwise. */ | 1737 | * and from after_state_ch otherwise. */ |
1729 | if (side == C_SYNC_SOURCE && mdev->tconn->agreed_pro_version < 96) | 1738 | if (side == C_SYNC_SOURCE && |
1730 | drbd_gen_and_send_sync_uuid(mdev); | 1739 | first_peer_device(device)->connection->agreed_pro_version < 96) |
1740 | drbd_gen_and_send_sync_uuid(first_peer_device(device)); | ||
1731 | 1741 | ||
1732 | if (mdev->tconn->agreed_pro_version < 95 && mdev->rs_total == 0) { | 1742 | if (first_peer_device(device)->connection->agreed_pro_version < 95 && |
1743 | device->rs_total == 0) { | ||
1733 | /* This still has a race (about when exactly the peers | 1744 | /* This still has a race (about when exactly the peers |
1734 | * detect connection loss) that can lead to a full sync | 1745 | * detect connection loss) that can lead to a full sync |
1735 | * on next handshake. In 8.3.9 we fixed this with explicit | 1746 | * on next handshake. In 8.3.9 we fixed this with explicit |
@@ -1745,33 +1756,33 @@ void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side) | |||
1745 | int timeo; | 1756 | int timeo; |
1746 | 1757 | ||
1747 | rcu_read_lock(); | 1758 | rcu_read_lock(); |
1748 | nc = rcu_dereference(mdev->tconn->net_conf); | 1759 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
1749 | timeo = nc->ping_int * HZ + nc->ping_timeo * HZ / 9; | 1760 | timeo = nc->ping_int * HZ + nc->ping_timeo * HZ / 9; |
1750 | rcu_read_unlock(); | 1761 | rcu_read_unlock(); |
1751 | schedule_timeout_interruptible(timeo); | 1762 | schedule_timeout_interruptible(timeo); |
1752 | } | 1763 | } |
1753 | drbd_resync_finished(mdev); | 1764 | drbd_resync_finished(device); |
1754 | } | 1765 | } |
1755 | 1766 | ||
1756 | drbd_rs_controller_reset(mdev); | 1767 | drbd_rs_controller_reset(device); |
1757 | /* ns.conn may already be != mdev->state.conn, | 1768 | /* ns.conn may already be != device->state.conn, |
1758 | * we may have been paused in between, or become paused until | 1769 | * we may have been paused in between, or become paused until |
1759 | * the timer triggers. | 1770 | * the timer triggers. |
1760 | * No matter, that is handled in resync_timer_fn() */ | 1771 | * No matter, that is handled in resync_timer_fn() */ |
1761 | if (ns.conn == C_SYNC_TARGET) | 1772 | if (ns.conn == C_SYNC_TARGET) |
1762 | mod_timer(&mdev->resync_timer, jiffies); | 1773 | mod_timer(&device->resync_timer, jiffies); |
1763 | 1774 | ||
1764 | drbd_md_sync(mdev); | 1775 | drbd_md_sync(device); |
1765 | } | 1776 | } |
1766 | put_ldev(mdev); | 1777 | put_ldev(device); |
1767 | mutex_unlock(mdev->state_mutex); | 1778 | mutex_unlock(device->state_mutex); |
1768 | } | 1779 | } |
1769 | 1780 | ||
1770 | /* If the resource already closed the current epoch, but we did not | 1781 | /* If the resource already closed the current epoch, but we did not |
1771 | * (because we have not yet seen new requests), we should send the | 1782 | * (because we have not yet seen new requests), we should send the |
1772 | * corresponding barrier now. Must be checked within the same spinlock | 1783 | * corresponding barrier now. Must be checked within the same spinlock |
1773 | * that is used to check for new requests. */ | 1784 | * that is used to check for new requests. */ |
1774 | bool need_to_send_barrier(struct drbd_tconn *connection) | 1785 | static bool need_to_send_barrier(struct drbd_connection *connection) |
1775 | { | 1786 | { |
1776 | if (!connection->send.seen_any_write_yet) | 1787 | if (!connection->send.seen_any_write_yet) |
1777 | return false; | 1788 | return false; |
@@ -1795,7 +1806,7 @@ bool need_to_send_barrier(struct drbd_tconn *connection) | |||
1795 | return true; | 1806 | return true; |
1796 | } | 1807 | } |
1797 | 1808 | ||
1798 | bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list) | 1809 | static bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_list) |
1799 | { | 1810 | { |
1800 | spin_lock_irq(&queue->q_lock); | 1811 | spin_lock_irq(&queue->q_lock); |
1801 | list_splice_init(&queue->q, work_list); | 1812 | list_splice_init(&queue->q, work_list); |
@@ -1803,7 +1814,7 @@ bool dequeue_work_batch(struct drbd_work_queue *queue, struct list_head *work_li | |||
1803 | return !list_empty(work_list); | 1814 | return !list_empty(work_list); |
1804 | } | 1815 | } |
1805 | 1816 | ||
1806 | bool dequeue_work_item(struct drbd_work_queue *queue, struct list_head *work_list) | 1817 | static bool dequeue_work_item(struct drbd_work_queue *queue, struct list_head *work_list) |
1807 | { | 1818 | { |
1808 | spin_lock_irq(&queue->q_lock); | 1819 | spin_lock_irq(&queue->q_lock); |
1809 | if (!list_empty(&queue->q)) | 1820 | if (!list_empty(&queue->q)) |
@@ -1812,7 +1823,7 @@ bool dequeue_work_item(struct drbd_work_queue *queue, struct list_head *work_lis | |||
1812 | return !list_empty(work_list); | 1823 | return !list_empty(work_list); |
1813 | } | 1824 | } |
1814 | 1825 | ||
1815 | void wait_for_work(struct drbd_tconn *connection, struct list_head *work_list) | 1826 | static void wait_for_work(struct drbd_connection *connection, struct list_head *work_list) |
1816 | { | 1827 | { |
1817 | DEFINE_WAIT(wait); | 1828 | DEFINE_WAIT(wait); |
1818 | struct net_conf *nc; | 1829 | struct net_conf *nc; |
@@ -1842,7 +1853,7 @@ void wait_for_work(struct drbd_tconn *connection, struct list_head *work_list) | |||
1842 | for (;;) { | 1853 | for (;;) { |
1843 | int send_barrier; | 1854 | int send_barrier; |
1844 | prepare_to_wait(&connection->sender_work.q_wait, &wait, TASK_INTERRUPTIBLE); | 1855 | prepare_to_wait(&connection->sender_work.q_wait, &wait, TASK_INTERRUPTIBLE); |
1845 | spin_lock_irq(&connection->req_lock); | 1856 | spin_lock_irq(&connection->resource->req_lock); |
1846 | spin_lock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */ | 1857 | spin_lock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */ |
1847 | /* dequeue single item only, | 1858 | /* dequeue single item only, |
1848 | * we still use drbd_queue_work_front() in some places */ | 1859 | * we still use drbd_queue_work_front() in some places */ |
@@ -1850,11 +1861,11 @@ void wait_for_work(struct drbd_tconn *connection, struct list_head *work_list) | |||
1850 | list_move(connection->sender_work.q.next, work_list); | 1861 | list_move(connection->sender_work.q.next, work_list); |
1851 | spin_unlock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */ | 1862 | spin_unlock(&connection->sender_work.q_lock); /* FIXME get rid of this one? */ |
1852 | if (!list_empty(work_list) || signal_pending(current)) { | 1863 | if (!list_empty(work_list) || signal_pending(current)) { |
1853 | spin_unlock_irq(&connection->req_lock); | 1864 | spin_unlock_irq(&connection->resource->req_lock); |
1854 | break; | 1865 | break; |
1855 | } | 1866 | } |
1856 | send_barrier = need_to_send_barrier(connection); | 1867 | send_barrier = need_to_send_barrier(connection); |
1857 | spin_unlock_irq(&connection->req_lock); | 1868 | spin_unlock_irq(&connection->resource->req_lock); |
1858 | if (send_barrier) { | 1869 | if (send_barrier) { |
1859 | drbd_send_barrier(connection); | 1870 | drbd_send_barrier(connection); |
1860 | connection->send.current_epoch_nr++; | 1871 | connection->send.current_epoch_nr++; |
@@ -1883,9 +1894,9 @@ void wait_for_work(struct drbd_tconn *connection, struct list_head *work_list) | |||
1883 | 1894 | ||
1884 | int drbd_worker(struct drbd_thread *thi) | 1895 | int drbd_worker(struct drbd_thread *thi) |
1885 | { | 1896 | { |
1886 | struct drbd_tconn *tconn = thi->tconn; | 1897 | struct drbd_connection *connection = thi->connection; |
1887 | struct drbd_work *w = NULL; | 1898 | struct drbd_work *w = NULL; |
1888 | struct drbd_conf *mdev; | 1899 | struct drbd_peer_device *peer_device; |
1889 | LIST_HEAD(work_list); | 1900 | LIST_HEAD(work_list); |
1890 | int vnr; | 1901 | int vnr; |
1891 | 1902 | ||
@@ -1895,12 +1906,12 @@ int drbd_worker(struct drbd_thread *thi) | |||
1895 | /* as long as we use drbd_queue_work_front(), | 1906 | /* as long as we use drbd_queue_work_front(), |
1896 | * we may only dequeue single work items here, not batches. */ | 1907 | * we may only dequeue single work items here, not batches. */ |
1897 | if (list_empty(&work_list)) | 1908 | if (list_empty(&work_list)) |
1898 | wait_for_work(tconn, &work_list); | 1909 | wait_for_work(connection, &work_list); |
1899 | 1910 | ||
1900 | if (signal_pending(current)) { | 1911 | if (signal_pending(current)) { |
1901 | flush_signals(current); | 1912 | flush_signals(current); |
1902 | if (get_t_state(thi) == RUNNING) { | 1913 | if (get_t_state(thi) == RUNNING) { |
1903 | conn_warn(tconn, "Worker got an unexpected signal\n"); | 1914 | drbd_warn(connection, "Worker got an unexpected signal\n"); |
1904 | continue; | 1915 | continue; |
1905 | } | 1916 | } |
1906 | break; | 1917 | break; |
@@ -1912,10 +1923,10 @@ int drbd_worker(struct drbd_thread *thi) | |||
1912 | while (!list_empty(&work_list)) { | 1923 | while (!list_empty(&work_list)) { |
1913 | w = list_first_entry(&work_list, struct drbd_work, list); | 1924 | w = list_first_entry(&work_list, struct drbd_work, list); |
1914 | list_del_init(&w->list); | 1925 | list_del_init(&w->list); |
1915 | if (w->cb(w, tconn->cstate < C_WF_REPORT_PARAMS) == 0) | 1926 | if (w->cb(w, connection->cstate < C_WF_REPORT_PARAMS) == 0) |
1916 | continue; | 1927 | continue; |
1917 | if (tconn->cstate >= C_WF_REPORT_PARAMS) | 1928 | if (connection->cstate >= C_WF_REPORT_PARAMS) |
1918 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); | 1929 | conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
1919 | } | 1930 | } |
1920 | } | 1931 | } |
1921 | 1932 | ||
@@ -1925,16 +1936,17 @@ int drbd_worker(struct drbd_thread *thi) | |||
1925 | list_del_init(&w->list); | 1936 | list_del_init(&w->list); |
1926 | w->cb(w, 1); | 1937 | w->cb(w, 1); |
1927 | } | 1938 | } |
1928 | dequeue_work_batch(&tconn->sender_work, &work_list); | 1939 | dequeue_work_batch(&connection->sender_work, &work_list); |
1929 | } while (!list_empty(&work_list)); | 1940 | } while (!list_empty(&work_list)); |
1930 | 1941 | ||
1931 | rcu_read_lock(); | 1942 | rcu_read_lock(); |
1932 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { | 1943 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
1933 | D_ASSERT(mdev->state.disk == D_DISKLESS && mdev->state.conn == C_STANDALONE); | 1944 | struct drbd_device *device = peer_device->device; |
1934 | kref_get(&mdev->kref); | 1945 | D_ASSERT(device, device->state.disk == D_DISKLESS && device->state.conn == C_STANDALONE); |
1946 | kref_get(&device->kref); | ||
1935 | rcu_read_unlock(); | 1947 | rcu_read_unlock(); |
1936 | drbd_mdev_cleanup(mdev); | 1948 | drbd_device_cleanup(device); |
1937 | kref_put(&mdev->kref, &drbd_minor_destroy); | 1949 | kref_put(&device->kref, drbd_destroy_device); |
1938 | rcu_read_lock(); | 1950 | rcu_read_lock(); |
1939 | } | 1951 | } |
1940 | rcu_read_unlock(); | 1952 | rcu_read_unlock(); |
diff --git a/drivers/block/drbd/drbd_wrappers.h b/drivers/block/drbd/drbd_wrappers.h index 328f18e4b4ee..3db9ebaf64f6 100644 --- a/drivers/block/drbd/drbd_wrappers.h +++ b/drivers/block/drbd/drbd_wrappers.h | |||
@@ -9,12 +9,12 @@ | |||
9 | extern char *drbd_sec_holder; | 9 | extern char *drbd_sec_holder; |
10 | 10 | ||
11 | /* sets the number of 512 byte sectors of our virtual device */ | 11 | /* sets the number of 512 byte sectors of our virtual device */ |
12 | static inline void drbd_set_my_capacity(struct drbd_conf *mdev, | 12 | static inline void drbd_set_my_capacity(struct drbd_device *device, |
13 | sector_t size) | 13 | sector_t size) |
14 | { | 14 | { |
15 | /* set_capacity(mdev->this_bdev->bd_disk, size); */ | 15 | /* set_capacity(device->this_bdev->bd_disk, size); */ |
16 | set_capacity(mdev->vdisk, size); | 16 | set_capacity(device->vdisk, size); |
17 | mdev->this_bdev->bd_inode->i_size = (loff_t)size << 9; | 17 | device->this_bdev->bd_inode->i_size = (loff_t)size << 9; |
18 | } | 18 | } |
19 | 19 | ||
20 | #define drbd_bio_uptodate(bio) bio_flagged(bio, BIO_UPTODATE) | 20 | #define drbd_bio_uptodate(bio) bio_flagged(bio, BIO_UPTODATE) |
@@ -27,20 +27,20 @@ extern void drbd_request_endio(struct bio *bio, int error); | |||
27 | /* | 27 | /* |
28 | * used to submit our private bio | 28 | * used to submit our private bio |
29 | */ | 29 | */ |
30 | static inline void drbd_generic_make_request(struct drbd_conf *mdev, | 30 | static inline void drbd_generic_make_request(struct drbd_device *device, |
31 | int fault_type, struct bio *bio) | 31 | int fault_type, struct bio *bio) |
32 | { | 32 | { |
33 | __release(local); | 33 | __release(local); |
34 | if (!bio->bi_bdev) { | 34 | if (!bio->bi_bdev) { |
35 | printk(KERN_ERR "drbd%d: drbd_generic_make_request: " | 35 | printk(KERN_ERR "drbd%d: drbd_generic_make_request: " |
36 | "bio->bi_bdev == NULL\n", | 36 | "bio->bi_bdev == NULL\n", |
37 | mdev_to_minor(mdev)); | 37 | device_to_minor(device)); |
38 | dump_stack(); | 38 | dump_stack(); |
39 | bio_endio(bio, -ENODEV); | 39 | bio_endio(bio, -ENODEV); |
40 | return; | 40 | return; |
41 | } | 41 | } |
42 | 42 | ||
43 | if (drbd_insert_fault(mdev, fault_type)) | 43 | if (drbd_insert_fault(device, fault_type)) |
44 | bio_endio(bio, -EIO); | 44 | bio_endio(bio, -EIO); |
45 | else | 45 | else |
46 | generic_make_request(bio); | 46 | generic_make_request(bio); |
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c index d777bb7cea93..59c5abe32f06 100644 --- a/drivers/block/mtip32xx/mtip32xx.c +++ b/drivers/block/mtip32xx/mtip32xx.c | |||
@@ -252,38 +252,45 @@ static void mtip_async_complete(struct mtip_port *port, | |||
252 | void *data, | 252 | void *data, |
253 | int status) | 253 | int status) |
254 | { | 254 | { |
255 | struct mtip_cmd *command; | 255 | struct mtip_cmd *cmd; |
256 | struct driver_data *dd = data; | 256 | struct driver_data *dd = data; |
257 | int cb_status = status ? -EIO : 0; | 257 | int unaligned, cb_status = status ? -EIO : 0; |
258 | void (*func)(void *, int); | ||
258 | 259 | ||
259 | if (unlikely(!dd) || unlikely(!port)) | 260 | if (unlikely(!dd) || unlikely(!port)) |
260 | return; | 261 | return; |
261 | 262 | ||
262 | command = &port->commands[tag]; | 263 | cmd = &port->commands[tag]; |
263 | 264 | ||
264 | if (unlikely(status == PORT_IRQ_TF_ERR)) { | 265 | if (unlikely(status == PORT_IRQ_TF_ERR)) { |
265 | dev_warn(&port->dd->pdev->dev, | 266 | dev_warn(&port->dd->pdev->dev, |
266 | "Command tag %d failed due to TFE\n", tag); | 267 | "Command tag %d failed due to TFE\n", tag); |
267 | } | 268 | } |
268 | 269 | ||
270 | /* Clear the active flag */ | ||
271 | atomic_set(&port->commands[tag].active, 0); | ||
272 | |||
269 | /* Upper layer callback */ | 273 | /* Upper layer callback */ |
270 | if (likely(command->async_callback)) | 274 | func = cmd->async_callback; |
271 | command->async_callback(command->async_data, cb_status); | 275 | if (likely(func && cmpxchg(&cmd->async_callback, func, 0) == func)) { |
272 | 276 | ||
273 | command->async_callback = NULL; | 277 | /* Unmap the DMA scatter list entries */ |
274 | command->comp_func = NULL; | 278 | dma_unmap_sg(&dd->pdev->dev, |
279 | cmd->sg, | ||
280 | cmd->scatter_ents, | ||
281 | cmd->direction); | ||
275 | 282 | ||
276 | /* Unmap the DMA scatter list entries */ | 283 | func(cmd->async_data, cb_status); |
277 | dma_unmap_sg(&dd->pdev->dev, | 284 | unaligned = cmd->unaligned; |
278 | command->sg, | ||
279 | command->scatter_ents, | ||
280 | command->direction); | ||
281 | 285 | ||
282 | /* Clear the allocated and active bits for the command */ | 286 | /* Clear the allocated bit for the command */ |
283 | atomic_set(&port->commands[tag].active, 0); | 287 | release_slot(port, tag); |
284 | release_slot(port, tag); | ||
285 | 288 | ||
286 | up(&port->cmd_slot); | 289 | if (unlikely(unaligned)) |
290 | up(&port->cmd_slot_unal); | ||
291 | else | ||
292 | up(&port->cmd_slot); | ||
293 | } | ||
287 | } | 294 | } |
288 | 295 | ||
289 | /* | 296 | /* |
@@ -660,11 +667,12 @@ static void mtip_timeout_function(unsigned long int data) | |||
660 | { | 667 | { |
661 | struct mtip_port *port = (struct mtip_port *) data; | 668 | struct mtip_port *port = (struct mtip_port *) data; |
662 | struct host_to_dev_fis *fis; | 669 | struct host_to_dev_fis *fis; |
663 | struct mtip_cmd *command; | 670 | struct mtip_cmd *cmd; |
664 | int tag, cmdto_cnt = 0; | 671 | int unaligned, tag, cmdto_cnt = 0; |
665 | unsigned int bit, group; | 672 | unsigned int bit, group; |
666 | unsigned int num_command_slots; | 673 | unsigned int num_command_slots; |
667 | unsigned long to, tagaccum[SLOTBITS_IN_LONGS]; | 674 | unsigned long to, tagaccum[SLOTBITS_IN_LONGS]; |
675 | void (*func)(void *, int); | ||
668 | 676 | ||
669 | if (unlikely(!port)) | 677 | if (unlikely(!port)) |
670 | return; | 678 | return; |
@@ -694,8 +702,8 @@ static void mtip_timeout_function(unsigned long int data) | |||
694 | group = tag >> 5; | 702 | group = tag >> 5; |
695 | bit = tag & 0x1F; | 703 | bit = tag & 0x1F; |
696 | 704 | ||
697 | command = &port->commands[tag]; | 705 | cmd = &port->commands[tag]; |
698 | fis = (struct host_to_dev_fis *) command->command; | 706 | fis = (struct host_to_dev_fis *) cmd->command; |
699 | 707 | ||
700 | set_bit(tag, tagaccum); | 708 | set_bit(tag, tagaccum); |
701 | cmdto_cnt++; | 709 | cmdto_cnt++; |
@@ -709,27 +717,30 @@ static void mtip_timeout_function(unsigned long int data) | |||
709 | */ | 717 | */ |
710 | writel(1 << bit, port->completed[group]); | 718 | writel(1 << bit, port->completed[group]); |
711 | 719 | ||
712 | /* Call the async completion callback. */ | 720 | /* Clear the active flag for the command */ |
713 | if (likely(command->async_callback)) | 721 | atomic_set(&port->commands[tag].active, 0); |
714 | command->async_callback(command->async_data, | ||
715 | -EIO); | ||
716 | command->async_callback = NULL; | ||
717 | command->comp_func = NULL; | ||
718 | 722 | ||
719 | /* Unmap the DMA scatter list entries */ | 723 | func = cmd->async_callback; |
720 | dma_unmap_sg(&port->dd->pdev->dev, | 724 | if (func && |
721 | command->sg, | 725 | cmpxchg(&cmd->async_callback, func, 0) == func) { |
722 | command->scatter_ents, | ||
723 | command->direction); | ||
724 | 726 | ||
725 | /* | 727 | /* Unmap the DMA scatter list entries */ |
726 | * Clear the allocated bit and active tag for the | 728 | dma_unmap_sg(&port->dd->pdev->dev, |
727 | * command. | 729 | cmd->sg, |
728 | */ | 730 | cmd->scatter_ents, |
729 | atomic_set(&port->commands[tag].active, 0); | 731 | cmd->direction); |
730 | release_slot(port, tag); | ||
731 | 732 | ||
732 | up(&port->cmd_slot); | 733 | func(cmd->async_data, -EIO); |
734 | unaligned = cmd->unaligned; | ||
735 | |||
736 | /* Clear the allocated bit for the command. */ | ||
737 | release_slot(port, tag); | ||
738 | |||
739 | if (unaligned) | ||
740 | up(&port->cmd_slot_unal); | ||
741 | else | ||
742 | up(&port->cmd_slot); | ||
743 | } | ||
733 | } | 744 | } |
734 | } | 745 | } |
735 | 746 | ||
@@ -4213,6 +4224,7 @@ skip_create_disk: | |||
4213 | blk_queue_max_hw_sectors(dd->queue, 0xffff); | 4224 | blk_queue_max_hw_sectors(dd->queue, 0xffff); |
4214 | blk_queue_max_segment_size(dd->queue, 0x400000); | 4225 | blk_queue_max_segment_size(dd->queue, 0x400000); |
4215 | blk_queue_io_min(dd->queue, 4096); | 4226 | blk_queue_io_min(dd->queue, 4096); |
4227 | blk_queue_bounce_limit(dd->queue, dd->pdev->dma_mask); | ||
4216 | 4228 | ||
4217 | /* | 4229 | /* |
4218 | * write back cache is not supported in the device. FUA depends on | 4230 | * write back cache is not supported in the device. FUA depends on |
@@ -4615,7 +4627,7 @@ static int mtip_pci_probe(struct pci_dev *pdev, | |||
4615 | if (rv) { | 4627 | if (rv) { |
4616 | dev_warn(&pdev->dev, | 4628 | dev_warn(&pdev->dev, |
4617 | "Unable to enable MSI interrupt.\n"); | 4629 | "Unable to enable MSI interrupt.\n"); |
4618 | goto block_initialize_err; | 4630 | goto msi_initialize_err; |
4619 | } | 4631 | } |
4620 | 4632 | ||
4621 | /* Initialize the block layer. */ | 4633 | /* Initialize the block layer. */ |
@@ -4645,6 +4657,8 @@ static int mtip_pci_probe(struct pci_dev *pdev, | |||
4645 | 4657 | ||
4646 | block_initialize_err: | 4658 | block_initialize_err: |
4647 | pci_disable_msi(pdev); | 4659 | pci_disable_msi(pdev); |
4660 | |||
4661 | msi_initialize_err: | ||
4648 | if (dd->isr_workq) { | 4662 | if (dd->isr_workq) { |
4649 | flush_workqueue(dd->isr_workq); | 4663 | flush_workqueue(dd->isr_workq); |
4650 | destroy_workqueue(dd->isr_workq); | 4664 | destroy_workqueue(dd->isr_workq); |
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h index 54174cb32feb..ffb955e7ccb9 100644 --- a/drivers/block/mtip32xx/mtip32xx.h +++ b/drivers/block/mtip32xx/mtip32xx.h | |||
@@ -92,7 +92,7 @@ | |||
92 | 92 | ||
93 | /* Driver name and version strings */ | 93 | /* Driver name and version strings */ |
94 | #define MTIP_DRV_NAME "mtip32xx" | 94 | #define MTIP_DRV_NAME "mtip32xx" |
95 | #define MTIP_DRV_VERSION "1.3.0" | 95 | #define MTIP_DRV_VERSION "1.3.1" |
96 | 96 | ||
97 | /* Maximum number of minor device numbers per device. */ | 97 | /* Maximum number of minor device numbers per device. */ |
98 | #define MTIP_MAX_MINORS 16 | 98 | #define MTIP_MAX_MINORS 16 |
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index 8459e4e7c719..da085ff10d25 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c | |||
@@ -1836,31 +1836,16 @@ static int nvme_setup_io_queues(struct nvme_dev *dev) | |||
1836 | /* Deregister the admin queue's interrupt */ | 1836 | /* Deregister the admin queue's interrupt */ |
1837 | free_irq(dev->entry[0].vector, adminq); | 1837 | free_irq(dev->entry[0].vector, adminq); |
1838 | 1838 | ||
1839 | vecs = nr_io_queues; | 1839 | for (i = 0; i < nr_io_queues; i++) |
1840 | for (i = 0; i < vecs; i++) | ||
1841 | dev->entry[i].entry = i; | 1840 | dev->entry[i].entry = i; |
1842 | for (;;) { | 1841 | vecs = pci_enable_msix_range(pdev, dev->entry, 1, nr_io_queues); |
1843 | result = pci_enable_msix(pdev, dev->entry, vecs); | 1842 | if (vecs < 0) { |
1844 | if (result <= 0) | 1843 | vecs = pci_enable_msi_range(pdev, 1, min(nr_io_queues, 32)); |
1845 | break; | 1844 | if (vecs < 0) { |
1846 | vecs = result; | 1845 | vecs = 1; |
1847 | } | 1846 | } else { |
1848 | 1847 | for (i = 0; i < vecs; i++) | |
1849 | if (result < 0) { | 1848 | dev->entry[i].vector = i + pdev->irq; |
1850 | vecs = nr_io_queues; | ||
1851 | if (vecs > 32) | ||
1852 | vecs = 32; | ||
1853 | for (;;) { | ||
1854 | result = pci_enable_msi_block(pdev, vecs); | ||
1855 | if (result == 0) { | ||
1856 | for (i = 0; i < vecs; i++) | ||
1857 | dev->entry[i].vector = i + pdev->irq; | ||
1858 | break; | ||
1859 | } else if (result < 0) { | ||
1860 | vecs = 1; | ||
1861 | break; | ||
1862 | } | ||
1863 | vecs = result; | ||
1864 | } | 1849 | } |
1865 | } | 1850 | } |
1866 | 1851 | ||
diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c index eb6e1e0e8db2..a69dd93d1bd5 100644 --- a/drivers/block/skd_main.c +++ b/drivers/block/skd_main.c | |||
@@ -3910,18 +3910,22 @@ static void skd_release_msix(struct skd_device *skdev) | |||
3910 | struct skd_msix_entry *qentry; | 3910 | struct skd_msix_entry *qentry; |
3911 | int i; | 3911 | int i; |
3912 | 3912 | ||
3913 | if (skdev->msix_entries == NULL) | 3913 | if (skdev->msix_entries) { |
3914 | return; | 3914 | for (i = 0; i < skdev->msix_count; i++) { |
3915 | for (i = 0; i < skdev->msix_count; i++) { | 3915 | qentry = &skdev->msix_entries[i]; |
3916 | qentry = &skdev->msix_entries[i]; | 3916 | skdev = qentry->rsp; |
3917 | skdev = qentry->rsp; | 3917 | |
3918 | if (qentry->have_irq) | ||
3919 | devm_free_irq(&skdev->pdev->dev, | ||
3920 | qentry->vector, qentry->rsp); | ||
3921 | } | ||
3918 | 3922 | ||
3919 | if (qentry->have_irq) | 3923 | kfree(skdev->msix_entries); |
3920 | devm_free_irq(&skdev->pdev->dev, | ||
3921 | qentry->vector, qentry->rsp); | ||
3922 | } | 3924 | } |
3923 | pci_disable_msix(skdev->pdev); | 3925 | |
3924 | kfree(skdev->msix_entries); | 3926 | if (skdev->msix_count) |
3927 | pci_disable_msix(skdev->pdev); | ||
3928 | |||
3925 | skdev->msix_count = 0; | 3929 | skdev->msix_count = 0; |
3926 | skdev->msix_entries = NULL; | 3930 | skdev->msix_entries = NULL; |
3927 | } | 3931 | } |
@@ -3929,12 +3933,10 @@ static void skd_release_msix(struct skd_device *skdev) | |||
3929 | static int skd_acquire_msix(struct skd_device *skdev) | 3933 | static int skd_acquire_msix(struct skd_device *skdev) |
3930 | { | 3934 | { |
3931 | int i, rc; | 3935 | int i, rc; |
3932 | struct pci_dev *pdev; | 3936 | struct pci_dev *pdev = skdev->pdev; |
3933 | struct msix_entry *entries = NULL; | 3937 | struct msix_entry *entries; |
3934 | struct skd_msix_entry *qentry; | 3938 | struct skd_msix_entry *qentry; |
3935 | 3939 | ||
3936 | pdev = skdev->pdev; | ||
3937 | skdev->msix_count = SKD_MAX_MSIX_COUNT; | ||
3938 | entries = kzalloc(sizeof(struct msix_entry) * SKD_MAX_MSIX_COUNT, | 3940 | entries = kzalloc(sizeof(struct msix_entry) * SKD_MAX_MSIX_COUNT, |
3939 | GFP_KERNEL); | 3941 | GFP_KERNEL); |
3940 | if (!entries) | 3942 | if (!entries) |
@@ -3943,40 +3945,26 @@ static int skd_acquire_msix(struct skd_device *skdev) | |||
3943 | for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) | 3945 | for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) |
3944 | entries[i].entry = i; | 3946 | entries[i].entry = i; |
3945 | 3947 | ||
3946 | rc = pci_enable_msix(pdev, entries, SKD_MAX_MSIX_COUNT); | 3948 | rc = pci_enable_msix_range(pdev, entries, |
3947 | if (rc < 0) | 3949 | SKD_MIN_MSIX_COUNT, SKD_MAX_MSIX_COUNT); |
3950 | if (rc < 0) { | ||
3951 | pr_err("(%s): failed to enable MSI-X %d\n", | ||
3952 | skd_name(skdev), rc); | ||
3948 | goto msix_out; | 3953 | goto msix_out; |
3949 | if (rc) { | ||
3950 | if (rc < SKD_MIN_MSIX_COUNT) { | ||
3951 | pr_err("(%s): failed to enable MSI-X %d\n", | ||
3952 | skd_name(skdev), rc); | ||
3953 | goto msix_out; | ||
3954 | } | ||
3955 | pr_debug("%s:%s:%d %s: <%s> allocated %d MSI-X vectors\n", | ||
3956 | skdev->name, __func__, __LINE__, | ||
3957 | pci_name(pdev), skdev->name, rc); | ||
3958 | |||
3959 | skdev->msix_count = rc; | ||
3960 | rc = pci_enable_msix(pdev, entries, skdev->msix_count); | ||
3961 | if (rc) { | ||
3962 | pr_err("(%s): failed to enable MSI-X " | ||
3963 | "support (%d) %d\n", | ||
3964 | skd_name(skdev), skdev->msix_count, rc); | ||
3965 | goto msix_out; | ||
3966 | } | ||
3967 | } | 3954 | } |
3955 | |||
3956 | skdev->msix_count = rc; | ||
3968 | skdev->msix_entries = kzalloc(sizeof(struct skd_msix_entry) * | 3957 | skdev->msix_entries = kzalloc(sizeof(struct skd_msix_entry) * |
3969 | skdev->msix_count, GFP_KERNEL); | 3958 | skdev->msix_count, GFP_KERNEL); |
3970 | if (!skdev->msix_entries) { | 3959 | if (!skdev->msix_entries) { |
3971 | rc = -ENOMEM; | 3960 | rc = -ENOMEM; |
3972 | skdev->msix_count = 0; | ||
3973 | pr_err("(%s): msix table allocation error\n", | 3961 | pr_err("(%s): msix table allocation error\n", |
3974 | skd_name(skdev)); | 3962 | skd_name(skdev)); |
3975 | goto msix_out; | 3963 | goto msix_out; |
3976 | } | 3964 | } |
3977 | 3965 | ||
3978 | qentry = skdev->msix_entries; | ||
3979 | for (i = 0; i < skdev->msix_count; i++) { | 3966 | for (i = 0; i < skdev->msix_count; i++) { |
3967 | qentry = &skdev->msix_entries[i]; | ||
3980 | qentry->vector = entries[i].vector; | 3968 | qentry->vector = entries[i].vector; |
3981 | qentry->entry = entries[i].entry; | 3969 | qentry->entry = entries[i].entry; |
3982 | qentry->rsp = NULL; | 3970 | qentry->rsp = NULL; |
@@ -3985,11 +3973,10 @@ static int skd_acquire_msix(struct skd_device *skdev) | |||
3985 | skdev->name, __func__, __LINE__, | 3973 | skdev->name, __func__, __LINE__, |
3986 | pci_name(pdev), skdev->name, | 3974 | pci_name(pdev), skdev->name, |
3987 | i, qentry->vector, qentry->entry); | 3975 | i, qentry->vector, qentry->entry); |
3988 | qentry++; | ||
3989 | } | 3976 | } |
3990 | 3977 | ||
3991 | /* Enable MSI-X vectors for the base queue */ | 3978 | /* Enable MSI-X vectors for the base queue */ |
3992 | for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) { | 3979 | for (i = 0; i < skdev->msix_count; i++) { |
3993 | qentry = &skdev->msix_entries[i]; | 3980 | qentry = &skdev->msix_entries[i]; |
3994 | snprintf(qentry->isr_name, sizeof(qentry->isr_name), | 3981 | snprintf(qentry->isr_name, sizeof(qentry->isr_name), |
3995 | "%s%d-msix %s", DRV_NAME, skdev->devno, | 3982 | "%s%d-msix %s", DRV_NAME, skdev->devno, |
@@ -4045,8 +4032,8 @@ RETRY_IRQ_TYPE: | |||
4045 | case SKD_IRQ_MSI: | 4032 | case SKD_IRQ_MSI: |
4046 | snprintf(skdev->isr_name, sizeof(skdev->isr_name), "%s%d-msi", | 4033 | snprintf(skdev->isr_name, sizeof(skdev->isr_name), "%s%d-msi", |
4047 | DRV_NAME, skdev->devno); | 4034 | DRV_NAME, skdev->devno); |
4048 | rc = pci_enable_msi(pdev); | 4035 | rc = pci_enable_msi_range(pdev, 1, 1); |
4049 | if (!rc) { | 4036 | if (rc > 0) { |
4050 | rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr, 0, | 4037 | rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr, 0, |
4051 | skdev->isr_name, skdev); | 4038 | skdev->isr_name, skdev); |
4052 | if (rc) { | 4039 | if (rc) { |
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 20e061c3e023..c74f7b56e7c4 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
32 | #include <linux/spinlock.h> | 32 | #include <linux/spinlock.h> |
33 | #include <linux/wait.h> | ||
33 | #include <asm/io.h> | 34 | #include <asm/io.h> |
34 | #include <asm/dbdma.h> | 35 | #include <asm/dbdma.h> |
35 | #include <asm/prom.h> | 36 | #include <asm/prom.h> |
@@ -840,14 +841,17 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state, | |||
840 | spin_lock_irqsave(&swim3_lock, flags); | 841 | spin_lock_irqsave(&swim3_lock, flags); |
841 | if (fs->state != idle && fs->state != available) { | 842 | if (fs->state != idle && fs->state != available) { |
842 | ++fs->wanted; | 843 | ++fs->wanted; |
843 | while (fs->state != available) { | 844 | /* this will enable irqs in order to sleep */ |
845 | if (!interruptible) | ||
846 | wait_event_lock_irq(fs->wait, | ||
847 | fs->state == available, | ||
848 | swim3_lock); | ||
849 | else if (wait_event_interruptible_lock_irq(fs->wait, | ||
850 | fs->state == available, | ||
851 | swim3_lock)) { | ||
852 | --fs->wanted; | ||
844 | spin_unlock_irqrestore(&swim3_lock, flags); | 853 | spin_unlock_irqrestore(&swim3_lock, flags); |
845 | if (interruptible && signal_pending(current)) { | 854 | return -EINTR; |
846 | --fs->wanted; | ||
847 | return -EINTR; | ||
848 | } | ||
849 | interruptible_sleep_on(&fs->wait); | ||
850 | spin_lock_irqsave(&swim3_lock, flags); | ||
851 | } | 855 | } |
852 | --fs->wanted; | 856 | --fs->wanted; |
853 | } | 857 | } |
diff --git a/drivers/md/bcache/Kconfig b/drivers/md/bcache/Kconfig index 2638417b19aa..4d200883c505 100644 --- a/drivers/md/bcache/Kconfig +++ b/drivers/md/bcache/Kconfig | |||
@@ -24,11 +24,3 @@ config BCACHE_CLOSURES_DEBUG | |||
24 | Keeps all active closures in a linked list and provides a debugfs | 24 | Keeps all active closures in a linked list and provides a debugfs |
25 | interface to list them, which makes it possible to see asynchronous | 25 | interface to list them, which makes it possible to see asynchronous |
26 | operations that get stuck. | 26 | operations that get stuck. |
27 | |||
28 | # cgroup code needs to be updated: | ||
29 | # | ||
30 | #config CGROUP_BCACHE | ||
31 | # bool "Cgroup controls for bcache" | ||
32 | # depends on BCACHE && BLK_CGROUP | ||
33 | # ---help--- | ||
34 | # TODO | ||
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c index c0d37d082443..443d03fbac47 100644 --- a/drivers/md/bcache/alloc.c +++ b/drivers/md/bcache/alloc.c | |||
@@ -78,12 +78,6 @@ uint8_t bch_inc_gen(struct cache *ca, struct bucket *b) | |||
78 | ca->set->need_gc = max(ca->set->need_gc, bucket_gc_gen(b)); | 78 | ca->set->need_gc = max(ca->set->need_gc, bucket_gc_gen(b)); |
79 | WARN_ON_ONCE(ca->set->need_gc > BUCKET_GC_GEN_MAX); | 79 | WARN_ON_ONCE(ca->set->need_gc > BUCKET_GC_GEN_MAX); |
80 | 80 | ||
81 | if (CACHE_SYNC(&ca->set->sb)) { | ||
82 | ca->need_save_prio = max(ca->need_save_prio, | ||
83 | bucket_disk_gen(b)); | ||
84 | WARN_ON_ONCE(ca->need_save_prio > BUCKET_DISK_GEN_MAX); | ||
85 | } | ||
86 | |||
87 | return ret; | 81 | return ret; |
88 | } | 82 | } |
89 | 83 | ||
@@ -120,51 +114,45 @@ void bch_rescale_priorities(struct cache_set *c, int sectors) | |||
120 | mutex_unlock(&c->bucket_lock); | 114 | mutex_unlock(&c->bucket_lock); |
121 | } | 115 | } |
122 | 116 | ||
123 | /* Allocation */ | 117 | /* |
118 | * Background allocation thread: scans for buckets to be invalidated, | ||
119 | * invalidates them, rewrites prios/gens (marking them as invalidated on disk), | ||
120 | * then optionally issues discard commands to the newly free buckets, then puts | ||
121 | * them on the various freelists. | ||
122 | */ | ||
124 | 123 | ||
125 | static inline bool can_inc_bucket_gen(struct bucket *b) | 124 | static inline bool can_inc_bucket_gen(struct bucket *b) |
126 | { | 125 | { |
127 | return bucket_gc_gen(b) < BUCKET_GC_GEN_MAX && | 126 | return bucket_gc_gen(b) < BUCKET_GC_GEN_MAX; |
128 | bucket_disk_gen(b) < BUCKET_DISK_GEN_MAX; | ||
129 | } | 127 | } |
130 | 128 | ||
131 | bool bch_bucket_add_unused(struct cache *ca, struct bucket *b) | 129 | bool bch_can_invalidate_bucket(struct cache *ca, struct bucket *b) |
132 | { | 130 | { |
133 | BUG_ON(GC_MARK(b) || GC_SECTORS_USED(b)); | 131 | BUG_ON(!ca->set->gc_mark_valid); |
134 | |||
135 | if (CACHE_REPLACEMENT(&ca->sb) == CACHE_REPLACEMENT_FIFO) { | ||
136 | unsigned i; | ||
137 | |||
138 | for (i = 0; i < RESERVE_NONE; i++) | ||
139 | if (!fifo_full(&ca->free[i])) | ||
140 | goto add; | ||
141 | 132 | ||
142 | return false; | 133 | return (!GC_MARK(b) || |
143 | } | 134 | GC_MARK(b) == GC_MARK_RECLAIMABLE) && |
144 | add: | ||
145 | b->prio = 0; | ||
146 | |||
147 | if (can_inc_bucket_gen(b) && | ||
148 | fifo_push(&ca->unused, b - ca->buckets)) { | ||
149 | atomic_inc(&b->pin); | ||
150 | return true; | ||
151 | } | ||
152 | |||
153 | return false; | ||
154 | } | ||
155 | |||
156 | static bool can_invalidate_bucket(struct cache *ca, struct bucket *b) | ||
157 | { | ||
158 | return GC_MARK(b) == GC_MARK_RECLAIMABLE && | ||
159 | !atomic_read(&b->pin) && | 135 | !atomic_read(&b->pin) && |
160 | can_inc_bucket_gen(b); | 136 | can_inc_bucket_gen(b); |
161 | } | 137 | } |
162 | 138 | ||
163 | static void invalidate_one_bucket(struct cache *ca, struct bucket *b) | 139 | void __bch_invalidate_one_bucket(struct cache *ca, struct bucket *b) |
164 | { | 140 | { |
141 | lockdep_assert_held(&ca->set->bucket_lock); | ||
142 | BUG_ON(GC_MARK(b) && GC_MARK(b) != GC_MARK_RECLAIMABLE); | ||
143 | |||
144 | if (GC_SECTORS_USED(b)) | ||
145 | trace_bcache_invalidate(ca, b - ca->buckets); | ||
146 | |||
165 | bch_inc_gen(ca, b); | 147 | bch_inc_gen(ca, b); |
166 | b->prio = INITIAL_PRIO; | 148 | b->prio = INITIAL_PRIO; |
167 | atomic_inc(&b->pin); | 149 | atomic_inc(&b->pin); |
150 | } | ||
151 | |||
152 | static void bch_invalidate_one_bucket(struct cache *ca, struct bucket *b) | ||
153 | { | ||
154 | __bch_invalidate_one_bucket(ca, b); | ||
155 | |||
168 | fifo_push(&ca->free_inc, b - ca->buckets); | 156 | fifo_push(&ca->free_inc, b - ca->buckets); |
169 | } | 157 | } |
170 | 158 | ||
@@ -195,20 +183,7 @@ static void invalidate_buckets_lru(struct cache *ca) | |||
195 | ca->heap.used = 0; | 183 | ca->heap.used = 0; |
196 | 184 | ||
197 | for_each_bucket(b, ca) { | 185 | for_each_bucket(b, ca) { |
198 | /* | 186 | if (!bch_can_invalidate_bucket(ca, b)) |
199 | * If we fill up the unused list, if we then return before | ||
200 | * adding anything to the free_inc list we'll skip writing | ||
201 | * prios/gens and just go back to allocating from the unused | ||
202 | * list: | ||
203 | */ | ||
204 | if (fifo_full(&ca->unused)) | ||
205 | return; | ||
206 | |||
207 | if (!can_invalidate_bucket(ca, b)) | ||
208 | continue; | ||
209 | |||
210 | if (!GC_SECTORS_USED(b) && | ||
211 | bch_bucket_add_unused(ca, b)) | ||
212 | continue; | 187 | continue; |
213 | 188 | ||
214 | if (!heap_full(&ca->heap)) | 189 | if (!heap_full(&ca->heap)) |
@@ -233,7 +208,7 @@ static void invalidate_buckets_lru(struct cache *ca) | |||
233 | return; | 208 | return; |
234 | } | 209 | } |
235 | 210 | ||
236 | invalidate_one_bucket(ca, b); | 211 | bch_invalidate_one_bucket(ca, b); |
237 | } | 212 | } |
238 | } | 213 | } |
239 | 214 | ||
@@ -249,8 +224,8 @@ static void invalidate_buckets_fifo(struct cache *ca) | |||
249 | 224 | ||
250 | b = ca->buckets + ca->fifo_last_bucket++; | 225 | b = ca->buckets + ca->fifo_last_bucket++; |
251 | 226 | ||
252 | if (can_invalidate_bucket(ca, b)) | 227 | if (bch_can_invalidate_bucket(ca, b)) |
253 | invalidate_one_bucket(ca, b); | 228 | bch_invalidate_one_bucket(ca, b); |
254 | 229 | ||
255 | if (++checked >= ca->sb.nbuckets) { | 230 | if (++checked >= ca->sb.nbuckets) { |
256 | ca->invalidate_needs_gc = 1; | 231 | ca->invalidate_needs_gc = 1; |
@@ -274,8 +249,8 @@ static void invalidate_buckets_random(struct cache *ca) | |||
274 | 249 | ||
275 | b = ca->buckets + n; | 250 | b = ca->buckets + n; |
276 | 251 | ||
277 | if (can_invalidate_bucket(ca, b)) | 252 | if (bch_can_invalidate_bucket(ca, b)) |
278 | invalidate_one_bucket(ca, b); | 253 | bch_invalidate_one_bucket(ca, b); |
279 | 254 | ||
280 | if (++checked >= ca->sb.nbuckets / 2) { | 255 | if (++checked >= ca->sb.nbuckets / 2) { |
281 | ca->invalidate_needs_gc = 1; | 256 | ca->invalidate_needs_gc = 1; |
@@ -287,8 +262,7 @@ static void invalidate_buckets_random(struct cache *ca) | |||
287 | 262 | ||
288 | static void invalidate_buckets(struct cache *ca) | 263 | static void invalidate_buckets(struct cache *ca) |
289 | { | 264 | { |
290 | if (ca->invalidate_needs_gc) | 265 | BUG_ON(ca->invalidate_needs_gc); |
291 | return; | ||
292 | 266 | ||
293 | switch (CACHE_REPLACEMENT(&ca->sb)) { | 267 | switch (CACHE_REPLACEMENT(&ca->sb)) { |
294 | case CACHE_REPLACEMENT_LRU: | 268 | case CACHE_REPLACEMENT_LRU: |
@@ -301,8 +275,6 @@ static void invalidate_buckets(struct cache *ca) | |||
301 | invalidate_buckets_random(ca); | 275 | invalidate_buckets_random(ca); |
302 | break; | 276 | break; |
303 | } | 277 | } |
304 | |||
305 | trace_bcache_alloc_invalidate(ca); | ||
306 | } | 278 | } |
307 | 279 | ||
308 | #define allocator_wait(ca, cond) \ | 280 | #define allocator_wait(ca, cond) \ |
@@ -350,17 +322,10 @@ static int bch_allocator_thread(void *arg) | |||
350 | * possibly issue discards to them, then we add the bucket to | 322 | * possibly issue discards to them, then we add the bucket to |
351 | * the free list: | 323 | * the free list: |
352 | */ | 324 | */ |
353 | while (1) { | 325 | while (!fifo_empty(&ca->free_inc)) { |
354 | long bucket; | 326 | long bucket; |
355 | 327 | ||
356 | if ((!atomic_read(&ca->set->prio_blocked) || | 328 | fifo_pop(&ca->free_inc, bucket); |
357 | !CACHE_SYNC(&ca->set->sb)) && | ||
358 | !fifo_empty(&ca->unused)) | ||
359 | fifo_pop(&ca->unused, bucket); | ||
360 | else if (!fifo_empty(&ca->free_inc)) | ||
361 | fifo_pop(&ca->free_inc, bucket); | ||
362 | else | ||
363 | break; | ||
364 | 329 | ||
365 | if (ca->discard) { | 330 | if (ca->discard) { |
366 | mutex_unlock(&ca->set->bucket_lock); | 331 | mutex_unlock(&ca->set->bucket_lock); |
@@ -371,6 +336,7 @@ static int bch_allocator_thread(void *arg) | |||
371 | } | 336 | } |
372 | 337 | ||
373 | allocator_wait(ca, bch_allocator_push(ca, bucket)); | 338 | allocator_wait(ca, bch_allocator_push(ca, bucket)); |
339 | wake_up(&ca->set->btree_cache_wait); | ||
374 | wake_up(&ca->set->bucket_wait); | 340 | wake_up(&ca->set->bucket_wait); |
375 | } | 341 | } |
376 | 342 | ||
@@ -380,9 +346,9 @@ static int bch_allocator_thread(void *arg) | |||
380 | * them to the free_inc list: | 346 | * them to the free_inc list: |
381 | */ | 347 | */ |
382 | 348 | ||
349 | retry_invalidate: | ||
383 | allocator_wait(ca, ca->set->gc_mark_valid && | 350 | allocator_wait(ca, ca->set->gc_mark_valid && |
384 | (ca->need_save_prio > 64 || | 351 | !ca->invalidate_needs_gc); |
385 | !ca->invalidate_needs_gc)); | ||
386 | invalidate_buckets(ca); | 352 | invalidate_buckets(ca); |
387 | 353 | ||
388 | /* | 354 | /* |
@@ -390,13 +356,28 @@ static int bch_allocator_thread(void *arg) | |||
390 | * new stuff to them: | 356 | * new stuff to them: |
391 | */ | 357 | */ |
392 | allocator_wait(ca, !atomic_read(&ca->set->prio_blocked)); | 358 | allocator_wait(ca, !atomic_read(&ca->set->prio_blocked)); |
393 | if (CACHE_SYNC(&ca->set->sb) && | 359 | if (CACHE_SYNC(&ca->set->sb)) { |
394 | (!fifo_empty(&ca->free_inc) || | 360 | /* |
395 | ca->need_save_prio > 64)) | 361 | * This could deadlock if an allocation with a btree |
362 | * node locked ever blocked - having the btree node | ||
363 | * locked would block garbage collection, but here we're | ||
364 | * waiting on garbage collection before we invalidate | ||
365 | * and free anything. | ||
366 | * | ||
367 | * But this should be safe since the btree code always | ||
368 | * uses btree_check_reserve() before allocating now, and | ||
369 | * if it fails it blocks without btree nodes locked. | ||
370 | */ | ||
371 | if (!fifo_full(&ca->free_inc)) | ||
372 | goto retry_invalidate; | ||
373 | |||
396 | bch_prio_write(ca); | 374 | bch_prio_write(ca); |
375 | } | ||
397 | } | 376 | } |
398 | } | 377 | } |
399 | 378 | ||
379 | /* Allocation */ | ||
380 | |||
400 | long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait) | 381 | long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait) |
401 | { | 382 | { |
402 | DEFINE_WAIT(w); | 383 | DEFINE_WAIT(w); |
@@ -408,8 +389,10 @@ long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait) | |||
408 | fifo_pop(&ca->free[reserve], r)) | 389 | fifo_pop(&ca->free[reserve], r)) |
409 | goto out; | 390 | goto out; |
410 | 391 | ||
411 | if (!wait) | 392 | if (!wait) { |
393 | trace_bcache_alloc_fail(ca, reserve); | ||
412 | return -1; | 394 | return -1; |
395 | } | ||
413 | 396 | ||
414 | do { | 397 | do { |
415 | prepare_to_wait(&ca->set->bucket_wait, &w, | 398 | prepare_to_wait(&ca->set->bucket_wait, &w, |
@@ -425,6 +408,8 @@ long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait) | |||
425 | out: | 408 | out: |
426 | wake_up_process(ca->alloc_thread); | 409 | wake_up_process(ca->alloc_thread); |
427 | 410 | ||
411 | trace_bcache_alloc(ca, reserve); | ||
412 | |||
428 | if (expensive_debug_checks(ca->set)) { | 413 | if (expensive_debug_checks(ca->set)) { |
429 | size_t iter; | 414 | size_t iter; |
430 | long i; | 415 | long i; |
@@ -438,8 +423,6 @@ out: | |||
438 | BUG_ON(i == r); | 423 | BUG_ON(i == r); |
439 | fifo_for_each(i, &ca->free_inc, iter) | 424 | fifo_for_each(i, &ca->free_inc, iter) |
440 | BUG_ON(i == r); | 425 | BUG_ON(i == r); |
441 | fifo_for_each(i, &ca->unused, iter) | ||
442 | BUG_ON(i == r); | ||
443 | } | 426 | } |
444 | 427 | ||
445 | b = ca->buckets + r; | 428 | b = ca->buckets + r; |
@@ -461,17 +444,19 @@ out: | |||
461 | return r; | 444 | return r; |
462 | } | 445 | } |
463 | 446 | ||
447 | void __bch_bucket_free(struct cache *ca, struct bucket *b) | ||
448 | { | ||
449 | SET_GC_MARK(b, 0); | ||
450 | SET_GC_SECTORS_USED(b, 0); | ||
451 | } | ||
452 | |||
464 | void bch_bucket_free(struct cache_set *c, struct bkey *k) | 453 | void bch_bucket_free(struct cache_set *c, struct bkey *k) |
465 | { | 454 | { |
466 | unsigned i; | 455 | unsigned i; |
467 | 456 | ||
468 | for (i = 0; i < KEY_PTRS(k); i++) { | 457 | for (i = 0; i < KEY_PTRS(k); i++) |
469 | struct bucket *b = PTR_BUCKET(c, k, i); | 458 | __bch_bucket_free(PTR_CACHE(c, k, i), |
470 | 459 | PTR_BUCKET(c, k, i)); | |
471 | SET_GC_MARK(b, GC_MARK_RECLAIMABLE); | ||
472 | SET_GC_SECTORS_USED(b, 0); | ||
473 | bch_bucket_add_unused(PTR_CACHE(c, k, i), b); | ||
474 | } | ||
475 | } | 460 | } |
476 | 461 | ||
477 | int __bch_bucket_alloc_set(struct cache_set *c, unsigned reserve, | 462 | int __bch_bucket_alloc_set(struct cache_set *c, unsigned reserve, |
@@ -709,25 +694,3 @@ int bch_cache_allocator_start(struct cache *ca) | |||
709 | ca->alloc_thread = k; | 694 | ca->alloc_thread = k; |
710 | return 0; | 695 | return 0; |
711 | } | 696 | } |
712 | |||
713 | int bch_cache_allocator_init(struct cache *ca) | ||
714 | { | ||
715 | /* | ||
716 | * Reserve: | ||
717 | * Prio/gen writes first | ||
718 | * Then 8 for btree allocations | ||
719 | * Then half for the moving garbage collector | ||
720 | */ | ||
721 | #if 0 | ||
722 | ca->watermark[WATERMARK_PRIO] = 0; | ||
723 | |||
724 | ca->watermark[WATERMARK_METADATA] = prio_buckets(ca); | ||
725 | |||
726 | ca->watermark[WATERMARK_MOVINGGC] = 8 + | ||
727 | ca->watermark[WATERMARK_METADATA]; | ||
728 | |||
729 | ca->watermark[WATERMARK_NONE] = ca->free.size / 2 + | ||
730 | ca->watermark[WATERMARK_MOVINGGC]; | ||
731 | #endif | ||
732 | return 0; | ||
733 | } | ||
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index a4c7306ff43d..82c9c5d35251 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
@@ -195,9 +195,7 @@ struct bucket { | |||
195 | atomic_t pin; | 195 | atomic_t pin; |
196 | uint16_t prio; | 196 | uint16_t prio; |
197 | uint8_t gen; | 197 | uint8_t gen; |
198 | uint8_t disk_gen; | ||
199 | uint8_t last_gc; /* Most out of date gen in the btree */ | 198 | uint8_t last_gc; /* Most out of date gen in the btree */ |
200 | uint8_t gc_gen; | ||
201 | uint16_t gc_mark; /* Bitfield used by GC. See below for field */ | 199 | uint16_t gc_mark; /* Bitfield used by GC. See below for field */ |
202 | }; | 200 | }; |
203 | 201 | ||
@@ -207,9 +205,9 @@ struct bucket { | |||
207 | */ | 205 | */ |
208 | 206 | ||
209 | BITMASK(GC_MARK, struct bucket, gc_mark, 0, 2); | 207 | BITMASK(GC_MARK, struct bucket, gc_mark, 0, 2); |
210 | #define GC_MARK_RECLAIMABLE 0 | 208 | #define GC_MARK_RECLAIMABLE 1 |
211 | #define GC_MARK_DIRTY 1 | 209 | #define GC_MARK_DIRTY 2 |
212 | #define GC_MARK_METADATA 2 | 210 | #define GC_MARK_METADATA 3 |
213 | #define GC_SECTORS_USED_SIZE 13 | 211 | #define GC_SECTORS_USED_SIZE 13 |
214 | #define MAX_GC_SECTORS_USED (~(~0ULL << GC_SECTORS_USED_SIZE)) | 212 | #define MAX_GC_SECTORS_USED (~(~0ULL << GC_SECTORS_USED_SIZE)) |
215 | BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, GC_SECTORS_USED_SIZE); | 213 | BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, GC_SECTORS_USED_SIZE); |
@@ -426,14 +424,9 @@ struct cache { | |||
426 | * their new gen to disk. After prio_write() finishes writing the new | 424 | * their new gen to disk. After prio_write() finishes writing the new |
427 | * gens/prios, they'll be moved to the free list (and possibly discarded | 425 | * gens/prios, they'll be moved to the free list (and possibly discarded |
428 | * in the process) | 426 | * in the process) |
429 | * | ||
430 | * unused: GC found nothing pointing into these buckets (possibly | ||
431 | * because all the data they contained was overwritten), so we only | ||
432 | * need to discard them before they can be moved to the free list. | ||
433 | */ | 427 | */ |
434 | DECLARE_FIFO(long, free)[RESERVE_NR]; | 428 | DECLARE_FIFO(long, free)[RESERVE_NR]; |
435 | DECLARE_FIFO(long, free_inc); | 429 | DECLARE_FIFO(long, free_inc); |
436 | DECLARE_FIFO(long, unused); | ||
437 | 430 | ||
438 | size_t fifo_last_bucket; | 431 | size_t fifo_last_bucket; |
439 | 432 | ||
@@ -443,12 +436,6 @@ struct cache { | |||
443 | DECLARE_HEAP(struct bucket *, heap); | 436 | DECLARE_HEAP(struct bucket *, heap); |
444 | 437 | ||
445 | /* | 438 | /* |
446 | * max(gen - disk_gen) for all buckets. When it gets too big we have to | ||
447 | * call prio_write() to keep gens from wrapping. | ||
448 | */ | ||
449 | uint8_t need_save_prio; | ||
450 | |||
451 | /* | ||
452 | * If nonzero, we know we aren't going to find any buckets to invalidate | 439 | * If nonzero, we know we aren't going to find any buckets to invalidate |
453 | * until a gc finishes - otherwise we could pointlessly burn a ton of | 440 | * until a gc finishes - otherwise we could pointlessly burn a ton of |
454 | * cpu | 441 | * cpu |
@@ -562,19 +549,16 @@ struct cache_set { | |||
562 | struct list_head btree_cache_freed; | 549 | struct list_head btree_cache_freed; |
563 | 550 | ||
564 | /* Number of elements in btree_cache + btree_cache_freeable lists */ | 551 | /* Number of elements in btree_cache + btree_cache_freeable lists */ |
565 | unsigned bucket_cache_used; | 552 | unsigned btree_cache_used; |
566 | 553 | ||
567 | /* | 554 | /* |
568 | * If we need to allocate memory for a new btree node and that | 555 | * If we need to allocate memory for a new btree node and that |
569 | * allocation fails, we can cannibalize another node in the btree cache | 556 | * allocation fails, we can cannibalize another node in the btree cache |
570 | * to satisfy the allocation. However, only one thread can be doing this | 557 | * to satisfy the allocation - lock to guarantee only one thread does |
571 | * at a time, for obvious reasons - try_harder and try_wait are | 558 | * this at a time: |
572 | * basically a lock for this that we can wait on asynchronously. The | ||
573 | * btree_root() macro releases the lock when it returns. | ||
574 | */ | 559 | */ |
575 | struct task_struct *try_harder; | 560 | wait_queue_head_t btree_cache_wait; |
576 | wait_queue_head_t try_wait; | 561 | struct task_struct *btree_cache_alloc_lock; |
577 | uint64_t try_harder_start; | ||
578 | 562 | ||
579 | /* | 563 | /* |
580 | * When we free a btree node, we increment the gen of the bucket the | 564 | * When we free a btree node, we increment the gen of the bucket the |
@@ -603,7 +587,7 @@ struct cache_set { | |||
603 | uint16_t min_prio; | 587 | uint16_t min_prio; |
604 | 588 | ||
605 | /* | 589 | /* |
606 | * max(gen - gc_gen) for all buckets. When it gets too big we have to gc | 590 | * max(gen - last_gc) for all buckets. When it gets too big we have to gc |
607 | * to keep gens from wrapping around. | 591 | * to keep gens from wrapping around. |
608 | */ | 592 | */ |
609 | uint8_t need_gc; | 593 | uint8_t need_gc; |
@@ -628,6 +612,8 @@ struct cache_set { | |||
628 | /* Number of moving GC bios in flight */ | 612 | /* Number of moving GC bios in flight */ |
629 | struct semaphore moving_in_flight; | 613 | struct semaphore moving_in_flight; |
630 | 614 | ||
615 | struct workqueue_struct *moving_gc_wq; | ||
616 | |||
631 | struct btree *root; | 617 | struct btree *root; |
632 | 618 | ||
633 | #ifdef CONFIG_BCACHE_DEBUG | 619 | #ifdef CONFIG_BCACHE_DEBUG |
@@ -667,7 +653,6 @@ struct cache_set { | |||
667 | struct time_stats btree_gc_time; | 653 | struct time_stats btree_gc_time; |
668 | struct time_stats btree_split_time; | 654 | struct time_stats btree_split_time; |
669 | struct time_stats btree_read_time; | 655 | struct time_stats btree_read_time; |
670 | struct time_stats try_harder_time; | ||
671 | 656 | ||
672 | atomic_long_t cache_read_races; | 657 | atomic_long_t cache_read_races; |
673 | atomic_long_t writeback_keys_done; | 658 | atomic_long_t writeback_keys_done; |
@@ -850,9 +835,6 @@ static inline bool cached_dev_get(struct cached_dev *dc) | |||
850 | /* | 835 | /* |
851 | * bucket_gc_gen() returns the difference between the bucket's current gen and | 836 | * bucket_gc_gen() returns the difference between the bucket's current gen and |
852 | * the oldest gen of any pointer into that bucket in the btree (last_gc). | 837 | * the oldest gen of any pointer into that bucket in the btree (last_gc). |
853 | * | ||
854 | * bucket_disk_gen() returns the difference between the current gen and the gen | ||
855 | * on disk; they're both used to make sure gens don't wrap around. | ||
856 | */ | 838 | */ |
857 | 839 | ||
858 | static inline uint8_t bucket_gc_gen(struct bucket *b) | 840 | static inline uint8_t bucket_gc_gen(struct bucket *b) |
@@ -860,13 +842,7 @@ static inline uint8_t bucket_gc_gen(struct bucket *b) | |||
860 | return b->gen - b->last_gc; | 842 | return b->gen - b->last_gc; |
861 | } | 843 | } |
862 | 844 | ||
863 | static inline uint8_t bucket_disk_gen(struct bucket *b) | ||
864 | { | ||
865 | return b->gen - b->disk_gen; | ||
866 | } | ||
867 | |||
868 | #define BUCKET_GC_GEN_MAX 96U | 845 | #define BUCKET_GC_GEN_MAX 96U |
869 | #define BUCKET_DISK_GEN_MAX 64U | ||
870 | 846 | ||
871 | #define kobj_attribute_write(n, fn) \ | 847 | #define kobj_attribute_write(n, fn) \ |
872 | static struct kobj_attribute ksysfs_##n = __ATTR(n, S_IWUSR, NULL, fn) | 848 | static struct kobj_attribute ksysfs_##n = __ATTR(n, S_IWUSR, NULL, fn) |
@@ -899,11 +875,14 @@ void bch_submit_bbio(struct bio *, struct cache_set *, struct bkey *, unsigned); | |||
899 | 875 | ||
900 | uint8_t bch_inc_gen(struct cache *, struct bucket *); | 876 | uint8_t bch_inc_gen(struct cache *, struct bucket *); |
901 | void bch_rescale_priorities(struct cache_set *, int); | 877 | void bch_rescale_priorities(struct cache_set *, int); |
902 | bool bch_bucket_add_unused(struct cache *, struct bucket *); | ||
903 | 878 | ||
904 | long bch_bucket_alloc(struct cache *, unsigned, bool); | 879 | bool bch_can_invalidate_bucket(struct cache *, struct bucket *); |
880 | void __bch_invalidate_one_bucket(struct cache *, struct bucket *); | ||
881 | |||
882 | void __bch_bucket_free(struct cache *, struct bucket *); | ||
905 | void bch_bucket_free(struct cache_set *, struct bkey *); | 883 | void bch_bucket_free(struct cache_set *, struct bkey *); |
906 | 884 | ||
885 | long bch_bucket_alloc(struct cache *, unsigned, bool); | ||
907 | int __bch_bucket_alloc_set(struct cache_set *, unsigned, | 886 | int __bch_bucket_alloc_set(struct cache_set *, unsigned, |
908 | struct bkey *, int, bool); | 887 | struct bkey *, int, bool); |
909 | int bch_bucket_alloc_set(struct cache_set *, unsigned, | 888 | int bch_bucket_alloc_set(struct cache_set *, unsigned, |
@@ -954,13 +933,10 @@ int bch_open_buckets_alloc(struct cache_set *); | |||
954 | void bch_open_buckets_free(struct cache_set *); | 933 | void bch_open_buckets_free(struct cache_set *); |
955 | 934 | ||
956 | int bch_cache_allocator_start(struct cache *ca); | 935 | int bch_cache_allocator_start(struct cache *ca); |
957 | int bch_cache_allocator_init(struct cache *ca); | ||
958 | 936 | ||
959 | void bch_debug_exit(void); | 937 | void bch_debug_exit(void); |
960 | int bch_debug_init(struct kobject *); | 938 | int bch_debug_init(struct kobject *); |
961 | void bch_request_exit(void); | 939 | void bch_request_exit(void); |
962 | int bch_request_init(void); | 940 | int bch_request_init(void); |
963 | void bch_btree_exit(void); | ||
964 | int bch_btree_init(void); | ||
965 | 941 | ||
966 | #endif /* _BCACHE_H */ | 942 | #endif /* _BCACHE_H */ |
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index 3f74b4b0747b..545416415305 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c | |||
@@ -23,8 +23,8 @@ void bch_dump_bset(struct btree_keys *b, struct bset *i, unsigned set) | |||
23 | for (k = i->start; k < bset_bkey_last(i); k = next) { | 23 | for (k = i->start; k < bset_bkey_last(i); k = next) { |
24 | next = bkey_next(k); | 24 | next = bkey_next(k); |
25 | 25 | ||
26 | printk(KERN_ERR "block %u key %li/%u: ", set, | 26 | printk(KERN_ERR "block %u key %u/%u: ", set, |
27 | (uint64_t *) k - i->d, i->keys); | 27 | (unsigned) ((u64 *) k - i->d), i->keys); |
28 | 28 | ||
29 | if (b->ops->key_dump) | 29 | if (b->ops->key_dump) |
30 | b->ops->key_dump(b, k); | 30 | b->ops->key_dump(b, k); |
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h index 003260f4ddf6..5f6728d5d4dd 100644 --- a/drivers/md/bcache/bset.h +++ b/drivers/md/bcache/bset.h | |||
@@ -478,6 +478,12 @@ static inline void bch_keylist_init(struct keylist *l) | |||
478 | l->top_p = l->keys_p = l->inline_keys; | 478 | l->top_p = l->keys_p = l->inline_keys; |
479 | } | 479 | } |
480 | 480 | ||
481 | static inline void bch_keylist_init_single(struct keylist *l, struct bkey *k) | ||
482 | { | ||
483 | l->keys = k; | ||
484 | l->top = bkey_next(k); | ||
485 | } | ||
486 | |||
481 | static inline void bch_keylist_push(struct keylist *l) | 487 | static inline void bch_keylist_push(struct keylist *l) |
482 | { | 488 | { |
483 | l->top = bkey_next(l->top); | 489 | l->top = bkey_next(l->top); |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 5f9c2a665ca5..7347b6100961 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -68,15 +68,11 @@ | |||
68 | * alloc_bucket() cannot fail. This should be true but is not completely | 68 | * alloc_bucket() cannot fail. This should be true but is not completely |
69 | * obvious. | 69 | * obvious. |
70 | * | 70 | * |
71 | * Make sure all allocations get charged to the root cgroup | ||
72 | * | ||
73 | * Plugging? | 71 | * Plugging? |
74 | * | 72 | * |
75 | * If data write is less than hard sector size of ssd, round up offset in open | 73 | * If data write is less than hard sector size of ssd, round up offset in open |
76 | * bucket to the next whole sector | 74 | * bucket to the next whole sector |
77 | * | 75 | * |
78 | * Also lookup by cgroup in get_open_bucket() | ||
79 | * | ||
80 | * Superblock needs to be fleshed out for multiple cache devices | 76 | * Superblock needs to be fleshed out for multiple cache devices |
81 | * | 77 | * |
82 | * Add a sysfs tunable for the number of writeback IOs in flight | 78 | * Add a sysfs tunable for the number of writeback IOs in flight |
@@ -97,8 +93,6 @@ | |||
97 | #define PTR_HASH(c, k) \ | 93 | #define PTR_HASH(c, k) \ |
98 | (((k)->ptr[0] >> c->bucket_bits) | PTR_GEN(k, 0)) | 94 | (((k)->ptr[0] >> c->bucket_bits) | PTR_GEN(k, 0)) |
99 | 95 | ||
100 | static struct workqueue_struct *btree_io_wq; | ||
101 | |||
102 | #define insert_lock(s, b) ((b)->level <= (s)->lock) | 96 | #define insert_lock(s, b) ((b)->level <= (s)->lock) |
103 | 97 | ||
104 | /* | 98 | /* |
@@ -123,7 +117,7 @@ static struct workqueue_struct *btree_io_wq; | |||
123 | ({ \ | 117 | ({ \ |
124 | int _r, l = (b)->level - 1; \ | 118 | int _r, l = (b)->level - 1; \ |
125 | bool _w = l <= (op)->lock; \ | 119 | bool _w = l <= (op)->lock; \ |
126 | struct btree *_child = bch_btree_node_get((b)->c, key, l, _w); \ | 120 | struct btree *_child = bch_btree_node_get((b)->c, op, key, l, _w);\ |
127 | if (!IS_ERR(_child)) { \ | 121 | if (!IS_ERR(_child)) { \ |
128 | _child->parent = (b); \ | 122 | _child->parent = (b); \ |
129 | _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \ | 123 | _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \ |
@@ -152,17 +146,12 @@ static struct workqueue_struct *btree_io_wq; | |||
152 | _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \ | 146 | _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \ |
153 | } \ | 147 | } \ |
154 | rw_unlock(_w, _b); \ | 148 | rw_unlock(_w, _b); \ |
149 | bch_cannibalize_unlock(c); \ | ||
155 | if (_r == -EINTR) \ | 150 | if (_r == -EINTR) \ |
156 | schedule(); \ | 151 | schedule(); \ |
157 | bch_cannibalize_unlock(c); \ | ||
158 | if (_r == -ENOSPC) { \ | ||
159 | wait_event((c)->try_wait, \ | ||
160 | !(c)->try_harder); \ | ||
161 | _r = -EINTR; \ | ||
162 | } \ | ||
163 | } while (_r == -EINTR); \ | 152 | } while (_r == -EINTR); \ |
164 | \ | 153 | \ |
165 | finish_wait(&(c)->bucket_wait, &(op)->wait); \ | 154 | finish_wait(&(c)->btree_cache_wait, &(op)->wait); \ |
166 | _r; \ | 155 | _r; \ |
167 | }) | 156 | }) |
168 | 157 | ||
@@ -171,6 +160,20 @@ static inline struct bset *write_block(struct btree *b) | |||
171 | return ((void *) btree_bset_first(b)) + b->written * block_bytes(b->c); | 160 | return ((void *) btree_bset_first(b)) + b->written * block_bytes(b->c); |
172 | } | 161 | } |
173 | 162 | ||
163 | static void bch_btree_init_next(struct btree *b) | ||
164 | { | ||
165 | /* If not a leaf node, always sort */ | ||
166 | if (b->level && b->keys.nsets) | ||
167 | bch_btree_sort(&b->keys, &b->c->sort); | ||
168 | else | ||
169 | bch_btree_sort_lazy(&b->keys, &b->c->sort); | ||
170 | |||
171 | if (b->written < btree_blocks(b)) | ||
172 | bch_bset_init_next(&b->keys, write_block(b), | ||
173 | bset_magic(&b->c->sb)); | ||
174 | |||
175 | } | ||
176 | |||
174 | /* Btree key manipulation */ | 177 | /* Btree key manipulation */ |
175 | 178 | ||
176 | void bkey_put(struct cache_set *c, struct bkey *k) | 179 | void bkey_put(struct cache_set *c, struct bkey *k) |
@@ -352,8 +355,7 @@ static void __btree_node_write_done(struct closure *cl) | |||
352 | btree_complete_write(b, w); | 355 | btree_complete_write(b, w); |
353 | 356 | ||
354 | if (btree_node_dirty(b)) | 357 | if (btree_node_dirty(b)) |
355 | queue_delayed_work(btree_io_wq, &b->work, | 358 | schedule_delayed_work(&b->work, 30 * HZ); |
356 | msecs_to_jiffies(30000)); | ||
357 | 359 | ||
358 | closure_return_with_destructor(cl, btree_node_write_unlock); | 360 | closure_return_with_destructor(cl, btree_node_write_unlock); |
359 | } | 361 | } |
@@ -442,10 +444,12 @@ static void do_btree_node_write(struct btree *b) | |||
442 | } | 444 | } |
443 | } | 445 | } |
444 | 446 | ||
445 | void bch_btree_node_write(struct btree *b, struct closure *parent) | 447 | void __bch_btree_node_write(struct btree *b, struct closure *parent) |
446 | { | 448 | { |
447 | struct bset *i = btree_bset_last(b); | 449 | struct bset *i = btree_bset_last(b); |
448 | 450 | ||
451 | lockdep_assert_held(&b->write_lock); | ||
452 | |||
449 | trace_bcache_btree_write(b); | 453 | trace_bcache_btree_write(b); |
450 | 454 | ||
451 | BUG_ON(current->bio_list); | 455 | BUG_ON(current->bio_list); |
@@ -469,23 +473,24 @@ void bch_btree_node_write(struct btree *b, struct closure *parent) | |||
469 | &PTR_CACHE(b->c, &b->key, 0)->btree_sectors_written); | 473 | &PTR_CACHE(b->c, &b->key, 0)->btree_sectors_written); |
470 | 474 | ||
471 | b->written += set_blocks(i, block_bytes(b->c)); | 475 | b->written += set_blocks(i, block_bytes(b->c)); |
476 | } | ||
472 | 477 | ||
473 | /* If not a leaf node, always sort */ | 478 | void bch_btree_node_write(struct btree *b, struct closure *parent) |
474 | if (b->level && b->keys.nsets) | 479 | { |
475 | bch_btree_sort(&b->keys, &b->c->sort); | 480 | unsigned nsets = b->keys.nsets; |
476 | else | 481 | |
477 | bch_btree_sort_lazy(&b->keys, &b->c->sort); | 482 | lockdep_assert_held(&b->lock); |
483 | |||
484 | __bch_btree_node_write(b, parent); | ||
478 | 485 | ||
479 | /* | 486 | /* |
480 | * do verify if there was more than one set initially (i.e. we did a | 487 | * do verify if there was more than one set initially (i.e. we did a |
481 | * sort) and we sorted down to a single set: | 488 | * sort) and we sorted down to a single set: |
482 | */ | 489 | */ |
483 | if (i != b->keys.set->data && !b->keys.nsets) | 490 | if (nsets && !b->keys.nsets) |
484 | bch_btree_verify(b); | 491 | bch_btree_verify(b); |
485 | 492 | ||
486 | if (b->written < btree_blocks(b)) | 493 | bch_btree_init_next(b); |
487 | bch_bset_init_next(&b->keys, write_block(b), | ||
488 | bset_magic(&b->c->sb)); | ||
489 | } | 494 | } |
490 | 495 | ||
491 | static void bch_btree_node_write_sync(struct btree *b) | 496 | static void bch_btree_node_write_sync(struct btree *b) |
@@ -493,7 +498,11 @@ static void bch_btree_node_write_sync(struct btree *b) | |||
493 | struct closure cl; | 498 | struct closure cl; |
494 | 499 | ||
495 | closure_init_stack(&cl); | 500 | closure_init_stack(&cl); |
501 | |||
502 | mutex_lock(&b->write_lock); | ||
496 | bch_btree_node_write(b, &cl); | 503 | bch_btree_node_write(b, &cl); |
504 | mutex_unlock(&b->write_lock); | ||
505 | |||
497 | closure_sync(&cl); | 506 | closure_sync(&cl); |
498 | } | 507 | } |
499 | 508 | ||
@@ -501,11 +510,10 @@ static void btree_node_write_work(struct work_struct *w) | |||
501 | { | 510 | { |
502 | struct btree *b = container_of(to_delayed_work(w), struct btree, work); | 511 | struct btree *b = container_of(to_delayed_work(w), struct btree, work); |
503 | 512 | ||
504 | rw_lock(true, b, b->level); | 513 | mutex_lock(&b->write_lock); |
505 | |||
506 | if (btree_node_dirty(b)) | 514 | if (btree_node_dirty(b)) |
507 | bch_btree_node_write(b, NULL); | 515 | __bch_btree_node_write(b, NULL); |
508 | rw_unlock(true, b); | 516 | mutex_unlock(&b->write_lock); |
509 | } | 517 | } |
510 | 518 | ||
511 | static void bch_btree_leaf_dirty(struct btree *b, atomic_t *journal_ref) | 519 | static void bch_btree_leaf_dirty(struct btree *b, atomic_t *journal_ref) |
@@ -513,11 +521,13 @@ static void bch_btree_leaf_dirty(struct btree *b, atomic_t *journal_ref) | |||
513 | struct bset *i = btree_bset_last(b); | 521 | struct bset *i = btree_bset_last(b); |
514 | struct btree_write *w = btree_current_write(b); | 522 | struct btree_write *w = btree_current_write(b); |
515 | 523 | ||
524 | lockdep_assert_held(&b->write_lock); | ||
525 | |||
516 | BUG_ON(!b->written); | 526 | BUG_ON(!b->written); |
517 | BUG_ON(!i->keys); | 527 | BUG_ON(!i->keys); |
518 | 528 | ||
519 | if (!btree_node_dirty(b)) | 529 | if (!btree_node_dirty(b)) |
520 | queue_delayed_work(btree_io_wq, &b->work, 30 * HZ); | 530 | schedule_delayed_work(&b->work, 30 * HZ); |
521 | 531 | ||
522 | set_btree_node_dirty(b); | 532 | set_btree_node_dirty(b); |
523 | 533 | ||
@@ -548,7 +558,7 @@ static void bch_btree_leaf_dirty(struct btree *b, atomic_t *journal_ref) | |||
548 | #define mca_reserve(c) (((c->root && c->root->level) \ | 558 | #define mca_reserve(c) (((c->root && c->root->level) \ |
549 | ? c->root->level : 1) * 8 + 16) | 559 | ? c->root->level : 1) * 8 + 16) |
550 | #define mca_can_free(c) \ | 560 | #define mca_can_free(c) \ |
551 | max_t(int, 0, c->bucket_cache_used - mca_reserve(c)) | 561 | max_t(int, 0, c->btree_cache_used - mca_reserve(c)) |
552 | 562 | ||
553 | static void mca_data_free(struct btree *b) | 563 | static void mca_data_free(struct btree *b) |
554 | { | 564 | { |
@@ -556,7 +566,7 @@ static void mca_data_free(struct btree *b) | |||
556 | 566 | ||
557 | bch_btree_keys_free(&b->keys); | 567 | bch_btree_keys_free(&b->keys); |
558 | 568 | ||
559 | b->c->bucket_cache_used--; | 569 | b->c->btree_cache_used--; |
560 | list_move(&b->list, &b->c->btree_cache_freed); | 570 | list_move(&b->list, &b->c->btree_cache_freed); |
561 | } | 571 | } |
562 | 572 | ||
@@ -581,7 +591,7 @@ static void mca_data_alloc(struct btree *b, struct bkey *k, gfp_t gfp) | |||
581 | ilog2(b->c->btree_pages), | 591 | ilog2(b->c->btree_pages), |
582 | btree_order(k)), | 592 | btree_order(k)), |
583 | gfp)) { | 593 | gfp)) { |
584 | b->c->bucket_cache_used++; | 594 | b->c->btree_cache_used++; |
585 | list_move(&b->list, &b->c->btree_cache); | 595 | list_move(&b->list, &b->c->btree_cache); |
586 | } else { | 596 | } else { |
587 | list_move(&b->list, &b->c->btree_cache_freed); | 597 | list_move(&b->list, &b->c->btree_cache_freed); |
@@ -597,6 +607,8 @@ static struct btree *mca_bucket_alloc(struct cache_set *c, | |||
597 | 607 | ||
598 | init_rwsem(&b->lock); | 608 | init_rwsem(&b->lock); |
599 | lockdep_set_novalidate_class(&b->lock); | 609 | lockdep_set_novalidate_class(&b->lock); |
610 | mutex_init(&b->write_lock); | ||
611 | lockdep_set_novalidate_class(&b->write_lock); | ||
600 | INIT_LIST_HEAD(&b->list); | 612 | INIT_LIST_HEAD(&b->list); |
601 | INIT_DELAYED_WORK(&b->work, btree_node_write_work); | 613 | INIT_DELAYED_WORK(&b->work, btree_node_write_work); |
602 | b->c = c; | 614 | b->c = c; |
@@ -630,8 +642,12 @@ static int mca_reap(struct btree *b, unsigned min_order, bool flush) | |||
630 | up(&b->io_mutex); | 642 | up(&b->io_mutex); |
631 | } | 643 | } |
632 | 644 | ||
645 | mutex_lock(&b->write_lock); | ||
633 | if (btree_node_dirty(b)) | 646 | if (btree_node_dirty(b)) |
634 | bch_btree_node_write_sync(b); | 647 | __bch_btree_node_write(b, &cl); |
648 | mutex_unlock(&b->write_lock); | ||
649 | |||
650 | closure_sync(&cl); | ||
635 | 651 | ||
636 | /* wait for any in flight btree write */ | 652 | /* wait for any in flight btree write */ |
637 | down(&b->io_mutex); | 653 | down(&b->io_mutex); |
@@ -654,7 +670,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, | |||
654 | if (c->shrinker_disabled) | 670 | if (c->shrinker_disabled) |
655 | return SHRINK_STOP; | 671 | return SHRINK_STOP; |
656 | 672 | ||
657 | if (c->try_harder) | 673 | if (c->btree_cache_alloc_lock) |
658 | return SHRINK_STOP; | 674 | return SHRINK_STOP; |
659 | 675 | ||
660 | /* Return -1 if we can't do anything right now */ | 676 | /* Return -1 if we can't do anything right now */ |
@@ -686,7 +702,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, | |||
686 | } | 702 | } |
687 | } | 703 | } |
688 | 704 | ||
689 | for (i = 0; (nr--) && i < c->bucket_cache_used; i++) { | 705 | for (i = 0; (nr--) && i < c->btree_cache_used; i++) { |
690 | if (list_empty(&c->btree_cache)) | 706 | if (list_empty(&c->btree_cache)) |
691 | goto out; | 707 | goto out; |
692 | 708 | ||
@@ -715,7 +731,7 @@ static unsigned long bch_mca_count(struct shrinker *shrink, | |||
715 | if (c->shrinker_disabled) | 731 | if (c->shrinker_disabled) |
716 | return 0; | 732 | return 0; |
717 | 733 | ||
718 | if (c->try_harder) | 734 | if (c->btree_cache_alloc_lock) |
719 | return 0; | 735 | return 0; |
720 | 736 | ||
721 | return mca_can_free(c) * c->btree_pages; | 737 | return mca_can_free(c) * c->btree_pages; |
@@ -819,17 +835,30 @@ out: | |||
819 | return b; | 835 | return b; |
820 | } | 836 | } |
821 | 837 | ||
822 | static struct btree *mca_cannibalize(struct cache_set *c, struct bkey *k) | 838 | static int mca_cannibalize_lock(struct cache_set *c, struct btree_op *op) |
839 | { | ||
840 | struct task_struct *old; | ||
841 | |||
842 | old = cmpxchg(&c->btree_cache_alloc_lock, NULL, current); | ||
843 | if (old && old != current) { | ||
844 | if (op) | ||
845 | prepare_to_wait(&c->btree_cache_wait, &op->wait, | ||
846 | TASK_UNINTERRUPTIBLE); | ||
847 | return -EINTR; | ||
848 | } | ||
849 | |||
850 | return 0; | ||
851 | } | ||
852 | |||
853 | static struct btree *mca_cannibalize(struct cache_set *c, struct btree_op *op, | ||
854 | struct bkey *k) | ||
823 | { | 855 | { |
824 | struct btree *b; | 856 | struct btree *b; |
825 | 857 | ||
826 | trace_bcache_btree_cache_cannibalize(c); | 858 | trace_bcache_btree_cache_cannibalize(c); |
827 | 859 | ||
828 | if (!c->try_harder) { | 860 | if (mca_cannibalize_lock(c, op)) |
829 | c->try_harder = current; | 861 | return ERR_PTR(-EINTR); |
830 | c->try_harder_start = local_clock(); | ||
831 | } else if (c->try_harder != current) | ||
832 | return ERR_PTR(-ENOSPC); | ||
833 | 862 | ||
834 | list_for_each_entry_reverse(b, &c->btree_cache, list) | 863 | list_for_each_entry_reverse(b, &c->btree_cache, list) |
835 | if (!mca_reap(b, btree_order(k), false)) | 864 | if (!mca_reap(b, btree_order(k), false)) |
@@ -839,6 +868,7 @@ static struct btree *mca_cannibalize(struct cache_set *c, struct bkey *k) | |||
839 | if (!mca_reap(b, btree_order(k), true)) | 868 | if (!mca_reap(b, btree_order(k), true)) |
840 | return b; | 869 | return b; |
841 | 870 | ||
871 | WARN(1, "btree cache cannibalize failed\n"); | ||
842 | return ERR_PTR(-ENOMEM); | 872 | return ERR_PTR(-ENOMEM); |
843 | } | 873 | } |
844 | 874 | ||
@@ -850,14 +880,14 @@ static struct btree *mca_cannibalize(struct cache_set *c, struct bkey *k) | |||
850 | */ | 880 | */ |
851 | static void bch_cannibalize_unlock(struct cache_set *c) | 881 | static void bch_cannibalize_unlock(struct cache_set *c) |
852 | { | 882 | { |
853 | if (c->try_harder == current) { | 883 | if (c->btree_cache_alloc_lock == current) { |
854 | bch_time_stats_update(&c->try_harder_time, c->try_harder_start); | 884 | c->btree_cache_alloc_lock = NULL; |
855 | c->try_harder = NULL; | 885 | wake_up(&c->btree_cache_wait); |
856 | wake_up(&c->try_wait); | ||
857 | } | 886 | } |
858 | } | 887 | } |
859 | 888 | ||
860 | static struct btree *mca_alloc(struct cache_set *c, struct bkey *k, int level) | 889 | static struct btree *mca_alloc(struct cache_set *c, struct btree_op *op, |
890 | struct bkey *k, int level) | ||
861 | { | 891 | { |
862 | struct btree *b; | 892 | struct btree *b; |
863 | 893 | ||
@@ -920,7 +950,7 @@ err: | |||
920 | if (b) | 950 | if (b) |
921 | rw_unlock(true, b); | 951 | rw_unlock(true, b); |
922 | 952 | ||
923 | b = mca_cannibalize(c, k); | 953 | b = mca_cannibalize(c, op, k); |
924 | if (!IS_ERR(b)) | 954 | if (!IS_ERR(b)) |
925 | goto out; | 955 | goto out; |
926 | 956 | ||
@@ -936,8 +966,8 @@ err: | |||
936 | * The btree node will have either a read or a write lock held, depending on | 966 | * The btree node will have either a read or a write lock held, depending on |
937 | * level and op->lock. | 967 | * level and op->lock. |
938 | */ | 968 | */ |
939 | struct btree *bch_btree_node_get(struct cache_set *c, struct bkey *k, | 969 | struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op, |
940 | int level, bool write) | 970 | struct bkey *k, int level, bool write) |
941 | { | 971 | { |
942 | int i = 0; | 972 | int i = 0; |
943 | struct btree *b; | 973 | struct btree *b; |
@@ -951,7 +981,7 @@ retry: | |||
951 | return ERR_PTR(-EAGAIN); | 981 | return ERR_PTR(-EAGAIN); |
952 | 982 | ||
953 | mutex_lock(&c->bucket_lock); | 983 | mutex_lock(&c->bucket_lock); |
954 | b = mca_alloc(c, k, level); | 984 | b = mca_alloc(c, op, k, level); |
955 | mutex_unlock(&c->bucket_lock); | 985 | mutex_unlock(&c->bucket_lock); |
956 | 986 | ||
957 | if (!b) | 987 | if (!b) |
@@ -997,7 +1027,7 @@ static void btree_node_prefetch(struct cache_set *c, struct bkey *k, int level) | |||
997 | struct btree *b; | 1027 | struct btree *b; |
998 | 1028 | ||
999 | mutex_lock(&c->bucket_lock); | 1029 | mutex_lock(&c->bucket_lock); |
1000 | b = mca_alloc(c, k, level); | 1030 | b = mca_alloc(c, NULL, k, level); |
1001 | mutex_unlock(&c->bucket_lock); | 1031 | mutex_unlock(&c->bucket_lock); |
1002 | 1032 | ||
1003 | if (!IS_ERR_OR_NULL(b)) { | 1033 | if (!IS_ERR_OR_NULL(b)) { |
@@ -1010,46 +1040,41 @@ static void btree_node_prefetch(struct cache_set *c, struct bkey *k, int level) | |||
1010 | 1040 | ||
1011 | static void btree_node_free(struct btree *b) | 1041 | static void btree_node_free(struct btree *b) |
1012 | { | 1042 | { |
1013 | unsigned i; | ||
1014 | |||
1015 | trace_bcache_btree_node_free(b); | 1043 | trace_bcache_btree_node_free(b); |
1016 | 1044 | ||
1017 | BUG_ON(b == b->c->root); | 1045 | BUG_ON(b == b->c->root); |
1018 | 1046 | ||
1047 | mutex_lock(&b->write_lock); | ||
1048 | |||
1019 | if (btree_node_dirty(b)) | 1049 | if (btree_node_dirty(b)) |
1020 | btree_complete_write(b, btree_current_write(b)); | 1050 | btree_complete_write(b, btree_current_write(b)); |
1021 | clear_bit(BTREE_NODE_dirty, &b->flags); | 1051 | clear_bit(BTREE_NODE_dirty, &b->flags); |
1022 | 1052 | ||
1053 | mutex_unlock(&b->write_lock); | ||
1054 | |||
1023 | cancel_delayed_work(&b->work); | 1055 | cancel_delayed_work(&b->work); |
1024 | 1056 | ||
1025 | mutex_lock(&b->c->bucket_lock); | 1057 | mutex_lock(&b->c->bucket_lock); |
1026 | |||
1027 | for (i = 0; i < KEY_PTRS(&b->key); i++) { | ||
1028 | BUG_ON(atomic_read(&PTR_BUCKET(b->c, &b->key, i)->pin)); | ||
1029 | |||
1030 | bch_inc_gen(PTR_CACHE(b->c, &b->key, i), | ||
1031 | PTR_BUCKET(b->c, &b->key, i)); | ||
1032 | } | ||
1033 | |||
1034 | bch_bucket_free(b->c, &b->key); | 1058 | bch_bucket_free(b->c, &b->key); |
1035 | mca_bucket_free(b); | 1059 | mca_bucket_free(b); |
1036 | mutex_unlock(&b->c->bucket_lock); | 1060 | mutex_unlock(&b->c->bucket_lock); |
1037 | } | 1061 | } |
1038 | 1062 | ||
1039 | struct btree *bch_btree_node_alloc(struct cache_set *c, int level, bool wait) | 1063 | struct btree *bch_btree_node_alloc(struct cache_set *c, struct btree_op *op, |
1064 | int level) | ||
1040 | { | 1065 | { |
1041 | BKEY_PADDED(key) k; | 1066 | BKEY_PADDED(key) k; |
1042 | struct btree *b = ERR_PTR(-EAGAIN); | 1067 | struct btree *b = ERR_PTR(-EAGAIN); |
1043 | 1068 | ||
1044 | mutex_lock(&c->bucket_lock); | 1069 | mutex_lock(&c->bucket_lock); |
1045 | retry: | 1070 | retry: |
1046 | if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait)) | 1071 | if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, op != NULL)) |
1047 | goto err; | 1072 | goto err; |
1048 | 1073 | ||
1049 | bkey_put(c, &k.key); | 1074 | bkey_put(c, &k.key); |
1050 | SET_KEY_SIZE(&k.key, c->btree_pages * PAGE_SECTORS); | 1075 | SET_KEY_SIZE(&k.key, c->btree_pages * PAGE_SECTORS); |
1051 | 1076 | ||
1052 | b = mca_alloc(c, &k.key, level); | 1077 | b = mca_alloc(c, op, &k.key, level); |
1053 | if (IS_ERR(b)) | 1078 | if (IS_ERR(b)) |
1054 | goto err_free; | 1079 | goto err_free; |
1055 | 1080 | ||
@@ -1075,12 +1100,15 @@ err: | |||
1075 | return b; | 1100 | return b; |
1076 | } | 1101 | } |
1077 | 1102 | ||
1078 | static struct btree *btree_node_alloc_replacement(struct btree *b, bool wait) | 1103 | static struct btree *btree_node_alloc_replacement(struct btree *b, |
1104 | struct btree_op *op) | ||
1079 | { | 1105 | { |
1080 | struct btree *n = bch_btree_node_alloc(b->c, b->level, wait); | 1106 | struct btree *n = bch_btree_node_alloc(b->c, op, b->level); |
1081 | if (!IS_ERR_OR_NULL(n)) { | 1107 | if (!IS_ERR_OR_NULL(n)) { |
1108 | mutex_lock(&n->write_lock); | ||
1082 | bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); | 1109 | bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); |
1083 | bkey_copy_key(&n->key, &b->key); | 1110 | bkey_copy_key(&n->key, &b->key); |
1111 | mutex_unlock(&n->write_lock); | ||
1084 | } | 1112 | } |
1085 | 1113 | ||
1086 | return n; | 1114 | return n; |
@@ -1090,43 +1118,47 @@ static void make_btree_freeing_key(struct btree *b, struct bkey *k) | |||
1090 | { | 1118 | { |
1091 | unsigned i; | 1119 | unsigned i; |
1092 | 1120 | ||
1121 | mutex_lock(&b->c->bucket_lock); | ||
1122 | |||
1123 | atomic_inc(&b->c->prio_blocked); | ||
1124 | |||
1093 | bkey_copy(k, &b->key); | 1125 | bkey_copy(k, &b->key); |
1094 | bkey_copy_key(k, &ZERO_KEY); | 1126 | bkey_copy_key(k, &ZERO_KEY); |
1095 | 1127 | ||
1096 | for (i = 0; i < KEY_PTRS(k); i++) { | 1128 | for (i = 0; i < KEY_PTRS(k); i++) |
1097 | uint8_t g = PTR_BUCKET(b->c, k, i)->gen + 1; | 1129 | SET_PTR_GEN(k, i, |
1098 | 1130 | bch_inc_gen(PTR_CACHE(b->c, &b->key, i), | |
1099 | SET_PTR_GEN(k, i, g); | 1131 | PTR_BUCKET(b->c, &b->key, i))); |
1100 | } | ||
1101 | 1132 | ||
1102 | atomic_inc(&b->c->prio_blocked); | 1133 | mutex_unlock(&b->c->bucket_lock); |
1103 | } | 1134 | } |
1104 | 1135 | ||
1105 | static int btree_check_reserve(struct btree *b, struct btree_op *op) | 1136 | static int btree_check_reserve(struct btree *b, struct btree_op *op) |
1106 | { | 1137 | { |
1107 | struct cache_set *c = b->c; | 1138 | struct cache_set *c = b->c; |
1108 | struct cache *ca; | 1139 | struct cache *ca; |
1109 | unsigned i, reserve = c->root->level * 2 + 1; | 1140 | unsigned i, reserve = (c->root->level - b->level) * 2 + 1; |
1110 | int ret = 0; | ||
1111 | 1141 | ||
1112 | mutex_lock(&c->bucket_lock); | 1142 | mutex_lock(&c->bucket_lock); |
1113 | 1143 | ||
1114 | for_each_cache(ca, c, i) | 1144 | for_each_cache(ca, c, i) |
1115 | if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) { | 1145 | if (fifo_used(&ca->free[RESERVE_BTREE]) < reserve) { |
1116 | if (op) | 1146 | if (op) |
1117 | prepare_to_wait(&c->bucket_wait, &op->wait, | 1147 | prepare_to_wait(&c->btree_cache_wait, &op->wait, |
1118 | TASK_UNINTERRUPTIBLE); | 1148 | TASK_UNINTERRUPTIBLE); |
1119 | ret = -EINTR; | 1149 | mutex_unlock(&c->bucket_lock); |
1120 | break; | 1150 | return -EINTR; |
1121 | } | 1151 | } |
1122 | 1152 | ||
1123 | mutex_unlock(&c->bucket_lock); | 1153 | mutex_unlock(&c->bucket_lock); |
1124 | return ret; | 1154 | |
1155 | return mca_cannibalize_lock(b->c, op); | ||
1125 | } | 1156 | } |
1126 | 1157 | ||
1127 | /* Garbage collection */ | 1158 | /* Garbage collection */ |
1128 | 1159 | ||
1129 | uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k) | 1160 | static uint8_t __bch_btree_mark_key(struct cache_set *c, int level, |
1161 | struct bkey *k) | ||
1130 | { | 1162 | { |
1131 | uint8_t stale = 0; | 1163 | uint8_t stale = 0; |
1132 | unsigned i; | 1164 | unsigned i; |
@@ -1146,8 +1178,8 @@ uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k) | |||
1146 | 1178 | ||
1147 | g = PTR_BUCKET(c, k, i); | 1179 | g = PTR_BUCKET(c, k, i); |
1148 | 1180 | ||
1149 | if (gen_after(g->gc_gen, PTR_GEN(k, i))) | 1181 | if (gen_after(g->last_gc, PTR_GEN(k, i))) |
1150 | g->gc_gen = PTR_GEN(k, i); | 1182 | g->last_gc = PTR_GEN(k, i); |
1151 | 1183 | ||
1152 | if (ptr_stale(c, k, i)) { | 1184 | if (ptr_stale(c, k, i)) { |
1153 | stale = max(stale, ptr_stale(c, k, i)); | 1185 | stale = max(stale, ptr_stale(c, k, i)); |
@@ -1163,6 +1195,8 @@ uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k) | |||
1163 | SET_GC_MARK(g, GC_MARK_METADATA); | 1195 | SET_GC_MARK(g, GC_MARK_METADATA); |
1164 | else if (KEY_DIRTY(k)) | 1196 | else if (KEY_DIRTY(k)) |
1165 | SET_GC_MARK(g, GC_MARK_DIRTY); | 1197 | SET_GC_MARK(g, GC_MARK_DIRTY); |
1198 | else if (!GC_MARK(g)) | ||
1199 | SET_GC_MARK(g, GC_MARK_RECLAIMABLE); | ||
1166 | 1200 | ||
1167 | /* guard against overflow */ | 1201 | /* guard against overflow */ |
1168 | SET_GC_SECTORS_USED(g, min_t(unsigned, | 1202 | SET_GC_SECTORS_USED(g, min_t(unsigned, |
@@ -1177,6 +1211,26 @@ uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k) | |||
1177 | 1211 | ||
1178 | #define btree_mark_key(b, k) __bch_btree_mark_key(b->c, b->level, k) | 1212 | #define btree_mark_key(b, k) __bch_btree_mark_key(b->c, b->level, k) |
1179 | 1213 | ||
1214 | void bch_initial_mark_key(struct cache_set *c, int level, struct bkey *k) | ||
1215 | { | ||
1216 | unsigned i; | ||
1217 | |||
1218 | for (i = 0; i < KEY_PTRS(k); i++) | ||
1219 | if (ptr_available(c, k, i) && | ||
1220 | !ptr_stale(c, k, i)) { | ||
1221 | struct bucket *b = PTR_BUCKET(c, k, i); | ||
1222 | |||
1223 | b->gen = PTR_GEN(k, i); | ||
1224 | |||
1225 | if (level && bkey_cmp(k, &ZERO_KEY)) | ||
1226 | b->prio = BTREE_PRIO; | ||
1227 | else if (!level && b->prio == BTREE_PRIO) | ||
1228 | b->prio = INITIAL_PRIO; | ||
1229 | } | ||
1230 | |||
1231 | __bch_btree_mark_key(c, level, k); | ||
1232 | } | ||
1233 | |||
1180 | static bool btree_gc_mark_node(struct btree *b, struct gc_stat *gc) | 1234 | static bool btree_gc_mark_node(struct btree *b, struct gc_stat *gc) |
1181 | { | 1235 | { |
1182 | uint8_t stale = 0; | 1236 | uint8_t stale = 0; |
@@ -1230,14 +1284,19 @@ static int bch_btree_insert_node(struct btree *, struct btree_op *, | |||
1230 | struct keylist *, atomic_t *, struct bkey *); | 1284 | struct keylist *, atomic_t *, struct bkey *); |
1231 | 1285 | ||
1232 | static int btree_gc_coalesce(struct btree *b, struct btree_op *op, | 1286 | static int btree_gc_coalesce(struct btree *b, struct btree_op *op, |
1233 | struct keylist *keylist, struct gc_stat *gc, | 1287 | struct gc_stat *gc, struct gc_merge_info *r) |
1234 | struct gc_merge_info *r) | ||
1235 | { | 1288 | { |
1236 | unsigned i, nodes = 0, keys = 0, blocks; | 1289 | unsigned i, nodes = 0, keys = 0, blocks; |
1237 | struct btree *new_nodes[GC_MERGE_NODES]; | 1290 | struct btree *new_nodes[GC_MERGE_NODES]; |
1291 | struct keylist keylist; | ||
1238 | struct closure cl; | 1292 | struct closure cl; |
1239 | struct bkey *k; | 1293 | struct bkey *k; |
1240 | 1294 | ||
1295 | bch_keylist_init(&keylist); | ||
1296 | |||
1297 | if (btree_check_reserve(b, NULL)) | ||
1298 | return 0; | ||
1299 | |||
1241 | memset(new_nodes, 0, sizeof(new_nodes)); | 1300 | memset(new_nodes, 0, sizeof(new_nodes)); |
1242 | closure_init_stack(&cl); | 1301 | closure_init_stack(&cl); |
1243 | 1302 | ||
@@ -1252,11 +1311,23 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, | |||
1252 | return 0; | 1311 | return 0; |
1253 | 1312 | ||
1254 | for (i = 0; i < nodes; i++) { | 1313 | for (i = 0; i < nodes; i++) { |
1255 | new_nodes[i] = btree_node_alloc_replacement(r[i].b, false); | 1314 | new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL); |
1256 | if (IS_ERR_OR_NULL(new_nodes[i])) | 1315 | if (IS_ERR_OR_NULL(new_nodes[i])) |
1257 | goto out_nocoalesce; | 1316 | goto out_nocoalesce; |
1258 | } | 1317 | } |
1259 | 1318 | ||
1319 | /* | ||
1320 | * We have to check the reserve here, after we've allocated our new | ||
1321 | * nodes, to make sure the insert below will succeed - we also check | ||
1322 | * before as an optimization to potentially avoid a bunch of expensive | ||
1323 | * allocs/sorts | ||
1324 | */ | ||
1325 | if (btree_check_reserve(b, NULL)) | ||
1326 | goto out_nocoalesce; | ||
1327 | |||
1328 | for (i = 0; i < nodes; i++) | ||
1329 | mutex_lock(&new_nodes[i]->write_lock); | ||
1330 | |||
1260 | for (i = nodes - 1; i > 0; --i) { | 1331 | for (i = nodes - 1; i > 0; --i) { |
1261 | struct bset *n1 = btree_bset_first(new_nodes[i]); | 1332 | struct bset *n1 = btree_bset_first(new_nodes[i]); |
1262 | struct bset *n2 = btree_bset_first(new_nodes[i - 1]); | 1333 | struct bset *n2 = btree_bset_first(new_nodes[i - 1]); |
@@ -1315,28 +1386,34 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, | |||
1315 | 1386 | ||
1316 | n2->keys -= keys; | 1387 | n2->keys -= keys; |
1317 | 1388 | ||
1318 | if (__bch_keylist_realloc(keylist, | 1389 | if (__bch_keylist_realloc(&keylist, |
1319 | bkey_u64s(&new_nodes[i]->key))) | 1390 | bkey_u64s(&new_nodes[i]->key))) |
1320 | goto out_nocoalesce; | 1391 | goto out_nocoalesce; |
1321 | 1392 | ||
1322 | bch_btree_node_write(new_nodes[i], &cl); | 1393 | bch_btree_node_write(new_nodes[i], &cl); |
1323 | bch_keylist_add(keylist, &new_nodes[i]->key); | 1394 | bch_keylist_add(&keylist, &new_nodes[i]->key); |
1324 | } | 1395 | } |
1325 | 1396 | ||
1326 | for (i = 0; i < nodes; i++) { | 1397 | for (i = 0; i < nodes; i++) |
1327 | if (__bch_keylist_realloc(keylist, bkey_u64s(&r[i].b->key))) | 1398 | mutex_unlock(&new_nodes[i]->write_lock); |
1328 | goto out_nocoalesce; | ||
1329 | 1399 | ||
1330 | make_btree_freeing_key(r[i].b, keylist->top); | 1400 | closure_sync(&cl); |
1331 | bch_keylist_push(keylist); | ||
1332 | } | ||
1333 | 1401 | ||
1334 | /* We emptied out this node */ | 1402 | /* We emptied out this node */ |
1335 | BUG_ON(btree_bset_first(new_nodes[0])->keys); | 1403 | BUG_ON(btree_bset_first(new_nodes[0])->keys); |
1336 | btree_node_free(new_nodes[0]); | 1404 | btree_node_free(new_nodes[0]); |
1337 | rw_unlock(true, new_nodes[0]); | 1405 | rw_unlock(true, new_nodes[0]); |
1338 | 1406 | ||
1339 | closure_sync(&cl); | 1407 | for (i = 0; i < nodes; i++) { |
1408 | if (__bch_keylist_realloc(&keylist, bkey_u64s(&r[i].b->key))) | ||
1409 | goto out_nocoalesce; | ||
1410 | |||
1411 | make_btree_freeing_key(r[i].b, keylist.top); | ||
1412 | bch_keylist_push(&keylist); | ||
1413 | } | ||
1414 | |||
1415 | bch_btree_insert_node(b, op, &keylist, NULL, NULL); | ||
1416 | BUG_ON(!bch_keylist_empty(&keylist)); | ||
1340 | 1417 | ||
1341 | for (i = 0; i < nodes; i++) { | 1418 | for (i = 0; i < nodes; i++) { |
1342 | btree_node_free(r[i].b); | 1419 | btree_node_free(r[i].b); |
@@ -1345,22 +1422,22 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, | |||
1345 | r[i].b = new_nodes[i]; | 1422 | r[i].b = new_nodes[i]; |
1346 | } | 1423 | } |
1347 | 1424 | ||
1348 | bch_btree_insert_node(b, op, keylist, NULL, NULL); | ||
1349 | BUG_ON(!bch_keylist_empty(keylist)); | ||
1350 | |||
1351 | memmove(r, r + 1, sizeof(r[0]) * (nodes - 1)); | 1425 | memmove(r, r + 1, sizeof(r[0]) * (nodes - 1)); |
1352 | r[nodes - 1].b = ERR_PTR(-EINTR); | 1426 | r[nodes - 1].b = ERR_PTR(-EINTR); |
1353 | 1427 | ||
1354 | trace_bcache_btree_gc_coalesce(nodes); | 1428 | trace_bcache_btree_gc_coalesce(nodes); |
1355 | gc->nodes--; | 1429 | gc->nodes--; |
1356 | 1430 | ||
1431 | bch_keylist_free(&keylist); | ||
1432 | |||
1357 | /* Invalidated our iterator */ | 1433 | /* Invalidated our iterator */ |
1358 | return -EINTR; | 1434 | return -EINTR; |
1359 | 1435 | ||
1360 | out_nocoalesce: | 1436 | out_nocoalesce: |
1361 | closure_sync(&cl); | 1437 | closure_sync(&cl); |
1438 | bch_keylist_free(&keylist); | ||
1362 | 1439 | ||
1363 | while ((k = bch_keylist_pop(keylist))) | 1440 | while ((k = bch_keylist_pop(&keylist))) |
1364 | if (!bkey_cmp(k, &ZERO_KEY)) | 1441 | if (!bkey_cmp(k, &ZERO_KEY)) |
1365 | atomic_dec(&b->c->prio_blocked); | 1442 | atomic_dec(&b->c->prio_blocked); |
1366 | 1443 | ||
@@ -1372,6 +1449,42 @@ out_nocoalesce: | |||
1372 | return 0; | 1449 | return 0; |
1373 | } | 1450 | } |
1374 | 1451 | ||
1452 | static int btree_gc_rewrite_node(struct btree *b, struct btree_op *op, | ||
1453 | struct btree *replace) | ||
1454 | { | ||
1455 | struct keylist keys; | ||
1456 | struct btree *n; | ||
1457 | |||
1458 | if (btree_check_reserve(b, NULL)) | ||
1459 | return 0; | ||
1460 | |||
1461 | n = btree_node_alloc_replacement(replace, NULL); | ||
1462 | |||
1463 | /* recheck reserve after allocating replacement node */ | ||
1464 | if (btree_check_reserve(b, NULL)) { | ||
1465 | btree_node_free(n); | ||
1466 | rw_unlock(true, n); | ||
1467 | return 0; | ||
1468 | } | ||
1469 | |||
1470 | bch_btree_node_write_sync(n); | ||
1471 | |||
1472 | bch_keylist_init(&keys); | ||
1473 | bch_keylist_add(&keys, &n->key); | ||
1474 | |||
1475 | make_btree_freeing_key(replace, keys.top); | ||
1476 | bch_keylist_push(&keys); | ||
1477 | |||
1478 | bch_btree_insert_node(b, op, &keys, NULL, NULL); | ||
1479 | BUG_ON(!bch_keylist_empty(&keys)); | ||
1480 | |||
1481 | btree_node_free(replace); | ||
1482 | rw_unlock(true, n); | ||
1483 | |||
1484 | /* Invalidated our iterator */ | ||
1485 | return -EINTR; | ||
1486 | } | ||
1487 | |||
1375 | static unsigned btree_gc_count_keys(struct btree *b) | 1488 | static unsigned btree_gc_count_keys(struct btree *b) |
1376 | { | 1489 | { |
1377 | struct bkey *k; | 1490 | struct bkey *k; |
@@ -1387,26 +1500,23 @@ static unsigned btree_gc_count_keys(struct btree *b) | |||
1387 | static int btree_gc_recurse(struct btree *b, struct btree_op *op, | 1500 | static int btree_gc_recurse(struct btree *b, struct btree_op *op, |
1388 | struct closure *writes, struct gc_stat *gc) | 1501 | struct closure *writes, struct gc_stat *gc) |
1389 | { | 1502 | { |
1390 | unsigned i; | ||
1391 | int ret = 0; | 1503 | int ret = 0; |
1392 | bool should_rewrite; | 1504 | bool should_rewrite; |
1393 | struct btree *n; | ||
1394 | struct bkey *k; | 1505 | struct bkey *k; |
1395 | struct keylist keys; | ||
1396 | struct btree_iter iter; | 1506 | struct btree_iter iter; |
1397 | struct gc_merge_info r[GC_MERGE_NODES]; | 1507 | struct gc_merge_info r[GC_MERGE_NODES]; |
1398 | struct gc_merge_info *last = r + GC_MERGE_NODES - 1; | 1508 | struct gc_merge_info *i, *last = r + ARRAY_SIZE(r) - 1; |
1399 | 1509 | ||
1400 | bch_keylist_init(&keys); | ||
1401 | bch_btree_iter_init(&b->keys, &iter, &b->c->gc_done); | 1510 | bch_btree_iter_init(&b->keys, &iter, &b->c->gc_done); |
1402 | 1511 | ||
1403 | for (i = 0; i < GC_MERGE_NODES; i++) | 1512 | for (i = r; i < r + ARRAY_SIZE(r); i++) |
1404 | r[i].b = ERR_PTR(-EINTR); | 1513 | i->b = ERR_PTR(-EINTR); |
1405 | 1514 | ||
1406 | while (1) { | 1515 | while (1) { |
1407 | k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad); | 1516 | k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad); |
1408 | if (k) { | 1517 | if (k) { |
1409 | r->b = bch_btree_node_get(b->c, k, b->level - 1, true); | 1518 | r->b = bch_btree_node_get(b->c, op, k, b->level - 1, |
1519 | true); | ||
1410 | if (IS_ERR(r->b)) { | 1520 | if (IS_ERR(r->b)) { |
1411 | ret = PTR_ERR(r->b); | 1521 | ret = PTR_ERR(r->b); |
1412 | break; | 1522 | break; |
@@ -1414,7 +1524,7 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, | |||
1414 | 1524 | ||
1415 | r->keys = btree_gc_count_keys(r->b); | 1525 | r->keys = btree_gc_count_keys(r->b); |
1416 | 1526 | ||
1417 | ret = btree_gc_coalesce(b, op, &keys, gc, r); | 1527 | ret = btree_gc_coalesce(b, op, gc, r); |
1418 | if (ret) | 1528 | if (ret) |
1419 | break; | 1529 | break; |
1420 | } | 1530 | } |
@@ -1424,32 +1534,10 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, | |||
1424 | 1534 | ||
1425 | if (!IS_ERR(last->b)) { | 1535 | if (!IS_ERR(last->b)) { |
1426 | should_rewrite = btree_gc_mark_node(last->b, gc); | 1536 | should_rewrite = btree_gc_mark_node(last->b, gc); |
1427 | if (should_rewrite && | 1537 | if (should_rewrite) { |
1428 | !btree_check_reserve(b, NULL)) { | 1538 | ret = btree_gc_rewrite_node(b, op, last->b); |
1429 | n = btree_node_alloc_replacement(last->b, | 1539 | if (ret) |
1430 | false); | ||
1431 | |||
1432 | if (!IS_ERR_OR_NULL(n)) { | ||
1433 | bch_btree_node_write_sync(n); | ||
1434 | bch_keylist_add(&keys, &n->key); | ||
1435 | |||
1436 | make_btree_freeing_key(last->b, | ||
1437 | keys.top); | ||
1438 | bch_keylist_push(&keys); | ||
1439 | |||
1440 | btree_node_free(last->b); | ||
1441 | |||
1442 | bch_btree_insert_node(b, op, &keys, | ||
1443 | NULL, NULL); | ||
1444 | BUG_ON(!bch_keylist_empty(&keys)); | ||
1445 | |||
1446 | rw_unlock(true, last->b); | ||
1447 | last->b = n; | ||
1448 | |||
1449 | /* Invalidated our iterator */ | ||
1450 | ret = -EINTR; | ||
1451 | break; | 1540 | break; |
1452 | } | ||
1453 | } | 1541 | } |
1454 | 1542 | ||
1455 | if (last->b->level) { | 1543 | if (last->b->level) { |
@@ -1464,8 +1552,10 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, | |||
1464 | * Must flush leaf nodes before gc ends, since replace | 1552 | * Must flush leaf nodes before gc ends, since replace |
1465 | * operations aren't journalled | 1553 | * operations aren't journalled |
1466 | */ | 1554 | */ |
1555 | mutex_lock(&last->b->write_lock); | ||
1467 | if (btree_node_dirty(last->b)) | 1556 | if (btree_node_dirty(last->b)) |
1468 | bch_btree_node_write(last->b, writes); | 1557 | bch_btree_node_write(last->b, writes); |
1558 | mutex_unlock(&last->b->write_lock); | ||
1469 | rw_unlock(true, last->b); | 1559 | rw_unlock(true, last->b); |
1470 | } | 1560 | } |
1471 | 1561 | ||
@@ -1478,15 +1568,15 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, | |||
1478 | } | 1568 | } |
1479 | } | 1569 | } |
1480 | 1570 | ||
1481 | for (i = 0; i < GC_MERGE_NODES; i++) | 1571 | for (i = r; i < r + ARRAY_SIZE(r); i++) |
1482 | if (!IS_ERR_OR_NULL(r[i].b)) { | 1572 | if (!IS_ERR_OR_NULL(i->b)) { |
1483 | if (btree_node_dirty(r[i].b)) | 1573 | mutex_lock(&i->b->write_lock); |
1484 | bch_btree_node_write(r[i].b, writes); | 1574 | if (btree_node_dirty(i->b)) |
1485 | rw_unlock(true, r[i].b); | 1575 | bch_btree_node_write(i->b, writes); |
1576 | mutex_unlock(&i->b->write_lock); | ||
1577 | rw_unlock(true, i->b); | ||
1486 | } | 1578 | } |
1487 | 1579 | ||
1488 | bch_keylist_free(&keys); | ||
1489 | |||
1490 | return ret; | 1580 | return ret; |
1491 | } | 1581 | } |
1492 | 1582 | ||
@@ -1499,10 +1589,11 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op, | |||
1499 | 1589 | ||
1500 | should_rewrite = btree_gc_mark_node(b, gc); | 1590 | should_rewrite = btree_gc_mark_node(b, gc); |
1501 | if (should_rewrite) { | 1591 | if (should_rewrite) { |
1502 | n = btree_node_alloc_replacement(b, false); | 1592 | n = btree_node_alloc_replacement(b, NULL); |
1503 | 1593 | ||
1504 | if (!IS_ERR_OR_NULL(n)) { | 1594 | if (!IS_ERR_OR_NULL(n)) { |
1505 | bch_btree_node_write_sync(n); | 1595 | bch_btree_node_write_sync(n); |
1596 | |||
1506 | bch_btree_set_root(n); | 1597 | bch_btree_set_root(n); |
1507 | btree_node_free(b); | 1598 | btree_node_free(b); |
1508 | rw_unlock(true, n); | 1599 | rw_unlock(true, n); |
@@ -1511,6 +1602,8 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op, | |||
1511 | } | 1602 | } |
1512 | } | 1603 | } |
1513 | 1604 | ||
1605 | __bch_btree_mark_key(b->c, b->level + 1, &b->key); | ||
1606 | |||
1514 | if (b->level) { | 1607 | if (b->level) { |
1515 | ret = btree_gc_recurse(b, op, writes, gc); | 1608 | ret = btree_gc_recurse(b, op, writes, gc); |
1516 | if (ret) | 1609 | if (ret) |
@@ -1538,9 +1631,9 @@ static void btree_gc_start(struct cache_set *c) | |||
1538 | 1631 | ||
1539 | for_each_cache(ca, c, i) | 1632 | for_each_cache(ca, c, i) |
1540 | for_each_bucket(b, ca) { | 1633 | for_each_bucket(b, ca) { |
1541 | b->gc_gen = b->gen; | 1634 | b->last_gc = b->gen; |
1542 | if (!atomic_read(&b->pin)) { | 1635 | if (!atomic_read(&b->pin)) { |
1543 | SET_GC_MARK(b, GC_MARK_RECLAIMABLE); | 1636 | SET_GC_MARK(b, 0); |
1544 | SET_GC_SECTORS_USED(b, 0); | 1637 | SET_GC_SECTORS_USED(b, 0); |
1545 | } | 1638 | } |
1546 | } | 1639 | } |
@@ -1548,7 +1641,7 @@ static void btree_gc_start(struct cache_set *c) | |||
1548 | mutex_unlock(&c->bucket_lock); | 1641 | mutex_unlock(&c->bucket_lock); |
1549 | } | 1642 | } |
1550 | 1643 | ||
1551 | size_t bch_btree_gc_finish(struct cache_set *c) | 1644 | static size_t bch_btree_gc_finish(struct cache_set *c) |
1552 | { | 1645 | { |
1553 | size_t available = 0; | 1646 | size_t available = 0; |
1554 | struct bucket *b; | 1647 | struct bucket *b; |
@@ -1561,11 +1654,6 @@ size_t bch_btree_gc_finish(struct cache_set *c) | |||
1561 | c->gc_mark_valid = 1; | 1654 | c->gc_mark_valid = 1; |
1562 | c->need_gc = 0; | 1655 | c->need_gc = 0; |
1563 | 1656 | ||
1564 | if (c->root) | ||
1565 | for (i = 0; i < KEY_PTRS(&c->root->key); i++) | ||
1566 | SET_GC_MARK(PTR_BUCKET(c, &c->root->key, i), | ||
1567 | GC_MARK_METADATA); | ||
1568 | |||
1569 | for (i = 0; i < KEY_PTRS(&c->uuid_bucket); i++) | 1657 | for (i = 0; i < KEY_PTRS(&c->uuid_bucket); i++) |
1570 | SET_GC_MARK(PTR_BUCKET(c, &c->uuid_bucket, i), | 1658 | SET_GC_MARK(PTR_BUCKET(c, &c->uuid_bucket, i), |
1571 | GC_MARK_METADATA); | 1659 | GC_MARK_METADATA); |
@@ -1605,15 +1693,15 @@ size_t bch_btree_gc_finish(struct cache_set *c) | |||
1605 | SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA); | 1693 | SET_GC_MARK(ca->buckets + *i, GC_MARK_METADATA); |
1606 | 1694 | ||
1607 | for_each_bucket(b, ca) { | 1695 | for_each_bucket(b, ca) { |
1608 | b->last_gc = b->gc_gen; | ||
1609 | c->need_gc = max(c->need_gc, bucket_gc_gen(b)); | 1696 | c->need_gc = max(c->need_gc, bucket_gc_gen(b)); |
1610 | 1697 | ||
1611 | if (!atomic_read(&b->pin) && | 1698 | if (atomic_read(&b->pin)) |
1612 | GC_MARK(b) == GC_MARK_RECLAIMABLE) { | 1699 | continue; |
1700 | |||
1701 | BUG_ON(!GC_MARK(b) && GC_SECTORS_USED(b)); | ||
1702 | |||
1703 | if (!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE) | ||
1613 | available++; | 1704 | available++; |
1614 | if (!GC_SECTORS_USED(b)) | ||
1615 | bch_bucket_add_unused(ca, b); | ||
1616 | } | ||
1617 | } | 1705 | } |
1618 | } | 1706 | } |
1619 | 1707 | ||
@@ -1705,36 +1793,16 @@ int bch_gc_thread_start(struct cache_set *c) | |||
1705 | 1793 | ||
1706 | /* Initial partial gc */ | 1794 | /* Initial partial gc */ |
1707 | 1795 | ||
1708 | static int bch_btree_check_recurse(struct btree *b, struct btree_op *op, | 1796 | static int bch_btree_check_recurse(struct btree *b, struct btree_op *op) |
1709 | unsigned long **seen) | ||
1710 | { | 1797 | { |
1711 | int ret = 0; | 1798 | int ret = 0; |
1712 | unsigned i; | ||
1713 | struct bkey *k, *p = NULL; | 1799 | struct bkey *k, *p = NULL; |
1714 | struct bucket *g; | ||
1715 | struct btree_iter iter; | 1800 | struct btree_iter iter; |
1716 | 1801 | ||
1717 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) { | 1802 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) |
1718 | for (i = 0; i < KEY_PTRS(k); i++) { | 1803 | bch_initial_mark_key(b->c, b->level, k); |
1719 | if (!ptr_available(b->c, k, i)) | ||
1720 | continue; | ||
1721 | |||
1722 | g = PTR_BUCKET(b->c, k, i); | ||
1723 | 1804 | ||
1724 | if (!__test_and_set_bit(PTR_BUCKET_NR(b->c, k, i), | 1805 | bch_initial_mark_key(b->c, b->level + 1, &b->key); |
1725 | seen[PTR_DEV(k, i)]) || | ||
1726 | !ptr_stale(b->c, k, i)) { | ||
1727 | g->gen = PTR_GEN(k, i); | ||
1728 | |||
1729 | if (b->level) | ||
1730 | g->prio = BTREE_PRIO; | ||
1731 | else if (g->prio == BTREE_PRIO) | ||
1732 | g->prio = INITIAL_PRIO; | ||
1733 | } | ||
1734 | } | ||
1735 | |||
1736 | btree_mark_key(b, k); | ||
1737 | } | ||
1738 | 1806 | ||
1739 | if (b->level) { | 1807 | if (b->level) { |
1740 | bch_btree_iter_init(&b->keys, &iter, NULL); | 1808 | bch_btree_iter_init(&b->keys, &iter, NULL); |
@@ -1746,40 +1814,58 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op, | |||
1746 | btree_node_prefetch(b->c, k, b->level - 1); | 1814 | btree_node_prefetch(b->c, k, b->level - 1); |
1747 | 1815 | ||
1748 | if (p) | 1816 | if (p) |
1749 | ret = btree(check_recurse, p, b, op, seen); | 1817 | ret = btree(check_recurse, p, b, op); |
1750 | 1818 | ||
1751 | p = k; | 1819 | p = k; |
1752 | } while (p && !ret); | 1820 | } while (p && !ret); |
1753 | } | 1821 | } |
1754 | 1822 | ||
1755 | return 0; | 1823 | return ret; |
1756 | } | 1824 | } |
1757 | 1825 | ||
1758 | int bch_btree_check(struct cache_set *c) | 1826 | int bch_btree_check(struct cache_set *c) |
1759 | { | 1827 | { |
1760 | int ret = -ENOMEM; | ||
1761 | unsigned i; | ||
1762 | unsigned long *seen[MAX_CACHES_PER_SET]; | ||
1763 | struct btree_op op; | 1828 | struct btree_op op; |
1764 | 1829 | ||
1765 | memset(seen, 0, sizeof(seen)); | ||
1766 | bch_btree_op_init(&op, SHRT_MAX); | 1830 | bch_btree_op_init(&op, SHRT_MAX); |
1767 | 1831 | ||
1768 | for (i = 0; c->cache[i]; i++) { | 1832 | return btree_root(check_recurse, c, &op); |
1769 | size_t n = DIV_ROUND_UP(c->cache[i]->sb.nbuckets, 8); | 1833 | } |
1770 | seen[i] = kmalloc(n, GFP_KERNEL); | 1834 | |
1771 | if (!seen[i]) | 1835 | void bch_initial_gc_finish(struct cache_set *c) |
1772 | goto err; | 1836 | { |
1837 | struct cache *ca; | ||
1838 | struct bucket *b; | ||
1839 | unsigned i; | ||
1840 | |||
1841 | bch_btree_gc_finish(c); | ||
1773 | 1842 | ||
1774 | /* Disables the seen array until prio_read() uses it too */ | 1843 | mutex_lock(&c->bucket_lock); |
1775 | memset(seen[i], 0xFF, n); | 1844 | |
1845 | /* | ||
1846 | * We need to put some unused buckets directly on the prio freelist in | ||
1847 | * order to get the allocator thread started - it needs freed buckets in | ||
1848 | * order to rewrite the prios and gens, and it needs to rewrite prios | ||
1849 | * and gens in order to free buckets. | ||
1850 | * | ||
1851 | * This is only safe for buckets that have no live data in them, which | ||
1852 | * there should always be some of. | ||
1853 | */ | ||
1854 | for_each_cache(ca, c, i) { | ||
1855 | for_each_bucket(b, ca) { | ||
1856 | if (fifo_full(&ca->free[RESERVE_PRIO])) | ||
1857 | break; | ||
1858 | |||
1859 | if (bch_can_invalidate_bucket(ca, b) && | ||
1860 | !GC_MARK(b)) { | ||
1861 | __bch_invalidate_one_bucket(ca, b); | ||
1862 | fifo_push(&ca->free[RESERVE_PRIO], | ||
1863 | b - ca->buckets); | ||
1864 | } | ||
1865 | } | ||
1776 | } | 1866 | } |
1777 | 1867 | ||
1778 | ret = btree_root(check_recurse, c, &op, seen); | 1868 | mutex_unlock(&c->bucket_lock); |
1779 | err: | ||
1780 | for (i = 0; i < MAX_CACHES_PER_SET; i++) | ||
1781 | kfree(seen[i]); | ||
1782 | return ret; | ||
1783 | } | 1869 | } |
1784 | 1870 | ||
1785 | /* Btree insertion */ | 1871 | /* Btree insertion */ |
@@ -1871,11 +1957,14 @@ static int btree_split(struct btree *b, struct btree_op *op, | |||
1871 | closure_init_stack(&cl); | 1957 | closure_init_stack(&cl); |
1872 | bch_keylist_init(&parent_keys); | 1958 | bch_keylist_init(&parent_keys); |
1873 | 1959 | ||
1874 | if (!b->level && | 1960 | if (btree_check_reserve(b, op)) { |
1875 | btree_check_reserve(b, op)) | 1961 | if (!b->level) |
1876 | return -EINTR; | 1962 | return -EINTR; |
1963 | else | ||
1964 | WARN(1, "insufficient reserve for split\n"); | ||
1965 | } | ||
1877 | 1966 | ||
1878 | n1 = btree_node_alloc_replacement(b, true); | 1967 | n1 = btree_node_alloc_replacement(b, op); |
1879 | if (IS_ERR(n1)) | 1968 | if (IS_ERR(n1)) |
1880 | goto err; | 1969 | goto err; |
1881 | 1970 | ||
@@ -1887,16 +1976,19 @@ static int btree_split(struct btree *b, struct btree_op *op, | |||
1887 | 1976 | ||
1888 | trace_bcache_btree_node_split(b, btree_bset_first(n1)->keys); | 1977 | trace_bcache_btree_node_split(b, btree_bset_first(n1)->keys); |
1889 | 1978 | ||
1890 | n2 = bch_btree_node_alloc(b->c, b->level, true); | 1979 | n2 = bch_btree_node_alloc(b->c, op, b->level); |
1891 | if (IS_ERR(n2)) | 1980 | if (IS_ERR(n2)) |
1892 | goto err_free1; | 1981 | goto err_free1; |
1893 | 1982 | ||
1894 | if (!b->parent) { | 1983 | if (!b->parent) { |
1895 | n3 = bch_btree_node_alloc(b->c, b->level + 1, true); | 1984 | n3 = bch_btree_node_alloc(b->c, op, b->level + 1); |
1896 | if (IS_ERR(n3)) | 1985 | if (IS_ERR(n3)) |
1897 | goto err_free2; | 1986 | goto err_free2; |
1898 | } | 1987 | } |
1899 | 1988 | ||
1989 | mutex_lock(&n1->write_lock); | ||
1990 | mutex_lock(&n2->write_lock); | ||
1991 | |||
1900 | bch_btree_insert_keys(n1, op, insert_keys, replace_key); | 1992 | bch_btree_insert_keys(n1, op, insert_keys, replace_key); |
1901 | 1993 | ||
1902 | /* | 1994 | /* |
@@ -1923,45 +2015,45 @@ static int btree_split(struct btree *b, struct btree_op *op, | |||
1923 | 2015 | ||
1924 | bch_keylist_add(&parent_keys, &n2->key); | 2016 | bch_keylist_add(&parent_keys, &n2->key); |
1925 | bch_btree_node_write(n2, &cl); | 2017 | bch_btree_node_write(n2, &cl); |
2018 | mutex_unlock(&n2->write_lock); | ||
1926 | rw_unlock(true, n2); | 2019 | rw_unlock(true, n2); |
1927 | } else { | 2020 | } else { |
1928 | trace_bcache_btree_node_compact(b, btree_bset_first(n1)->keys); | 2021 | trace_bcache_btree_node_compact(b, btree_bset_first(n1)->keys); |
1929 | 2022 | ||
2023 | mutex_lock(&n1->write_lock); | ||
1930 | bch_btree_insert_keys(n1, op, insert_keys, replace_key); | 2024 | bch_btree_insert_keys(n1, op, insert_keys, replace_key); |
1931 | } | 2025 | } |
1932 | 2026 | ||
1933 | bch_keylist_add(&parent_keys, &n1->key); | 2027 | bch_keylist_add(&parent_keys, &n1->key); |
1934 | bch_btree_node_write(n1, &cl); | 2028 | bch_btree_node_write(n1, &cl); |
2029 | mutex_unlock(&n1->write_lock); | ||
1935 | 2030 | ||
1936 | if (n3) { | 2031 | if (n3) { |
1937 | /* Depth increases, make a new root */ | 2032 | /* Depth increases, make a new root */ |
2033 | mutex_lock(&n3->write_lock); | ||
1938 | bkey_copy_key(&n3->key, &MAX_KEY); | 2034 | bkey_copy_key(&n3->key, &MAX_KEY); |
1939 | bch_btree_insert_keys(n3, op, &parent_keys, NULL); | 2035 | bch_btree_insert_keys(n3, op, &parent_keys, NULL); |
1940 | bch_btree_node_write(n3, &cl); | 2036 | bch_btree_node_write(n3, &cl); |
2037 | mutex_unlock(&n3->write_lock); | ||
1941 | 2038 | ||
1942 | closure_sync(&cl); | 2039 | closure_sync(&cl); |
1943 | bch_btree_set_root(n3); | 2040 | bch_btree_set_root(n3); |
1944 | rw_unlock(true, n3); | 2041 | rw_unlock(true, n3); |
1945 | |||
1946 | btree_node_free(b); | ||
1947 | } else if (!b->parent) { | 2042 | } else if (!b->parent) { |
1948 | /* Root filled up but didn't need to be split */ | 2043 | /* Root filled up but didn't need to be split */ |
1949 | closure_sync(&cl); | 2044 | closure_sync(&cl); |
1950 | bch_btree_set_root(n1); | 2045 | bch_btree_set_root(n1); |
1951 | |||
1952 | btree_node_free(b); | ||
1953 | } else { | 2046 | } else { |
1954 | /* Split a non root node */ | 2047 | /* Split a non root node */ |
1955 | closure_sync(&cl); | 2048 | closure_sync(&cl); |
1956 | make_btree_freeing_key(b, parent_keys.top); | 2049 | make_btree_freeing_key(b, parent_keys.top); |
1957 | bch_keylist_push(&parent_keys); | 2050 | bch_keylist_push(&parent_keys); |
1958 | 2051 | ||
1959 | btree_node_free(b); | ||
1960 | |||
1961 | bch_btree_insert_node(b->parent, op, &parent_keys, NULL, NULL); | 2052 | bch_btree_insert_node(b->parent, op, &parent_keys, NULL, NULL); |
1962 | BUG_ON(!bch_keylist_empty(&parent_keys)); | 2053 | BUG_ON(!bch_keylist_empty(&parent_keys)); |
1963 | } | 2054 | } |
1964 | 2055 | ||
2056 | btree_node_free(b); | ||
1965 | rw_unlock(true, n1); | 2057 | rw_unlock(true, n1); |
1966 | 2058 | ||
1967 | bch_time_stats_update(&b->c->btree_split_time, start_time); | 2059 | bch_time_stats_update(&b->c->btree_split_time, start_time); |
@@ -1976,7 +2068,7 @@ err_free1: | |||
1976 | btree_node_free(n1); | 2068 | btree_node_free(n1); |
1977 | rw_unlock(true, n1); | 2069 | rw_unlock(true, n1); |
1978 | err: | 2070 | err: |
1979 | WARN(1, "bcache: btree split failed"); | 2071 | WARN(1, "bcache: btree split failed (level %u)", b->level); |
1980 | 2072 | ||
1981 | if (n3 == ERR_PTR(-EAGAIN) || | 2073 | if (n3 == ERR_PTR(-EAGAIN) || |
1982 | n2 == ERR_PTR(-EAGAIN) || | 2074 | n2 == ERR_PTR(-EAGAIN) || |
@@ -1991,33 +2083,54 @@ static int bch_btree_insert_node(struct btree *b, struct btree_op *op, | |||
1991 | atomic_t *journal_ref, | 2083 | atomic_t *journal_ref, |
1992 | struct bkey *replace_key) | 2084 | struct bkey *replace_key) |
1993 | { | 2085 | { |
2086 | struct closure cl; | ||
2087 | |||
1994 | BUG_ON(b->level && replace_key); | 2088 | BUG_ON(b->level && replace_key); |
1995 | 2089 | ||
2090 | closure_init_stack(&cl); | ||
2091 | |||
2092 | mutex_lock(&b->write_lock); | ||
2093 | |||
2094 | if (write_block(b) != btree_bset_last(b) && | ||
2095 | b->keys.last_set_unwritten) | ||
2096 | bch_btree_init_next(b); /* just wrote a set */ | ||
2097 | |||
1996 | if (bch_keylist_nkeys(insert_keys) > insert_u64s_remaining(b)) { | 2098 | if (bch_keylist_nkeys(insert_keys) > insert_u64s_remaining(b)) { |
1997 | if (current->bio_list) { | 2099 | mutex_unlock(&b->write_lock); |
1998 | op->lock = b->c->root->level + 1; | 2100 | goto split; |
1999 | return -EAGAIN; | 2101 | } |
2000 | } else if (op->lock <= b->c->root->level) { | ||
2001 | op->lock = b->c->root->level + 1; | ||
2002 | return -EINTR; | ||
2003 | } else { | ||
2004 | /* Invalidated all iterators */ | ||
2005 | int ret = btree_split(b, op, insert_keys, replace_key); | ||
2006 | 2102 | ||
2007 | return bch_keylist_empty(insert_keys) ? | 2103 | BUG_ON(write_block(b) != btree_bset_last(b)); |
2008 | 0 : ret ?: -EINTR; | ||
2009 | } | ||
2010 | } else { | ||
2011 | BUG_ON(write_block(b) != btree_bset_last(b)); | ||
2012 | 2104 | ||
2013 | if (bch_btree_insert_keys(b, op, insert_keys, replace_key)) { | 2105 | if (bch_btree_insert_keys(b, op, insert_keys, replace_key)) { |
2014 | if (!b->level) | 2106 | if (!b->level) |
2015 | bch_btree_leaf_dirty(b, journal_ref); | 2107 | bch_btree_leaf_dirty(b, journal_ref); |
2016 | else | 2108 | else |
2017 | bch_btree_node_write_sync(b); | 2109 | bch_btree_node_write(b, &cl); |
2018 | } | 2110 | } |
2019 | 2111 | ||
2020 | return 0; | 2112 | mutex_unlock(&b->write_lock); |
2113 | |||
2114 | /* wait for btree node write if necessary, after unlock */ | ||
2115 | closure_sync(&cl); | ||
2116 | |||
2117 | return 0; | ||
2118 | split: | ||
2119 | if (current->bio_list) { | ||
2120 | op->lock = b->c->root->level + 1; | ||
2121 | return -EAGAIN; | ||
2122 | } else if (op->lock <= b->c->root->level) { | ||
2123 | op->lock = b->c->root->level + 1; | ||
2124 | return -EINTR; | ||
2125 | } else { | ||
2126 | /* Invalidated all iterators */ | ||
2127 | int ret = btree_split(b, op, insert_keys, replace_key); | ||
2128 | |||
2129 | if (bch_keylist_empty(insert_keys)) | ||
2130 | return 0; | ||
2131 | else if (!ret) | ||
2132 | return -EINTR; | ||
2133 | return ret; | ||
2021 | } | 2134 | } |
2022 | } | 2135 | } |
2023 | 2136 | ||
@@ -2403,18 +2516,3 @@ void bch_keybuf_init(struct keybuf *buf) | |||
2403 | spin_lock_init(&buf->lock); | 2516 | spin_lock_init(&buf->lock); |
2404 | array_allocator_init(&buf->freelist); | 2517 | array_allocator_init(&buf->freelist); |
2405 | } | 2518 | } |
2406 | |||
2407 | void bch_btree_exit(void) | ||
2408 | { | ||
2409 | if (btree_io_wq) | ||
2410 | destroy_workqueue(btree_io_wq); | ||
2411 | } | ||
2412 | |||
2413 | int __init bch_btree_init(void) | ||
2414 | { | ||
2415 | btree_io_wq = create_singlethread_workqueue("bch_btree_io"); | ||
2416 | if (!btree_io_wq) | ||
2417 | return -ENOMEM; | ||
2418 | |||
2419 | return 0; | ||
2420 | } | ||
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h index af065e97e55c..91dfa5e69685 100644 --- a/drivers/md/bcache/btree.h +++ b/drivers/md/bcache/btree.h | |||
@@ -127,6 +127,8 @@ struct btree { | |||
127 | struct cache_set *c; | 127 | struct cache_set *c; |
128 | struct btree *parent; | 128 | struct btree *parent; |
129 | 129 | ||
130 | struct mutex write_lock; | ||
131 | |||
130 | unsigned long flags; | 132 | unsigned long flags; |
131 | uint16_t written; /* would be nice to kill */ | 133 | uint16_t written; /* would be nice to kill */ |
132 | uint8_t level; | 134 | uint8_t level; |
@@ -236,11 +238,13 @@ static inline void rw_unlock(bool w, struct btree *b) | |||
236 | } | 238 | } |
237 | 239 | ||
238 | void bch_btree_node_read_done(struct btree *); | 240 | void bch_btree_node_read_done(struct btree *); |
241 | void __bch_btree_node_write(struct btree *, struct closure *); | ||
239 | void bch_btree_node_write(struct btree *, struct closure *); | 242 | void bch_btree_node_write(struct btree *, struct closure *); |
240 | 243 | ||
241 | void bch_btree_set_root(struct btree *); | 244 | void bch_btree_set_root(struct btree *); |
242 | struct btree *bch_btree_node_alloc(struct cache_set *, int, bool); | 245 | struct btree *bch_btree_node_alloc(struct cache_set *, struct btree_op *, int); |
243 | struct btree *bch_btree_node_get(struct cache_set *, struct bkey *, int, bool); | 246 | struct btree *bch_btree_node_get(struct cache_set *, struct btree_op *, |
247 | struct bkey *, int, bool); | ||
244 | 248 | ||
245 | int bch_btree_insert_check_key(struct btree *, struct btree_op *, | 249 | int bch_btree_insert_check_key(struct btree *, struct btree_op *, |
246 | struct bkey *); | 250 | struct bkey *); |
@@ -248,10 +252,10 @@ int bch_btree_insert(struct cache_set *, struct keylist *, | |||
248 | atomic_t *, struct bkey *); | 252 | atomic_t *, struct bkey *); |
249 | 253 | ||
250 | int bch_gc_thread_start(struct cache_set *); | 254 | int bch_gc_thread_start(struct cache_set *); |
251 | size_t bch_btree_gc_finish(struct cache_set *); | 255 | void bch_initial_gc_finish(struct cache_set *); |
252 | void bch_moving_gc(struct cache_set *); | 256 | void bch_moving_gc(struct cache_set *); |
253 | int bch_btree_check(struct cache_set *); | 257 | int bch_btree_check(struct cache_set *); |
254 | uint8_t __bch_btree_mark_key(struct cache_set *, int, struct bkey *); | 258 | void bch_initial_mark_key(struct cache_set *, int, struct bkey *); |
255 | 259 | ||
256 | static inline void wake_up_gc(struct cache_set *c) | 260 | static inline void wake_up_gc(struct cache_set *c) |
257 | { | 261 | { |
diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c index 416d1a3e028e..3a0de4cf9771 100644 --- a/drivers/md/bcache/extents.c +++ b/drivers/md/bcache/extents.c | |||
@@ -194,9 +194,9 @@ err: | |||
194 | mutex_unlock(&b->c->bucket_lock); | 194 | mutex_unlock(&b->c->bucket_lock); |
195 | bch_extent_to_text(buf, sizeof(buf), k); | 195 | bch_extent_to_text(buf, sizeof(buf), k); |
196 | btree_bug(b, | 196 | btree_bug(b, |
197 | "inconsistent btree pointer %s: bucket %zi pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i", | 197 | "inconsistent btree pointer %s: bucket %zi pin %i prio %i gen %i last_gc %i mark %llu", |
198 | buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin), | 198 | buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin), |
199 | g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen); | 199 | g->prio, g->gen, g->last_gc, GC_MARK(g)); |
200 | return true; | 200 | return true; |
201 | } | 201 | } |
202 | 202 | ||
@@ -308,6 +308,16 @@ static struct bkey *bch_extent_sort_fixup(struct btree_iter *iter, | |||
308 | return NULL; | 308 | return NULL; |
309 | } | 309 | } |
310 | 310 | ||
311 | static void bch_subtract_dirty(struct bkey *k, | ||
312 | struct cache_set *c, | ||
313 | uint64_t offset, | ||
314 | int sectors) | ||
315 | { | ||
316 | if (KEY_DIRTY(k)) | ||
317 | bcache_dev_sectors_dirty_add(c, KEY_INODE(k), | ||
318 | offset, -sectors); | ||
319 | } | ||
320 | |||
311 | static bool bch_extent_insert_fixup(struct btree_keys *b, | 321 | static bool bch_extent_insert_fixup(struct btree_keys *b, |
312 | struct bkey *insert, | 322 | struct bkey *insert, |
313 | struct btree_iter *iter, | 323 | struct btree_iter *iter, |
@@ -315,13 +325,6 @@ static bool bch_extent_insert_fixup(struct btree_keys *b, | |||
315 | { | 325 | { |
316 | struct cache_set *c = container_of(b, struct btree, keys)->c; | 326 | struct cache_set *c = container_of(b, struct btree, keys)->c; |
317 | 327 | ||
318 | void subtract_dirty(struct bkey *k, uint64_t offset, int sectors) | ||
319 | { | ||
320 | if (KEY_DIRTY(k)) | ||
321 | bcache_dev_sectors_dirty_add(c, KEY_INODE(k), | ||
322 | offset, -sectors); | ||
323 | } | ||
324 | |||
325 | uint64_t old_offset; | 328 | uint64_t old_offset; |
326 | unsigned old_size, sectors_found = 0; | 329 | unsigned old_size, sectors_found = 0; |
327 | 330 | ||
@@ -398,7 +401,8 @@ static bool bch_extent_insert_fixup(struct btree_keys *b, | |||
398 | 401 | ||
399 | struct bkey *top; | 402 | struct bkey *top; |
400 | 403 | ||
401 | subtract_dirty(k, KEY_START(insert), KEY_SIZE(insert)); | 404 | bch_subtract_dirty(k, c, KEY_START(insert), |
405 | KEY_SIZE(insert)); | ||
402 | 406 | ||
403 | if (bkey_written(b, k)) { | 407 | if (bkey_written(b, k)) { |
404 | /* | 408 | /* |
@@ -448,7 +452,7 @@ static bool bch_extent_insert_fixup(struct btree_keys *b, | |||
448 | } | 452 | } |
449 | } | 453 | } |
450 | 454 | ||
451 | subtract_dirty(k, old_offset, old_size - KEY_SIZE(k)); | 455 | bch_subtract_dirty(k, c, old_offset, old_size - KEY_SIZE(k)); |
452 | } | 456 | } |
453 | 457 | ||
454 | check_failed: | 458 | check_failed: |
@@ -499,9 +503,9 @@ static bool bch_extent_bad_expensive(struct btree *b, const struct bkey *k, | |||
499 | 503 | ||
500 | if (mutex_trylock(&b->c->bucket_lock)) { | 504 | if (mutex_trylock(&b->c->bucket_lock)) { |
501 | if (b->c->gc_mark_valid && | 505 | if (b->c->gc_mark_valid && |
502 | ((GC_MARK(g) != GC_MARK_DIRTY && | 506 | (!GC_MARK(g) || |
503 | KEY_DIRTY(k)) || | 507 | GC_MARK(g) == GC_MARK_METADATA || |
504 | GC_MARK(g) == GC_MARK_METADATA)) | 508 | (GC_MARK(g) != GC_MARK_DIRTY && KEY_DIRTY(k)))) |
505 | goto err; | 509 | goto err; |
506 | 510 | ||
507 | if (g->prio == BTREE_PRIO) | 511 | if (g->prio == BTREE_PRIO) |
@@ -515,9 +519,9 @@ err: | |||
515 | mutex_unlock(&b->c->bucket_lock); | 519 | mutex_unlock(&b->c->bucket_lock); |
516 | bch_extent_to_text(buf, sizeof(buf), k); | 520 | bch_extent_to_text(buf, sizeof(buf), k); |
517 | btree_bug(b, | 521 | btree_bug(b, |
518 | "inconsistent extent pointer %s:\nbucket %zu pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i", | 522 | "inconsistent extent pointer %s:\nbucket %zu pin %i prio %i gen %i last_gc %i mark %llu", |
519 | buf, PTR_BUCKET_NR(b->c, k, ptr), atomic_read(&g->pin), | 523 | buf, PTR_BUCKET_NR(b->c, k, ptr), atomic_read(&g->pin), |
520 | g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen); | 524 | g->prio, g->gen, g->last_gc, GC_MARK(g)); |
521 | return true; | 525 | return true; |
522 | } | 526 | } |
523 | 527 | ||
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c index 18039affc306..59e82021b5bb 100644 --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c | |||
@@ -237,8 +237,14 @@ bsearch: | |||
237 | for (i = 0; i < ca->sb.njournal_buckets; i++) | 237 | for (i = 0; i < ca->sb.njournal_buckets; i++) |
238 | if (ja->seq[i] > seq) { | 238 | if (ja->seq[i] > seq) { |
239 | seq = ja->seq[i]; | 239 | seq = ja->seq[i]; |
240 | ja->cur_idx = ja->discard_idx = | 240 | /* |
241 | ja->last_idx = i; | 241 | * When journal_reclaim() goes to allocate for |
242 | * the first time, it'll use the bucket after | ||
243 | * ja->cur_idx | ||
244 | */ | ||
245 | ja->cur_idx = i; | ||
246 | ja->last_idx = ja->discard_idx = (i + 1) % | ||
247 | ca->sb.njournal_buckets; | ||
242 | 248 | ||
243 | } | 249 | } |
244 | } | 250 | } |
@@ -288,16 +294,11 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list) | |||
288 | k = bkey_next(k)) { | 294 | k = bkey_next(k)) { |
289 | unsigned j; | 295 | unsigned j; |
290 | 296 | ||
291 | for (j = 0; j < KEY_PTRS(k); j++) { | 297 | for (j = 0; j < KEY_PTRS(k); j++) |
292 | struct bucket *g = PTR_BUCKET(c, k, j); | 298 | if (ptr_available(c, k, j)) |
293 | atomic_inc(&g->pin); | 299 | atomic_inc(&PTR_BUCKET(c, k, j)->pin); |
294 | 300 | ||
295 | if (g->prio == BTREE_PRIO && | 301 | bch_initial_mark_key(c, 0, k); |
296 | !ptr_stale(c, k, j)) | ||
297 | g->prio = INITIAL_PRIO; | ||
298 | } | ||
299 | |||
300 | __bch_btree_mark_key(c, 0, k); | ||
301 | } | 302 | } |
302 | } | 303 | } |
303 | } | 304 | } |
@@ -312,8 +313,6 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list) | |||
312 | uint64_t start = i->j.last_seq, end = i->j.seq, n = start; | 313 | uint64_t start = i->j.last_seq, end = i->j.seq, n = start; |
313 | struct keylist keylist; | 314 | struct keylist keylist; |
314 | 315 | ||
315 | bch_keylist_init(&keylist); | ||
316 | |||
317 | list_for_each_entry(i, list, list) { | 316 | list_for_each_entry(i, list, list) { |
318 | BUG_ON(i->pin && atomic_read(i->pin) != 1); | 317 | BUG_ON(i->pin && atomic_read(i->pin) != 1); |
319 | 318 | ||
@@ -326,8 +325,7 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list) | |||
326 | k = bkey_next(k)) { | 325 | k = bkey_next(k)) { |
327 | trace_bcache_journal_replay_key(k); | 326 | trace_bcache_journal_replay_key(k); |
328 | 327 | ||
329 | bkey_copy(keylist.top, k); | 328 | bch_keylist_init_single(&keylist, k); |
330 | bch_keylist_push(&keylist); | ||
331 | 329 | ||
332 | ret = bch_btree_insert(s, &keylist, i->pin, NULL); | 330 | ret = bch_btree_insert(s, &keylist, i->pin, NULL); |
333 | if (ret) | 331 | if (ret) |
@@ -383,16 +381,15 @@ retry: | |||
383 | 381 | ||
384 | b = best; | 382 | b = best; |
385 | if (b) { | 383 | if (b) { |
386 | rw_lock(true, b, b->level); | 384 | mutex_lock(&b->write_lock); |
387 | |||
388 | if (!btree_current_write(b)->journal) { | 385 | if (!btree_current_write(b)->journal) { |
389 | rw_unlock(true, b); | 386 | mutex_unlock(&b->write_lock); |
390 | /* We raced */ | 387 | /* We raced */ |
391 | goto retry; | 388 | goto retry; |
392 | } | 389 | } |
393 | 390 | ||
394 | bch_btree_node_write(b, NULL); | 391 | __bch_btree_node_write(b, NULL); |
395 | rw_unlock(true, b); | 392 | mutex_unlock(&b->write_lock); |
396 | } | 393 | } |
397 | } | 394 | } |
398 | 395 | ||
@@ -536,6 +533,7 @@ void bch_journal_next(struct journal *j) | |||
536 | atomic_set(&fifo_back(&j->pin), 1); | 533 | atomic_set(&fifo_back(&j->pin), 1); |
537 | 534 | ||
538 | j->cur->data->seq = ++j->seq; | 535 | j->cur->data->seq = ++j->seq; |
536 | j->cur->dirty = false; | ||
539 | j->cur->need_write = false; | 537 | j->cur->need_write = false; |
540 | j->cur->data->keys = 0; | 538 | j->cur->data->keys = 0; |
541 | 539 | ||
@@ -731,7 +729,10 @@ static void journal_write_work(struct work_struct *work) | |||
731 | struct cache_set, | 729 | struct cache_set, |
732 | journal.work); | 730 | journal.work); |
733 | spin_lock(&c->journal.lock); | 731 | spin_lock(&c->journal.lock); |
734 | journal_try_write(c); | 732 | if (c->journal.cur->dirty) |
733 | journal_try_write(c); | ||
734 | else | ||
735 | spin_unlock(&c->journal.lock); | ||
735 | } | 736 | } |
736 | 737 | ||
737 | /* | 738 | /* |
@@ -761,7 +762,8 @@ atomic_t *bch_journal(struct cache_set *c, | |||
761 | if (parent) { | 762 | if (parent) { |
762 | closure_wait(&w->wait, parent); | 763 | closure_wait(&w->wait, parent); |
763 | journal_try_write(c); | 764 | journal_try_write(c); |
764 | } else if (!w->need_write) { | 765 | } else if (!w->dirty) { |
766 | w->dirty = true; | ||
765 | schedule_delayed_work(&c->journal.work, | 767 | schedule_delayed_work(&c->journal.work, |
766 | msecs_to_jiffies(c->journal_delay_ms)); | 768 | msecs_to_jiffies(c->journal_delay_ms)); |
767 | spin_unlock(&c->journal.lock); | 769 | spin_unlock(&c->journal.lock); |
diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h index 9180c4465075..e3c39457afbb 100644 --- a/drivers/md/bcache/journal.h +++ b/drivers/md/bcache/journal.h | |||
@@ -95,6 +95,7 @@ struct journal_write { | |||
95 | 95 | ||
96 | struct cache_set *c; | 96 | struct cache_set *c; |
97 | struct closure_waitlist wait; | 97 | struct closure_waitlist wait; |
98 | bool dirty; | ||
98 | bool need_write; | 99 | bool need_write; |
99 | }; | 100 | }; |
100 | 101 | ||
diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c index 9eb60d102de8..cd7490311e51 100644 --- a/drivers/md/bcache/movinggc.c +++ b/drivers/md/bcache/movinggc.c | |||
@@ -24,12 +24,10 @@ static bool moving_pred(struct keybuf *buf, struct bkey *k) | |||
24 | moving_gc_keys); | 24 | moving_gc_keys); |
25 | unsigned i; | 25 | unsigned i; |
26 | 26 | ||
27 | for (i = 0; i < KEY_PTRS(k); i++) { | 27 | for (i = 0; i < KEY_PTRS(k); i++) |
28 | struct bucket *g = PTR_BUCKET(c, k, i); | 28 | if (ptr_available(c, k, i) && |
29 | 29 | GC_MOVE(PTR_BUCKET(c, k, i))) | |
30 | if (GC_MOVE(g)) | ||
31 | return true; | 30 | return true; |
32 | } | ||
33 | 31 | ||
34 | return false; | 32 | return false; |
35 | } | 33 | } |
@@ -115,7 +113,7 @@ static void write_moving(struct closure *cl) | |||
115 | closure_call(&op->cl, bch_data_insert, NULL, cl); | 113 | closure_call(&op->cl, bch_data_insert, NULL, cl); |
116 | } | 114 | } |
117 | 115 | ||
118 | continue_at(cl, write_moving_finish, system_wq); | 116 | continue_at(cl, write_moving_finish, op->wq); |
119 | } | 117 | } |
120 | 118 | ||
121 | static void read_moving_submit(struct closure *cl) | 119 | static void read_moving_submit(struct closure *cl) |
@@ -125,7 +123,7 @@ static void read_moving_submit(struct closure *cl) | |||
125 | 123 | ||
126 | bch_submit_bbio(bio, io->op.c, &io->w->key, 0); | 124 | bch_submit_bbio(bio, io->op.c, &io->w->key, 0); |
127 | 125 | ||
128 | continue_at(cl, write_moving, system_wq); | 126 | continue_at(cl, write_moving, io->op.wq); |
129 | } | 127 | } |
130 | 128 | ||
131 | static void read_moving(struct cache_set *c) | 129 | static void read_moving(struct cache_set *c) |
@@ -160,6 +158,7 @@ static void read_moving(struct cache_set *c) | |||
160 | io->w = w; | 158 | io->w = w; |
161 | io->op.inode = KEY_INODE(&w->key); | 159 | io->op.inode = KEY_INODE(&w->key); |
162 | io->op.c = c; | 160 | io->op.c = c; |
161 | io->op.wq = c->moving_gc_wq; | ||
163 | 162 | ||
164 | moving_init(io); | 163 | moving_init(io); |
165 | bio = &io->bio.bio; | 164 | bio = &io->bio.bio; |
@@ -216,7 +215,10 @@ void bch_moving_gc(struct cache_set *c) | |||
216 | ca->heap.used = 0; | 215 | ca->heap.used = 0; |
217 | 216 | ||
218 | for_each_bucket(b, ca) { | 217 | for_each_bucket(b, ca) { |
219 | if (!GC_SECTORS_USED(b)) | 218 | if (GC_MARK(b) == GC_MARK_METADATA || |
219 | !GC_SECTORS_USED(b) || | ||
220 | GC_SECTORS_USED(b) == ca->sb.bucket_size || | ||
221 | atomic_read(&b->pin)) | ||
220 | continue; | 222 | continue; |
221 | 223 | ||
222 | if (!heap_full(&ca->heap)) { | 224 | if (!heap_full(&ca->heap)) { |
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 5d5d031cf381..15fff4f68a7c 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c | |||
@@ -12,11 +12,9 @@ | |||
12 | #include "request.h" | 12 | #include "request.h" |
13 | #include "writeback.h" | 13 | #include "writeback.h" |
14 | 14 | ||
15 | #include <linux/cgroup.h> | ||
16 | #include <linux/module.h> | 15 | #include <linux/module.h> |
17 | #include <linux/hash.h> | 16 | #include <linux/hash.h> |
18 | #include <linux/random.h> | 17 | #include <linux/random.h> |
19 | #include "blk-cgroup.h" | ||
20 | 18 | ||
21 | #include <trace/events/bcache.h> | 19 | #include <trace/events/bcache.h> |
22 | 20 | ||
@@ -27,171 +25,13 @@ struct kmem_cache *bch_search_cache; | |||
27 | 25 | ||
28 | static void bch_data_insert_start(struct closure *); | 26 | static void bch_data_insert_start(struct closure *); |
29 | 27 | ||
30 | /* Cgroup interface */ | ||
31 | |||
32 | #ifdef CONFIG_CGROUP_BCACHE | ||
33 | static struct bch_cgroup bcache_default_cgroup = { .cache_mode = -1 }; | ||
34 | |||
35 | static struct bch_cgroup *cgroup_to_bcache(struct cgroup *cgroup) | ||
36 | { | ||
37 | struct cgroup_subsys_state *css; | ||
38 | return cgroup && | ||
39 | (css = cgroup_subsys_state(cgroup, bcache_subsys_id)) | ||
40 | ? container_of(css, struct bch_cgroup, css) | ||
41 | : &bcache_default_cgroup; | ||
42 | } | ||
43 | |||
44 | struct bch_cgroup *bch_bio_to_cgroup(struct bio *bio) | ||
45 | { | ||
46 | struct cgroup_subsys_state *css = bio->bi_css | ||
47 | ? cgroup_subsys_state(bio->bi_css->cgroup, bcache_subsys_id) | ||
48 | : task_subsys_state(current, bcache_subsys_id); | ||
49 | |||
50 | return css | ||
51 | ? container_of(css, struct bch_cgroup, css) | ||
52 | : &bcache_default_cgroup; | ||
53 | } | ||
54 | |||
55 | static ssize_t cache_mode_read(struct cgroup *cgrp, struct cftype *cft, | ||
56 | struct file *file, | ||
57 | char __user *buf, size_t nbytes, loff_t *ppos) | ||
58 | { | ||
59 | char tmp[1024]; | ||
60 | int len = bch_snprint_string_list(tmp, PAGE_SIZE, bch_cache_modes, | ||
61 | cgroup_to_bcache(cgrp)->cache_mode + 1); | ||
62 | |||
63 | if (len < 0) | ||
64 | return len; | ||
65 | |||
66 | return simple_read_from_buffer(buf, nbytes, ppos, tmp, len); | ||
67 | } | ||
68 | |||
69 | static int cache_mode_write(struct cgroup *cgrp, struct cftype *cft, | ||
70 | const char *buf) | ||
71 | { | ||
72 | int v = bch_read_string_list(buf, bch_cache_modes); | ||
73 | if (v < 0) | ||
74 | return v; | ||
75 | |||
76 | cgroup_to_bcache(cgrp)->cache_mode = v - 1; | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static u64 bch_verify_read(struct cgroup *cgrp, struct cftype *cft) | ||
81 | { | ||
82 | return cgroup_to_bcache(cgrp)->verify; | ||
83 | } | ||
84 | |||
85 | static int bch_verify_write(struct cgroup *cgrp, struct cftype *cft, u64 val) | ||
86 | { | ||
87 | cgroup_to_bcache(cgrp)->verify = val; | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static u64 bch_cache_hits_read(struct cgroup *cgrp, struct cftype *cft) | ||
92 | { | ||
93 | struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp); | ||
94 | return atomic_read(&bcachecg->stats.cache_hits); | ||
95 | } | ||
96 | |||
97 | static u64 bch_cache_misses_read(struct cgroup *cgrp, struct cftype *cft) | ||
98 | { | ||
99 | struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp); | ||
100 | return atomic_read(&bcachecg->stats.cache_misses); | ||
101 | } | ||
102 | |||
103 | static u64 bch_cache_bypass_hits_read(struct cgroup *cgrp, | ||
104 | struct cftype *cft) | ||
105 | { | ||
106 | struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp); | ||
107 | return atomic_read(&bcachecg->stats.cache_bypass_hits); | ||
108 | } | ||
109 | |||
110 | static u64 bch_cache_bypass_misses_read(struct cgroup *cgrp, | ||
111 | struct cftype *cft) | ||
112 | { | ||
113 | struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp); | ||
114 | return atomic_read(&bcachecg->stats.cache_bypass_misses); | ||
115 | } | ||
116 | |||
117 | static struct cftype bch_files[] = { | ||
118 | { | ||
119 | .name = "cache_mode", | ||
120 | .read = cache_mode_read, | ||
121 | .write_string = cache_mode_write, | ||
122 | }, | ||
123 | { | ||
124 | .name = "verify", | ||
125 | .read_u64 = bch_verify_read, | ||
126 | .write_u64 = bch_verify_write, | ||
127 | }, | ||
128 | { | ||
129 | .name = "cache_hits", | ||
130 | .read_u64 = bch_cache_hits_read, | ||
131 | }, | ||
132 | { | ||
133 | .name = "cache_misses", | ||
134 | .read_u64 = bch_cache_misses_read, | ||
135 | }, | ||
136 | { | ||
137 | .name = "cache_bypass_hits", | ||
138 | .read_u64 = bch_cache_bypass_hits_read, | ||
139 | }, | ||
140 | { | ||
141 | .name = "cache_bypass_misses", | ||
142 | .read_u64 = bch_cache_bypass_misses_read, | ||
143 | }, | ||
144 | { } /* terminate */ | ||
145 | }; | ||
146 | |||
147 | static void init_bch_cgroup(struct bch_cgroup *cg) | ||
148 | { | ||
149 | cg->cache_mode = -1; | ||
150 | } | ||
151 | |||
152 | static struct cgroup_subsys_state *bcachecg_create(struct cgroup *cgroup) | ||
153 | { | ||
154 | struct bch_cgroup *cg; | ||
155 | |||
156 | cg = kzalloc(sizeof(*cg), GFP_KERNEL); | ||
157 | if (!cg) | ||
158 | return ERR_PTR(-ENOMEM); | ||
159 | init_bch_cgroup(cg); | ||
160 | return &cg->css; | ||
161 | } | ||
162 | |||
163 | static void bcachecg_destroy(struct cgroup *cgroup) | ||
164 | { | ||
165 | struct bch_cgroup *cg = cgroup_to_bcache(cgroup); | ||
166 | kfree(cg); | ||
167 | } | ||
168 | |||
169 | struct cgroup_subsys bcache_subsys = { | ||
170 | .create = bcachecg_create, | ||
171 | .destroy = bcachecg_destroy, | ||
172 | .subsys_id = bcache_subsys_id, | ||
173 | .name = "bcache", | ||
174 | .module = THIS_MODULE, | ||
175 | }; | ||
176 | EXPORT_SYMBOL_GPL(bcache_subsys); | ||
177 | #endif | ||
178 | |||
179 | static unsigned cache_mode(struct cached_dev *dc, struct bio *bio) | 28 | static unsigned cache_mode(struct cached_dev *dc, struct bio *bio) |
180 | { | 29 | { |
181 | #ifdef CONFIG_CGROUP_BCACHE | ||
182 | int r = bch_bio_to_cgroup(bio)->cache_mode; | ||
183 | if (r >= 0) | ||
184 | return r; | ||
185 | #endif | ||
186 | return BDEV_CACHE_MODE(&dc->sb); | 30 | return BDEV_CACHE_MODE(&dc->sb); |
187 | } | 31 | } |
188 | 32 | ||
189 | static bool verify(struct cached_dev *dc, struct bio *bio) | 33 | static bool verify(struct cached_dev *dc, struct bio *bio) |
190 | { | 34 | { |
191 | #ifdef CONFIG_CGROUP_BCACHE | ||
192 | if (bch_bio_to_cgroup(bio)->verify) | ||
193 | return true; | ||
194 | #endif | ||
195 | return dc->verify; | 35 | return dc->verify; |
196 | } | 36 | } |
197 | 37 | ||
@@ -248,7 +88,7 @@ static void bch_data_insert_keys(struct closure *cl) | |||
248 | atomic_dec_bug(journal_ref); | 88 | atomic_dec_bug(journal_ref); |
249 | 89 | ||
250 | if (!op->insert_data_done) | 90 | if (!op->insert_data_done) |
251 | continue_at(cl, bch_data_insert_start, bcache_wq); | 91 | continue_at(cl, bch_data_insert_start, op->wq); |
252 | 92 | ||
253 | bch_keylist_free(&op->insert_keys); | 93 | bch_keylist_free(&op->insert_keys); |
254 | closure_return(cl); | 94 | closure_return(cl); |
@@ -297,7 +137,7 @@ static void bch_data_invalidate(struct closure *cl) | |||
297 | op->insert_data_done = true; | 137 | op->insert_data_done = true; |
298 | bio_put(bio); | 138 | bio_put(bio); |
299 | out: | 139 | out: |
300 | continue_at(cl, bch_data_insert_keys, bcache_wq); | 140 | continue_at(cl, bch_data_insert_keys, op->wq); |
301 | } | 141 | } |
302 | 142 | ||
303 | static void bch_data_insert_error(struct closure *cl) | 143 | static void bch_data_insert_error(struct closure *cl) |
@@ -340,7 +180,7 @@ static void bch_data_insert_endio(struct bio *bio, int error) | |||
340 | if (op->writeback) | 180 | if (op->writeback) |
341 | op->error = error; | 181 | op->error = error; |
342 | else if (!op->replace) | 182 | else if (!op->replace) |
343 | set_closure_fn(cl, bch_data_insert_error, bcache_wq); | 183 | set_closure_fn(cl, bch_data_insert_error, op->wq); |
344 | else | 184 | else |
345 | set_closure_fn(cl, NULL, NULL); | 185 | set_closure_fn(cl, NULL, NULL); |
346 | } | 186 | } |
@@ -376,7 +216,7 @@ static void bch_data_insert_start(struct closure *cl) | |||
376 | if (bch_keylist_realloc(&op->insert_keys, | 216 | if (bch_keylist_realloc(&op->insert_keys, |
377 | 3 + (op->csum ? 1 : 0), | 217 | 3 + (op->csum ? 1 : 0), |
378 | op->c)) | 218 | op->c)) |
379 | continue_at(cl, bch_data_insert_keys, bcache_wq); | 219 | continue_at(cl, bch_data_insert_keys, op->wq); |
380 | 220 | ||
381 | k = op->insert_keys.top; | 221 | k = op->insert_keys.top; |
382 | bkey_init(k); | 222 | bkey_init(k); |
@@ -413,7 +253,7 @@ static void bch_data_insert_start(struct closure *cl) | |||
413 | } while (n != bio); | 253 | } while (n != bio); |
414 | 254 | ||
415 | op->insert_data_done = true; | 255 | op->insert_data_done = true; |
416 | continue_at(cl, bch_data_insert_keys, bcache_wq); | 256 | continue_at(cl, bch_data_insert_keys, op->wq); |
417 | err: | 257 | err: |
418 | /* bch_alloc_sectors() blocks if s->writeback = true */ | 258 | /* bch_alloc_sectors() blocks if s->writeback = true */ |
419 | BUG_ON(op->writeback); | 259 | BUG_ON(op->writeback); |
@@ -442,7 +282,7 @@ err: | |||
442 | bio_put(bio); | 282 | bio_put(bio); |
443 | 283 | ||
444 | if (!bch_keylist_empty(&op->insert_keys)) | 284 | if (!bch_keylist_empty(&op->insert_keys)) |
445 | continue_at(cl, bch_data_insert_keys, bcache_wq); | 285 | continue_at(cl, bch_data_insert_keys, op->wq); |
446 | else | 286 | else |
447 | closure_return(cl); | 287 | closure_return(cl); |
448 | } | 288 | } |
@@ -824,6 +664,7 @@ static inline struct search *search_alloc(struct bio *bio, | |||
824 | s->iop.error = 0; | 664 | s->iop.error = 0; |
825 | s->iop.flags = 0; | 665 | s->iop.flags = 0; |
826 | s->iop.flush_journal = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0; | 666 | s->iop.flush_journal = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0; |
667 | s->iop.wq = bcache_wq; | ||
827 | 668 | ||
828 | return s; | 669 | return s; |
829 | } | 670 | } |
@@ -1203,22 +1044,13 @@ void bch_cached_dev_request_init(struct cached_dev *dc) | |||
1203 | static int flash_dev_cache_miss(struct btree *b, struct search *s, | 1044 | static int flash_dev_cache_miss(struct btree *b, struct search *s, |
1204 | struct bio *bio, unsigned sectors) | 1045 | struct bio *bio, unsigned sectors) |
1205 | { | 1046 | { |
1206 | struct bio_vec bv; | 1047 | unsigned bytes = min(sectors, bio_sectors(bio)) << 9; |
1207 | struct bvec_iter iter; | ||
1208 | |||
1209 | /* Zero fill bio */ | ||
1210 | 1048 | ||
1211 | bio_for_each_segment(bv, bio, iter) { | 1049 | swap(bio->bi_iter.bi_size, bytes); |
1212 | unsigned j = min(bv.bv_len >> 9, sectors); | 1050 | zero_fill_bio(bio); |
1213 | 1051 | swap(bio->bi_iter.bi_size, bytes); | |
1214 | void *p = kmap(bv.bv_page); | ||
1215 | memset(p + bv.bv_offset, 0, j << 9); | ||
1216 | kunmap(bv.bv_page); | ||
1217 | |||
1218 | sectors -= j; | ||
1219 | } | ||
1220 | 1052 | ||
1221 | bio_advance(bio, min(sectors << 9, bio->bi_iter.bi_size)); | 1053 | bio_advance(bio, bytes); |
1222 | 1054 | ||
1223 | if (!bio->bi_iter.bi_size) | 1055 | if (!bio->bi_iter.bi_size) |
1224 | return MAP_DONE; | 1056 | return MAP_DONE; |
@@ -1313,9 +1145,6 @@ void bch_flash_dev_request_init(struct bcache_device *d) | |||
1313 | 1145 | ||
1314 | void bch_request_exit(void) | 1146 | void bch_request_exit(void) |
1315 | { | 1147 | { |
1316 | #ifdef CONFIG_CGROUP_BCACHE | ||
1317 | cgroup_unload_subsys(&bcache_subsys); | ||
1318 | #endif | ||
1319 | if (bch_search_cache) | 1148 | if (bch_search_cache) |
1320 | kmem_cache_destroy(bch_search_cache); | 1149 | kmem_cache_destroy(bch_search_cache); |
1321 | } | 1150 | } |
@@ -1326,11 +1155,5 @@ int __init bch_request_init(void) | |||
1326 | if (!bch_search_cache) | 1155 | if (!bch_search_cache) |
1327 | return -ENOMEM; | 1156 | return -ENOMEM; |
1328 | 1157 | ||
1329 | #ifdef CONFIG_CGROUP_BCACHE | ||
1330 | cgroup_load_subsys(&bcache_subsys); | ||
1331 | init_bch_cgroup(&bcache_default_cgroup); | ||
1332 | |||
1333 | cgroup_add_cftypes(&bcache_subsys, bch_files); | ||
1334 | #endif | ||
1335 | return 0; | 1158 | return 0; |
1336 | } | 1159 | } |
diff --git a/drivers/md/bcache/request.h b/drivers/md/bcache/request.h index 39f21dbedc38..1ff36875c2b3 100644 --- a/drivers/md/bcache/request.h +++ b/drivers/md/bcache/request.h | |||
@@ -1,12 +1,11 @@ | |||
1 | #ifndef _BCACHE_REQUEST_H_ | 1 | #ifndef _BCACHE_REQUEST_H_ |
2 | #define _BCACHE_REQUEST_H_ | 2 | #define _BCACHE_REQUEST_H_ |
3 | 3 | ||
4 | #include <linux/cgroup.h> | ||
5 | |||
6 | struct data_insert_op { | 4 | struct data_insert_op { |
7 | struct closure cl; | 5 | struct closure cl; |
8 | struct cache_set *c; | 6 | struct cache_set *c; |
9 | struct bio *bio; | 7 | struct bio *bio; |
8 | struct workqueue_struct *wq; | ||
10 | 9 | ||
11 | unsigned inode; | 10 | unsigned inode; |
12 | uint16_t write_point; | 11 | uint16_t write_point; |
@@ -41,20 +40,4 @@ void bch_flash_dev_request_init(struct bcache_device *d); | |||
41 | 40 | ||
42 | extern struct kmem_cache *bch_search_cache, *bch_passthrough_cache; | 41 | extern struct kmem_cache *bch_search_cache, *bch_passthrough_cache; |
43 | 42 | ||
44 | struct bch_cgroup { | ||
45 | #ifdef CONFIG_CGROUP_BCACHE | ||
46 | struct cgroup_subsys_state css; | ||
47 | #endif | ||
48 | /* | ||
49 | * We subtract one from the index into bch_cache_modes[], so that | ||
50 | * default == -1; this makes it so the rest match up with d->cache_mode, | ||
51 | * and we use d->cache_mode if cgrp->cache_mode < 0 | ||
52 | */ | ||
53 | short cache_mode; | ||
54 | bool verify; | ||
55 | struct cache_stat_collector stats; | ||
56 | }; | ||
57 | |||
58 | struct bch_cgroup *bch_bio_to_cgroup(struct bio *bio); | ||
59 | |||
60 | #endif /* _BCACHE_REQUEST_H_ */ | 43 | #endif /* _BCACHE_REQUEST_H_ */ |
diff --git a/drivers/md/bcache/stats.c b/drivers/md/bcache/stats.c index 84d0782f702e..0ca072c20d0d 100644 --- a/drivers/md/bcache/stats.c +++ b/drivers/md/bcache/stats.c | |||
@@ -201,9 +201,6 @@ void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d, | |||
201 | struct cached_dev *dc = container_of(d, struct cached_dev, disk); | 201 | struct cached_dev *dc = container_of(d, struct cached_dev, disk); |
202 | mark_cache_stats(&dc->accounting.collector, hit, bypass); | 202 | mark_cache_stats(&dc->accounting.collector, hit, bypass); |
203 | mark_cache_stats(&c->accounting.collector, hit, bypass); | 203 | mark_cache_stats(&c->accounting.collector, hit, bypass); |
204 | #ifdef CONFIG_CGROUP_BCACHE | ||
205 | mark_cache_stats(&(bch_bio_to_cgroup(s->orig_bio)->stats), hit, bypass); | ||
206 | #endif | ||
207 | } | 204 | } |
208 | 205 | ||
209 | void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d) | 206 | void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d) |
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 24a3a1546caa..926ded8ccbf5 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c | |||
@@ -541,9 +541,6 @@ static void prio_io(struct cache *ca, uint64_t bucket, unsigned long rw) | |||
541 | closure_sync(cl); | 541 | closure_sync(cl); |
542 | } | 542 | } |
543 | 543 | ||
544 | #define buckets_free(c) "free %zu, free_inc %zu, unused %zu", \ | ||
545 | fifo_used(&c->free), fifo_used(&c->free_inc), fifo_used(&c->unused) | ||
546 | |||
547 | void bch_prio_write(struct cache *ca) | 544 | void bch_prio_write(struct cache *ca) |
548 | { | 545 | { |
549 | int i; | 546 | int i; |
@@ -554,10 +551,6 @@ void bch_prio_write(struct cache *ca) | |||
554 | 551 | ||
555 | lockdep_assert_held(&ca->set->bucket_lock); | 552 | lockdep_assert_held(&ca->set->bucket_lock); |
556 | 553 | ||
557 | for (b = ca->buckets; | ||
558 | b < ca->buckets + ca->sb.nbuckets; b++) | ||
559 | b->disk_gen = b->gen; | ||
560 | |||
561 | ca->disk_buckets->seq++; | 554 | ca->disk_buckets->seq++; |
562 | 555 | ||
563 | atomic_long_add(ca->sb.bucket_size * prio_buckets(ca), | 556 | atomic_long_add(ca->sb.bucket_size * prio_buckets(ca), |
@@ -601,14 +594,17 @@ void bch_prio_write(struct cache *ca) | |||
601 | 594 | ||
602 | mutex_lock(&ca->set->bucket_lock); | 595 | mutex_lock(&ca->set->bucket_lock); |
603 | 596 | ||
604 | ca->need_save_prio = 0; | ||
605 | |||
606 | /* | 597 | /* |
607 | * Don't want the old priorities to get garbage collected until after we | 598 | * Don't want the old priorities to get garbage collected until after we |
608 | * finish writing the new ones, and they're journalled | 599 | * finish writing the new ones, and they're journalled |
609 | */ | 600 | */ |
610 | for (i = 0; i < prio_buckets(ca); i++) | 601 | for (i = 0; i < prio_buckets(ca); i++) { |
602 | if (ca->prio_last_buckets[i]) | ||
603 | __bch_bucket_free(ca, | ||
604 | &ca->buckets[ca->prio_last_buckets[i]]); | ||
605 | |||
611 | ca->prio_last_buckets[i] = ca->prio_buckets[i]; | 606 | ca->prio_last_buckets[i] = ca->prio_buckets[i]; |
607 | } | ||
612 | } | 608 | } |
613 | 609 | ||
614 | static void prio_read(struct cache *ca, uint64_t bucket) | 610 | static void prio_read(struct cache *ca, uint64_t bucket) |
@@ -639,7 +635,7 @@ static void prio_read(struct cache *ca, uint64_t bucket) | |||
639 | } | 635 | } |
640 | 636 | ||
641 | b->prio = le16_to_cpu(d->prio); | 637 | b->prio = le16_to_cpu(d->prio); |
642 | b->gen = b->disk_gen = b->last_gc = b->gc_gen = d->gen; | 638 | b->gen = b->last_gc = d->gen; |
643 | } | 639 | } |
644 | } | 640 | } |
645 | 641 | ||
@@ -843,6 +839,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, | |||
843 | q->limits.max_segment_size = UINT_MAX; | 839 | q->limits.max_segment_size = UINT_MAX; |
844 | q->limits.max_segments = BIO_MAX_PAGES; | 840 | q->limits.max_segments = BIO_MAX_PAGES; |
845 | q->limits.max_discard_sectors = UINT_MAX; | 841 | q->limits.max_discard_sectors = UINT_MAX; |
842 | q->limits.discard_granularity = 512; | ||
846 | q->limits.io_min = block_size; | 843 | q->limits.io_min = block_size; |
847 | q->limits.logical_block_size = block_size; | 844 | q->limits.logical_block_size = block_size; |
848 | q->limits.physical_block_size = block_size; | 845 | q->limits.physical_block_size = block_size; |
@@ -1355,6 +1352,8 @@ static void cache_set_free(struct closure *cl) | |||
1355 | bch_bset_sort_state_free(&c->sort); | 1352 | bch_bset_sort_state_free(&c->sort); |
1356 | free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c))); | 1353 | free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c))); |
1357 | 1354 | ||
1355 | if (c->moving_gc_wq) | ||
1356 | destroy_workqueue(c->moving_gc_wq); | ||
1358 | if (c->bio_split) | 1357 | if (c->bio_split) |
1359 | bioset_free(c->bio_split); | 1358 | bioset_free(c->bio_split); |
1360 | if (c->fill_iter) | 1359 | if (c->fill_iter) |
@@ -1395,14 +1394,21 @@ static void cache_set_flush(struct closure *cl) | |||
1395 | list_add(&c->root->list, &c->btree_cache); | 1394 | list_add(&c->root->list, &c->btree_cache); |
1396 | 1395 | ||
1397 | /* Should skip this if we're unregistering because of an error */ | 1396 | /* Should skip this if we're unregistering because of an error */ |
1398 | list_for_each_entry(b, &c->btree_cache, list) | 1397 | list_for_each_entry(b, &c->btree_cache, list) { |
1398 | mutex_lock(&b->write_lock); | ||
1399 | if (btree_node_dirty(b)) | 1399 | if (btree_node_dirty(b)) |
1400 | bch_btree_node_write(b, NULL); | 1400 | __bch_btree_node_write(b, NULL); |
1401 | mutex_unlock(&b->write_lock); | ||
1402 | } | ||
1401 | 1403 | ||
1402 | for_each_cache(ca, c, i) | 1404 | for_each_cache(ca, c, i) |
1403 | if (ca->alloc_thread) | 1405 | if (ca->alloc_thread) |
1404 | kthread_stop(ca->alloc_thread); | 1406 | kthread_stop(ca->alloc_thread); |
1405 | 1407 | ||
1408 | cancel_delayed_work_sync(&c->journal.work); | ||
1409 | /* flush last journal entry if needed */ | ||
1410 | c->journal.work.work.func(&c->journal.work.work); | ||
1411 | |||
1406 | closure_return(cl); | 1412 | closure_return(cl); |
1407 | } | 1413 | } |
1408 | 1414 | ||
@@ -1485,14 +1491,13 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) | |||
1485 | 1491 | ||
1486 | sema_init(&c->sb_write_mutex, 1); | 1492 | sema_init(&c->sb_write_mutex, 1); |
1487 | mutex_init(&c->bucket_lock); | 1493 | mutex_init(&c->bucket_lock); |
1488 | init_waitqueue_head(&c->try_wait); | 1494 | init_waitqueue_head(&c->btree_cache_wait); |
1489 | init_waitqueue_head(&c->bucket_wait); | 1495 | init_waitqueue_head(&c->bucket_wait); |
1490 | sema_init(&c->uuid_write_mutex, 1); | 1496 | sema_init(&c->uuid_write_mutex, 1); |
1491 | 1497 | ||
1492 | spin_lock_init(&c->btree_gc_time.lock); | 1498 | spin_lock_init(&c->btree_gc_time.lock); |
1493 | spin_lock_init(&c->btree_split_time.lock); | 1499 | spin_lock_init(&c->btree_split_time.lock); |
1494 | spin_lock_init(&c->btree_read_time.lock); | 1500 | spin_lock_init(&c->btree_read_time.lock); |
1495 | spin_lock_init(&c->try_harder_time.lock); | ||
1496 | 1501 | ||
1497 | bch_moving_init_cache_set(c); | 1502 | bch_moving_init_cache_set(c); |
1498 | 1503 | ||
@@ -1517,6 +1522,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) | |||
1517 | !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) || | 1522 | !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) || |
1518 | !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || | 1523 | !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || |
1519 | !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) || | 1524 | !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) || |
1525 | !(c->moving_gc_wq = create_workqueue("bcache_gc")) || | ||
1520 | bch_journal_alloc(c) || | 1526 | bch_journal_alloc(c) || |
1521 | bch_btree_cache_alloc(c) || | 1527 | bch_btree_cache_alloc(c) || |
1522 | bch_open_buckets_alloc(c) || | 1528 | bch_open_buckets_alloc(c) || |
@@ -1580,7 +1586,7 @@ static void run_cache_set(struct cache_set *c) | |||
1580 | goto err; | 1586 | goto err; |
1581 | 1587 | ||
1582 | err = "error reading btree root"; | 1588 | err = "error reading btree root"; |
1583 | c->root = bch_btree_node_get(c, k, j->btree_level, true); | 1589 | c->root = bch_btree_node_get(c, NULL, k, j->btree_level, true); |
1584 | if (IS_ERR_OR_NULL(c->root)) | 1590 | if (IS_ERR_OR_NULL(c->root)) |
1585 | goto err; | 1591 | goto err; |
1586 | 1592 | ||
@@ -1596,7 +1602,7 @@ static void run_cache_set(struct cache_set *c) | |||
1596 | goto err; | 1602 | goto err; |
1597 | 1603 | ||
1598 | bch_journal_mark(c, &journal); | 1604 | bch_journal_mark(c, &journal); |
1599 | bch_btree_gc_finish(c); | 1605 | bch_initial_gc_finish(c); |
1600 | pr_debug("btree_check() done"); | 1606 | pr_debug("btree_check() done"); |
1601 | 1607 | ||
1602 | /* | 1608 | /* |
@@ -1638,7 +1644,7 @@ static void run_cache_set(struct cache_set *c) | |||
1638 | ca->sb.d[j] = ca->sb.first_bucket + j; | 1644 | ca->sb.d[j] = ca->sb.first_bucket + j; |
1639 | } | 1645 | } |
1640 | 1646 | ||
1641 | bch_btree_gc_finish(c); | 1647 | bch_initial_gc_finish(c); |
1642 | 1648 | ||
1643 | err = "error starting allocator thread"; | 1649 | err = "error starting allocator thread"; |
1644 | for_each_cache(ca, c, i) | 1650 | for_each_cache(ca, c, i) |
@@ -1655,12 +1661,14 @@ static void run_cache_set(struct cache_set *c) | |||
1655 | goto err; | 1661 | goto err; |
1656 | 1662 | ||
1657 | err = "cannot allocate new btree root"; | 1663 | err = "cannot allocate new btree root"; |
1658 | c->root = bch_btree_node_alloc(c, 0, true); | 1664 | c->root = bch_btree_node_alloc(c, NULL, 0); |
1659 | if (IS_ERR_OR_NULL(c->root)) | 1665 | if (IS_ERR_OR_NULL(c->root)) |
1660 | goto err; | 1666 | goto err; |
1661 | 1667 | ||
1668 | mutex_lock(&c->root->write_lock); | ||
1662 | bkey_copy_key(&c->root->key, &MAX_KEY); | 1669 | bkey_copy_key(&c->root->key, &MAX_KEY); |
1663 | bch_btree_node_write(c->root, &cl); | 1670 | bch_btree_node_write(c->root, &cl); |
1671 | mutex_unlock(&c->root->write_lock); | ||
1664 | 1672 | ||
1665 | bch_btree_set_root(c->root); | 1673 | bch_btree_set_root(c->root); |
1666 | rw_unlock(true, c->root); | 1674 | rw_unlock(true, c->root); |
@@ -1782,7 +1790,6 @@ void bch_cache_release(struct kobject *kobj) | |||
1782 | vfree(ca->buckets); | 1790 | vfree(ca->buckets); |
1783 | 1791 | ||
1784 | free_heap(&ca->heap); | 1792 | free_heap(&ca->heap); |
1785 | free_fifo(&ca->unused); | ||
1786 | free_fifo(&ca->free_inc); | 1793 | free_fifo(&ca->free_inc); |
1787 | 1794 | ||
1788 | for (i = 0; i < RESERVE_NR; i++) | 1795 | for (i = 0; i < RESERVE_NR; i++) |
@@ -1819,7 +1826,6 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca) | |||
1819 | !init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL) || | 1826 | !init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL) || |
1820 | !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || | 1827 | !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || |
1821 | !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || | 1828 | !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || |
1822 | !init_fifo(&ca->unused, free << 2, GFP_KERNEL) || | ||
1823 | !init_heap(&ca->heap, free << 3, GFP_KERNEL) || | 1829 | !init_heap(&ca->heap, free << 3, GFP_KERNEL) || |
1824 | !(ca->buckets = vzalloc(sizeof(struct bucket) * | 1830 | !(ca->buckets = vzalloc(sizeof(struct bucket) * |
1825 | ca->sb.nbuckets)) || | 1831 | ca->sb.nbuckets)) || |
@@ -1834,13 +1840,7 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca) | |||
1834 | for_each_bucket(b, ca) | 1840 | for_each_bucket(b, ca) |
1835 | atomic_set(&b->pin, 0); | 1841 | atomic_set(&b->pin, 0); |
1836 | 1842 | ||
1837 | if (bch_cache_allocator_init(ca)) | ||
1838 | goto err; | ||
1839 | |||
1840 | return 0; | 1843 | return 0; |
1841 | err: | ||
1842 | kobject_put(&ca->kobj); | ||
1843 | return -ENOMEM; | ||
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | static void register_cache(struct cache_sb *sb, struct page *sb_page, | 1846 | static void register_cache(struct cache_sb *sb, struct page *sb_page, |
@@ -1869,7 +1869,10 @@ static void register_cache(struct cache_sb *sb, struct page *sb_page, | |||
1869 | if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache")) | 1869 | if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache")) |
1870 | goto err; | 1870 | goto err; |
1871 | 1871 | ||
1872 | mutex_lock(&bch_register_lock); | ||
1872 | err = register_cache_set(ca); | 1873 | err = register_cache_set(ca); |
1874 | mutex_unlock(&bch_register_lock); | ||
1875 | |||
1873 | if (err) | 1876 | if (err) |
1874 | goto err; | 1877 | goto err; |
1875 | 1878 | ||
@@ -1931,8 +1934,6 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, | |||
1931 | if (!try_module_get(THIS_MODULE)) | 1934 | if (!try_module_get(THIS_MODULE)) |
1932 | return -EBUSY; | 1935 | return -EBUSY; |
1933 | 1936 | ||
1934 | mutex_lock(&bch_register_lock); | ||
1935 | |||
1936 | if (!(path = kstrndup(buffer, size, GFP_KERNEL)) || | 1937 | if (!(path = kstrndup(buffer, size, GFP_KERNEL)) || |
1937 | !(sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL))) | 1938 | !(sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL))) |
1938 | goto err; | 1939 | goto err; |
@@ -1965,7 +1966,9 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, | |||
1965 | if (!dc) | 1966 | if (!dc) |
1966 | goto err_close; | 1967 | goto err_close; |
1967 | 1968 | ||
1969 | mutex_lock(&bch_register_lock); | ||
1968 | register_bdev(sb, sb_page, bdev, dc); | 1970 | register_bdev(sb, sb_page, bdev, dc); |
1971 | mutex_unlock(&bch_register_lock); | ||
1969 | } else { | 1972 | } else { |
1970 | struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); | 1973 | struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); |
1971 | if (!ca) | 1974 | if (!ca) |
@@ -1978,7 +1981,6 @@ out: | |||
1978 | put_page(sb_page); | 1981 | put_page(sb_page); |
1979 | kfree(sb); | 1982 | kfree(sb); |
1980 | kfree(path); | 1983 | kfree(path); |
1981 | mutex_unlock(&bch_register_lock); | ||
1982 | module_put(THIS_MODULE); | 1984 | module_put(THIS_MODULE); |
1983 | return ret; | 1985 | return ret; |
1984 | 1986 | ||
@@ -2057,7 +2059,6 @@ static void bcache_exit(void) | |||
2057 | { | 2059 | { |
2058 | bch_debug_exit(); | 2060 | bch_debug_exit(); |
2059 | bch_request_exit(); | 2061 | bch_request_exit(); |
2060 | bch_btree_exit(); | ||
2061 | if (bcache_kobj) | 2062 | if (bcache_kobj) |
2062 | kobject_put(bcache_kobj); | 2063 | kobject_put(bcache_kobj); |
2063 | if (bcache_wq) | 2064 | if (bcache_wq) |
@@ -2087,7 +2088,6 @@ static int __init bcache_init(void) | |||
2087 | if (!(bcache_wq = create_workqueue("bcache")) || | 2088 | if (!(bcache_wq = create_workqueue("bcache")) || |
2088 | !(bcache_kobj = kobject_create_and_add("bcache", fs_kobj)) || | 2089 | !(bcache_kobj = kobject_create_and_add("bcache", fs_kobj)) || |
2089 | sysfs_create_files(bcache_kobj, files) || | 2090 | sysfs_create_files(bcache_kobj, files) || |
2090 | bch_btree_init() || | ||
2091 | bch_request_init() || | 2091 | bch_request_init() || |
2092 | bch_debug_init(bcache_kobj)) | 2092 | bch_debug_init(bcache_kobj)) |
2093 | goto err; | 2093 | goto err; |
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index d8458d477a12..b3ff57d61dde 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c | |||
@@ -54,7 +54,6 @@ sysfs_time_stats_attribute(btree_gc, sec, ms); | |||
54 | sysfs_time_stats_attribute(btree_split, sec, us); | 54 | sysfs_time_stats_attribute(btree_split, sec, us); |
55 | sysfs_time_stats_attribute(btree_sort, ms, us); | 55 | sysfs_time_stats_attribute(btree_sort, ms, us); |
56 | sysfs_time_stats_attribute(btree_read, ms, us); | 56 | sysfs_time_stats_attribute(btree_read, ms, us); |
57 | sysfs_time_stats_attribute(try_harder, ms, us); | ||
58 | 57 | ||
59 | read_attribute(btree_nodes); | 58 | read_attribute(btree_nodes); |
60 | read_attribute(btree_used_percent); | 59 | read_attribute(btree_used_percent); |
@@ -406,7 +405,7 @@ struct bset_stats_op { | |||
406 | struct bset_stats stats; | 405 | struct bset_stats stats; |
407 | }; | 406 | }; |
408 | 407 | ||
409 | static int btree_bset_stats(struct btree_op *b_op, struct btree *b) | 408 | static int bch_btree_bset_stats(struct btree_op *b_op, struct btree *b) |
410 | { | 409 | { |
411 | struct bset_stats_op *op = container_of(b_op, struct bset_stats_op, op); | 410 | struct bset_stats_op *op = container_of(b_op, struct bset_stats_op, op); |
412 | 411 | ||
@@ -424,7 +423,7 @@ static int bch_bset_print_stats(struct cache_set *c, char *buf) | |||
424 | memset(&op, 0, sizeof(op)); | 423 | memset(&op, 0, sizeof(op)); |
425 | bch_btree_op_init(&op.op, -1); | 424 | bch_btree_op_init(&op.op, -1); |
426 | 425 | ||
427 | ret = bch_btree_map_nodes(&op.op, c, &ZERO_KEY, btree_bset_stats); | 426 | ret = bch_btree_map_nodes(&op.op, c, &ZERO_KEY, bch_btree_bset_stats); |
428 | if (ret < 0) | 427 | if (ret < 0) |
429 | return ret; | 428 | return ret; |
430 | 429 | ||
@@ -442,81 +441,81 @@ static int bch_bset_print_stats(struct cache_set *c, char *buf) | |||
442 | op.stats.floats, op.stats.failed); | 441 | op.stats.floats, op.stats.failed); |
443 | } | 442 | } |
444 | 443 | ||
445 | SHOW(__bch_cache_set) | 444 | static unsigned bch_root_usage(struct cache_set *c) |
446 | { | 445 | { |
447 | unsigned root_usage(struct cache_set *c) | 446 | unsigned bytes = 0; |
448 | { | 447 | struct bkey *k; |
449 | unsigned bytes = 0; | 448 | struct btree *b; |
450 | struct bkey *k; | 449 | struct btree_iter iter; |
451 | struct btree *b; | ||
452 | struct btree_iter iter; | ||
453 | 450 | ||
454 | goto lock_root; | 451 | goto lock_root; |
455 | 452 | ||
456 | do { | 453 | do { |
457 | rw_unlock(false, b); | 454 | rw_unlock(false, b); |
458 | lock_root: | 455 | lock_root: |
459 | b = c->root; | 456 | b = c->root; |
460 | rw_lock(false, b, b->level); | 457 | rw_lock(false, b, b->level); |
461 | } while (b != c->root); | 458 | } while (b != c->root); |
462 | 459 | ||
463 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad) | 460 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad) |
464 | bytes += bkey_bytes(k); | 461 | bytes += bkey_bytes(k); |
465 | 462 | ||
466 | rw_unlock(false, b); | 463 | rw_unlock(false, b); |
467 | 464 | ||
468 | return (bytes * 100) / btree_bytes(c); | 465 | return (bytes * 100) / btree_bytes(c); |
469 | } | 466 | } |
470 | 467 | ||
471 | size_t cache_size(struct cache_set *c) | 468 | static size_t bch_cache_size(struct cache_set *c) |
472 | { | 469 | { |
473 | size_t ret = 0; | 470 | size_t ret = 0; |
474 | struct btree *b; | 471 | struct btree *b; |
475 | 472 | ||
476 | mutex_lock(&c->bucket_lock); | 473 | mutex_lock(&c->bucket_lock); |
477 | list_for_each_entry(b, &c->btree_cache, list) | 474 | list_for_each_entry(b, &c->btree_cache, list) |
478 | ret += 1 << (b->keys.page_order + PAGE_SHIFT); | 475 | ret += 1 << (b->keys.page_order + PAGE_SHIFT); |
479 | 476 | ||
480 | mutex_unlock(&c->bucket_lock); | 477 | mutex_unlock(&c->bucket_lock); |
481 | return ret; | 478 | return ret; |
482 | } | 479 | } |
483 | |||
484 | unsigned cache_max_chain(struct cache_set *c) | ||
485 | { | ||
486 | unsigned ret = 0; | ||
487 | struct hlist_head *h; | ||
488 | 480 | ||
489 | mutex_lock(&c->bucket_lock); | 481 | static unsigned bch_cache_max_chain(struct cache_set *c) |
482 | { | ||
483 | unsigned ret = 0; | ||
484 | struct hlist_head *h; | ||
490 | 485 | ||
491 | for (h = c->bucket_hash; | 486 | mutex_lock(&c->bucket_lock); |
492 | h < c->bucket_hash + (1 << BUCKET_HASH_BITS); | ||
493 | h++) { | ||
494 | unsigned i = 0; | ||
495 | struct hlist_node *p; | ||
496 | 487 | ||
497 | hlist_for_each(p, h) | 488 | for (h = c->bucket_hash; |
498 | i++; | 489 | h < c->bucket_hash + (1 << BUCKET_HASH_BITS); |
490 | h++) { | ||
491 | unsigned i = 0; | ||
492 | struct hlist_node *p; | ||
499 | 493 | ||
500 | ret = max(ret, i); | 494 | hlist_for_each(p, h) |
501 | } | 495 | i++; |
502 | 496 | ||
503 | mutex_unlock(&c->bucket_lock); | 497 | ret = max(ret, i); |
504 | return ret; | ||
505 | } | 498 | } |
506 | 499 | ||
507 | unsigned btree_used(struct cache_set *c) | 500 | mutex_unlock(&c->bucket_lock); |
508 | { | 501 | return ret; |
509 | return div64_u64(c->gc_stats.key_bytes * 100, | 502 | } |
510 | (c->gc_stats.nodes ?: 1) * btree_bytes(c)); | ||
511 | } | ||
512 | 503 | ||
513 | unsigned average_key_size(struct cache_set *c) | 504 | static unsigned bch_btree_used(struct cache_set *c) |
514 | { | 505 | { |
515 | return c->gc_stats.nkeys | 506 | return div64_u64(c->gc_stats.key_bytes * 100, |
516 | ? div64_u64(c->gc_stats.data, c->gc_stats.nkeys) | 507 | (c->gc_stats.nodes ?: 1) * btree_bytes(c)); |
517 | : 0; | 508 | } |
518 | } | ||
519 | 509 | ||
510 | static unsigned bch_average_key_size(struct cache_set *c) | ||
511 | { | ||
512 | return c->gc_stats.nkeys | ||
513 | ? div64_u64(c->gc_stats.data, c->gc_stats.nkeys) | ||
514 | : 0; | ||
515 | } | ||
516 | |||
517 | SHOW(__bch_cache_set) | ||
518 | { | ||
520 | struct cache_set *c = container_of(kobj, struct cache_set, kobj); | 519 | struct cache_set *c = container_of(kobj, struct cache_set, kobj); |
521 | 520 | ||
522 | sysfs_print(synchronous, CACHE_SYNC(&c->sb)); | 521 | sysfs_print(synchronous, CACHE_SYNC(&c->sb)); |
@@ -524,21 +523,20 @@ lock_root: | |||
524 | sysfs_hprint(bucket_size, bucket_bytes(c)); | 523 | sysfs_hprint(bucket_size, bucket_bytes(c)); |
525 | sysfs_hprint(block_size, block_bytes(c)); | 524 | sysfs_hprint(block_size, block_bytes(c)); |
526 | sysfs_print(tree_depth, c->root->level); | 525 | sysfs_print(tree_depth, c->root->level); |
527 | sysfs_print(root_usage_percent, root_usage(c)); | 526 | sysfs_print(root_usage_percent, bch_root_usage(c)); |
528 | 527 | ||
529 | sysfs_hprint(btree_cache_size, cache_size(c)); | 528 | sysfs_hprint(btree_cache_size, bch_cache_size(c)); |
530 | sysfs_print(btree_cache_max_chain, cache_max_chain(c)); | 529 | sysfs_print(btree_cache_max_chain, bch_cache_max_chain(c)); |
531 | sysfs_print(cache_available_percent, 100 - c->gc_stats.in_use); | 530 | sysfs_print(cache_available_percent, 100 - c->gc_stats.in_use); |
532 | 531 | ||
533 | sysfs_print_time_stats(&c->btree_gc_time, btree_gc, sec, ms); | 532 | sysfs_print_time_stats(&c->btree_gc_time, btree_gc, sec, ms); |
534 | sysfs_print_time_stats(&c->btree_split_time, btree_split, sec, us); | 533 | sysfs_print_time_stats(&c->btree_split_time, btree_split, sec, us); |
535 | sysfs_print_time_stats(&c->sort.time, btree_sort, ms, us); | 534 | sysfs_print_time_stats(&c->sort.time, btree_sort, ms, us); |
536 | sysfs_print_time_stats(&c->btree_read_time, btree_read, ms, us); | 535 | sysfs_print_time_stats(&c->btree_read_time, btree_read, ms, us); |
537 | sysfs_print_time_stats(&c->try_harder_time, try_harder, ms, us); | ||
538 | 536 | ||
539 | sysfs_print(btree_used_percent, btree_used(c)); | 537 | sysfs_print(btree_used_percent, bch_btree_used(c)); |
540 | sysfs_print(btree_nodes, c->gc_stats.nodes); | 538 | sysfs_print(btree_nodes, c->gc_stats.nodes); |
541 | sysfs_hprint(average_key_size, average_key_size(c)); | 539 | sysfs_hprint(average_key_size, bch_average_key_size(c)); |
542 | 540 | ||
543 | sysfs_print(cache_read_races, | 541 | sysfs_print(cache_read_races, |
544 | atomic_long_read(&c->cache_read_races)); | 542 | atomic_long_read(&c->cache_read_races)); |
@@ -709,7 +707,6 @@ static struct attribute *bch_cache_set_internal_files[] = { | |||
709 | sysfs_time_stats_attribute_list(btree_split, sec, us) | 707 | sysfs_time_stats_attribute_list(btree_split, sec, us) |
710 | sysfs_time_stats_attribute_list(btree_sort, ms, us) | 708 | sysfs_time_stats_attribute_list(btree_sort, ms, us) |
711 | sysfs_time_stats_attribute_list(btree_read, ms, us) | 709 | sysfs_time_stats_attribute_list(btree_read, ms, us) |
712 | sysfs_time_stats_attribute_list(try_harder, ms, us) | ||
713 | 710 | ||
714 | &sysfs_btree_nodes, | 711 | &sysfs_btree_nodes, |
715 | &sysfs_btree_used_percent, | 712 | &sysfs_btree_used_percent, |
@@ -761,7 +758,9 @@ SHOW(__bch_cache) | |||
761 | int cmp(const void *l, const void *r) | 758 | int cmp(const void *l, const void *r) |
762 | { return *((uint16_t *) r) - *((uint16_t *) l); } | 759 | { return *((uint16_t *) r) - *((uint16_t *) l); } |
763 | 760 | ||
764 | size_t n = ca->sb.nbuckets, i, unused, btree; | 761 | struct bucket *b; |
762 | size_t n = ca->sb.nbuckets, i; | ||
763 | size_t unused = 0, available = 0, dirty = 0, meta = 0; | ||
765 | uint64_t sum = 0; | 764 | uint64_t sum = 0; |
766 | /* Compute 31 quantiles */ | 765 | /* Compute 31 quantiles */ |
767 | uint16_t q[31], *p, *cached; | 766 | uint16_t q[31], *p, *cached; |
@@ -772,6 +771,17 @@ SHOW(__bch_cache) | |||
772 | return -ENOMEM; | 771 | return -ENOMEM; |
773 | 772 | ||
774 | mutex_lock(&ca->set->bucket_lock); | 773 | mutex_lock(&ca->set->bucket_lock); |
774 | for_each_bucket(b, ca) { | ||
775 | if (!GC_SECTORS_USED(b)) | ||
776 | unused++; | ||
777 | if (GC_MARK(b) == GC_MARK_RECLAIMABLE) | ||
778 | available++; | ||
779 | if (GC_MARK(b) == GC_MARK_DIRTY) | ||
780 | dirty++; | ||
781 | if (GC_MARK(b) == GC_MARK_METADATA) | ||
782 | meta++; | ||
783 | } | ||
784 | |||
775 | for (i = ca->sb.first_bucket; i < n; i++) | 785 | for (i = ca->sb.first_bucket; i < n; i++) |
776 | p[i] = ca->buckets[i].prio; | 786 | p[i] = ca->buckets[i].prio; |
777 | mutex_unlock(&ca->set->bucket_lock); | 787 | mutex_unlock(&ca->set->bucket_lock); |
@@ -786,10 +796,7 @@ SHOW(__bch_cache) | |||
786 | 796 | ||
787 | while (cached < p + n && | 797 | while (cached < p + n && |
788 | *cached == BTREE_PRIO) | 798 | *cached == BTREE_PRIO) |
789 | cached++; | 799 | cached++, n--; |
790 | |||
791 | btree = cached - p; | ||
792 | n -= btree; | ||
793 | 800 | ||
794 | for (i = 0; i < n; i++) | 801 | for (i = 0; i < n; i++) |
795 | sum += INITIAL_PRIO - cached[i]; | 802 | sum += INITIAL_PRIO - cached[i]; |
@@ -805,12 +812,16 @@ SHOW(__bch_cache) | |||
805 | 812 | ||
806 | ret = scnprintf(buf, PAGE_SIZE, | 813 | ret = scnprintf(buf, PAGE_SIZE, |
807 | "Unused: %zu%%\n" | 814 | "Unused: %zu%%\n" |
815 | "Clean: %zu%%\n" | ||
816 | "Dirty: %zu%%\n" | ||
808 | "Metadata: %zu%%\n" | 817 | "Metadata: %zu%%\n" |
809 | "Average: %llu\n" | 818 | "Average: %llu\n" |
810 | "Sectors per Q: %zu\n" | 819 | "Sectors per Q: %zu\n" |
811 | "Quantiles: [", | 820 | "Quantiles: [", |
812 | unused * 100 / (size_t) ca->sb.nbuckets, | 821 | unused * 100 / (size_t) ca->sb.nbuckets, |
813 | btree * 100 / (size_t) ca->sb.nbuckets, sum, | 822 | available * 100 / (size_t) ca->sb.nbuckets, |
823 | dirty * 100 / (size_t) ca->sb.nbuckets, | ||
824 | meta * 100 / (size_t) ca->sb.nbuckets, sum, | ||
814 | n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1)); | 825 | n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1)); |
815 | 826 | ||
816 | for (i = 0; i < ARRAY_SIZE(q); i++) | 827 | for (i = 0; i < ARRAY_SIZE(q); i++) |
diff --git a/drivers/md/bcache/trace.c b/drivers/md/bcache/trace.c index adbc3df17a80..b7820b0d2621 100644 --- a/drivers/md/bcache/trace.c +++ b/drivers/md/bcache/trace.c | |||
@@ -45,7 +45,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_btree_node_split); | |||
45 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_btree_node_compact); | 45 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_btree_node_compact); |
46 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_btree_set_root); | 46 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_btree_set_root); |
47 | 47 | ||
48 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_alloc_invalidate); | 48 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_invalidate); |
49 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_alloc_fail); | 49 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_alloc_fail); |
50 | 50 | ||
51 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_writeback); | 51 | EXPORT_TRACEPOINT_SYMBOL_GPL(bcache_writeback); |
diff --git a/include/linux/drbd.h b/include/linux/drbd.h index de7d74ab3de6..3dbe9bd57a09 100644 --- a/include/linux/drbd.h +++ b/include/linux/drbd.h | |||
@@ -327,12 +327,6 @@ enum drbd_state_rv { | |||
327 | SS_AFTER_LAST_ERROR = -22, /* Keep this at bottom */ | 327 | SS_AFTER_LAST_ERROR = -22, /* Keep this at bottom */ |
328 | }; | 328 | }; |
329 | 329 | ||
330 | /* from drbd_strings.c */ | ||
331 | extern const char *drbd_conn_str(enum drbd_conns); | ||
332 | extern const char *drbd_role_str(enum drbd_role); | ||
333 | extern const char *drbd_disk_str(enum drbd_disk_state); | ||
334 | extern const char *drbd_set_st_err_str(enum drbd_state_rv); | ||
335 | |||
336 | #define SHARED_SECRET_MAX 64 | 330 | #define SHARED_SECRET_MAX 64 |
337 | 331 | ||
338 | #define MDF_CONSISTENT (1 << 0) | 332 | #define MDF_CONSISTENT (1 << 0) |
@@ -382,4 +376,6 @@ enum drbd_timeout_flag { | |||
382 | #define DRBD_MD_INDEX_FLEX_EXT -2 | 376 | #define DRBD_MD_INDEX_FLEX_EXT -2 |
383 | #define DRBD_MD_INDEX_FLEX_INT -3 | 377 | #define DRBD_MD_INDEX_FLEX_INT -3 |
384 | 378 | ||
379 | #define DRBD_CPU_MASK_SIZE 32 | ||
380 | |||
385 | #endif | 381 | #endif |
diff --git a/include/linux/drbd_genl.h b/include/linux/drbd_genl.h index e8c44572b8cb..4193f5f2636c 100644 --- a/include/linux/drbd_genl.h +++ b/include/linux/drbd_genl.h | |||
@@ -135,7 +135,7 @@ GENL_struct(DRBD_NLA_DISK_CONF, 3, disk_conf, | |||
135 | ) | 135 | ) |
136 | 136 | ||
137 | GENL_struct(DRBD_NLA_RESOURCE_OPTS, 4, res_opts, | 137 | GENL_struct(DRBD_NLA_RESOURCE_OPTS, 4, res_opts, |
138 | __str_field_def(1, DRBD_GENLA_F_MANDATORY, cpu_mask, 32) | 138 | __str_field_def(1, DRBD_GENLA_F_MANDATORY, cpu_mask, DRBD_CPU_MASK_SIZE) |
139 | __u32_field_def(2, DRBD_GENLA_F_MANDATORY, on_no_data, DRBD_ON_NO_DATA_DEF) | 139 | __u32_field_def(2, DRBD_GENLA_F_MANDATORY, on_no_data, DRBD_ON_NO_DATA_DEF) |
140 | ) | 140 | ) |
141 | 141 | ||
@@ -276,9 +276,9 @@ GENL_op( | |||
276 | ) | 276 | ) |
277 | 277 | ||
278 | /* add DRBD minor devices as volumes to resources */ | 278 | /* add DRBD minor devices as volumes to resources */ |
279 | GENL_op(DRBD_ADM_NEW_MINOR, 5, GENL_doit(drbd_adm_add_minor), | 279 | GENL_op(DRBD_ADM_NEW_MINOR, 5, GENL_doit(drbd_adm_new_minor), |
280 | GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, DRBD_F_REQUIRED)) | 280 | GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, DRBD_F_REQUIRED)) |
281 | GENL_op(DRBD_ADM_DEL_MINOR, 6, GENL_doit(drbd_adm_delete_minor), | 281 | GENL_op(DRBD_ADM_DEL_MINOR, 6, GENL_doit(drbd_adm_del_minor), |
282 | GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, DRBD_F_REQUIRED)) | 282 | GENL_tla_expected(DRBD_NLA_CFG_CONTEXT, DRBD_F_REQUIRED)) |
283 | 283 | ||
284 | /* add or delete resources */ | 284 | /* add or delete resources */ |
diff --git a/include/linux/idr.h b/include/linux/idr.h index 871a213a8477..9c95d210458b 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h | |||
@@ -85,6 +85,7 @@ void idr_remove(struct idr *idp, int id); | |||
85 | void idr_free(struct idr *idp, int id); | 85 | void idr_free(struct idr *idp, int id); |
86 | void idr_destroy(struct idr *idp); | 86 | void idr_destroy(struct idr *idp); |
87 | void idr_init(struct idr *idp); | 87 | void idr_init(struct idr *idp); |
88 | bool idr_is_empty(struct idr *idp); | ||
88 | 89 | ||
89 | /** | 90 | /** |
90 | * idr_preload_end - end preload section started with idr_preload() | 91 | * idr_preload_end - end preload section started with idr_preload() |
diff --git a/include/trace/events/bcache.h b/include/trace/events/bcache.h index 7110897c3dfa..c9c3c044b32f 100644 --- a/include/trace/events/bcache.h +++ b/include/trace/events/bcache.h | |||
@@ -399,26 +399,43 @@ TRACE_EVENT(bcache_keyscan, | |||
399 | 399 | ||
400 | /* Allocator */ | 400 | /* Allocator */ |
401 | 401 | ||
402 | TRACE_EVENT(bcache_alloc_invalidate, | 402 | TRACE_EVENT(bcache_invalidate, |
403 | TP_PROTO(struct cache *ca), | 403 | TP_PROTO(struct cache *ca, size_t bucket), |
404 | TP_ARGS(ca), | 404 | TP_ARGS(ca, bucket), |
405 | 405 | ||
406 | TP_STRUCT__entry( | 406 | TP_STRUCT__entry( |
407 | __field(unsigned, free ) | 407 | __field(unsigned, sectors ) |
408 | __field(unsigned, free_inc ) | 408 | __field(dev_t, dev ) |
409 | __field(unsigned, free_inc_size ) | 409 | __field(__u64, offset ) |
410 | __field(unsigned, unused ) | ||
411 | ), | 410 | ), |
412 | 411 | ||
413 | TP_fast_assign( | 412 | TP_fast_assign( |
414 | __entry->free = fifo_used(&ca->free[RESERVE_NONE]); | 413 | __entry->dev = ca->bdev->bd_dev; |
415 | __entry->free_inc = fifo_used(&ca->free_inc); | 414 | __entry->offset = bucket << ca->set->bucket_bits; |
416 | __entry->free_inc_size = ca->free_inc.size; | 415 | __entry->sectors = GC_SECTORS_USED(&ca->buckets[bucket]); |
417 | __entry->unused = fifo_used(&ca->unused); | ||
418 | ), | 416 | ), |
419 | 417 | ||
420 | TP_printk("free %u free_inc %u/%u unused %u", __entry->free, | 418 | TP_printk("invalidated %u sectors at %d,%d sector=%llu", |
421 | __entry->free_inc, __entry->free_inc_size, __entry->unused) | 419 | __entry->sectors, MAJOR(__entry->dev), |
420 | MINOR(__entry->dev), __entry->offset) | ||
421 | ); | ||
422 | |||
423 | TRACE_EVENT(bcache_alloc, | ||
424 | TP_PROTO(struct cache *ca, size_t bucket), | ||
425 | TP_ARGS(ca, bucket), | ||
426 | |||
427 | TP_STRUCT__entry( | ||
428 | __field(dev_t, dev ) | ||
429 | __field(__u64, offset ) | ||
430 | ), | ||
431 | |||
432 | TP_fast_assign( | ||
433 | __entry->dev = ca->bdev->bd_dev; | ||
434 | __entry->offset = bucket << ca->set->bucket_bits; | ||
435 | ), | ||
436 | |||
437 | TP_printk("allocated %d,%d sector=%llu", MAJOR(__entry->dev), | ||
438 | MINOR(__entry->dev), __entry->offset) | ||
422 | ); | 439 | ); |
423 | 440 | ||
424 | TRACE_EVENT(bcache_alloc_fail, | 441 | TRACE_EVENT(bcache_alloc_fail, |
@@ -426,21 +443,22 @@ TRACE_EVENT(bcache_alloc_fail, | |||
426 | TP_ARGS(ca, reserve), | 443 | TP_ARGS(ca, reserve), |
427 | 444 | ||
428 | TP_STRUCT__entry( | 445 | TP_STRUCT__entry( |
446 | __field(dev_t, dev ) | ||
429 | __field(unsigned, free ) | 447 | __field(unsigned, free ) |
430 | __field(unsigned, free_inc ) | 448 | __field(unsigned, free_inc ) |
431 | __field(unsigned, unused ) | ||
432 | __field(unsigned, blocked ) | 449 | __field(unsigned, blocked ) |
433 | ), | 450 | ), |
434 | 451 | ||
435 | TP_fast_assign( | 452 | TP_fast_assign( |
453 | __entry->dev = ca->bdev->bd_dev; | ||
436 | __entry->free = fifo_used(&ca->free[reserve]); | 454 | __entry->free = fifo_used(&ca->free[reserve]); |
437 | __entry->free_inc = fifo_used(&ca->free_inc); | 455 | __entry->free_inc = fifo_used(&ca->free_inc); |
438 | __entry->unused = fifo_used(&ca->unused); | ||
439 | __entry->blocked = atomic_read(&ca->set->prio_blocked); | 456 | __entry->blocked = atomic_read(&ca->set->prio_blocked); |
440 | ), | 457 | ), |
441 | 458 | ||
442 | TP_printk("free %u free_inc %u unused %u blocked %u", __entry->free, | 459 | TP_printk("alloc fail %d,%d free %u free_inc %u blocked %u", |
443 | __entry->free_inc, __entry->unused, __entry->blocked) | 460 | MAJOR(__entry->dev), MINOR(__entry->dev), __entry->free, |
461 | __entry->free_inc, __entry->blocked) | ||
444 | ); | 462 | ); |
445 | 463 | ||
446 | /* Background writeback */ | 464 | /* Background writeback */ |
@@ -869,6 +869,16 @@ void idr_init(struct idr *idp) | |||
869 | } | 869 | } |
870 | EXPORT_SYMBOL(idr_init); | 870 | EXPORT_SYMBOL(idr_init); |
871 | 871 | ||
872 | static int idr_has_entry(int id, void *p, void *data) | ||
873 | { | ||
874 | return 1; | ||
875 | } | ||
876 | |||
877 | bool idr_is_empty(struct idr *idp) | ||
878 | { | ||
879 | return !idr_for_each(idp, idr_has_entry, NULL); | ||
880 | } | ||
881 | EXPORT_SYMBOL(idr_is_empty); | ||
872 | 882 | ||
873 | /** | 883 | /** |
874 | * DOC: IDA description | 884 | * DOC: IDA description |