blob: 7a2faf6d48e26d6506a1c5d47e088d50337e6a0d [file] [log] [blame]
Philipp Reisnerb411b362009-09-25 16:07:19 -07001/*
2 drbd_nl.c
3
4 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5
6 Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
7 Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
8 Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
9
10 drbd is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 drbd is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with drbd; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 */
25
Philipp Reisnerb411b362009-09-25 16:07:19 -070026#include <linux/module.h>
27#include <linux/drbd.h>
28#include <linux/in.h>
29#include <linux/fs.h>
30#include <linux/file.h>
31#include <linux/slab.h>
32#include <linux/connector.h>
33#include <linux/blkpg.h>
34#include <linux/cpumask.h>
35#include "drbd_int.h"
Philipp Reisner265be2d2010-05-31 10:14:17 +020036#include "drbd_req.h"
Philipp Reisnerb411b362009-09-25 16:07:19 -070037#include "drbd_wrappers.h"
38#include <asm/unaligned.h>
39#include <linux/drbd_tag_magic.h>
40#include <linux/drbd_limits.h>
Philipp Reisner87f7be42010-06-11 13:56:33 +020041#include <linux/compiler.h>
42#include <linux/kthread.h>
Philipp Reisnerb411b362009-09-25 16:07:19 -070043
44static unsigned short *tl_add_blob(unsigned short *, enum drbd_tags, const void *, int);
45static unsigned short *tl_add_str(unsigned short *, enum drbd_tags, const char *);
46static unsigned short *tl_add_int(unsigned short *, enum drbd_tags, const void *);
47
48/* see get_sb_bdev and bd_claim */
49static char *drbd_m_holder = "Hands off! this is DRBD's meta data device.";
50
51/* Generate the tag_list to struct functions */
52#define NL_PACKET(name, number, fields) \
53static int name ## _from_tags(struct drbd_conf *mdev, \
54 unsigned short *tags, struct name *arg) __attribute__ ((unused)); \
55static int name ## _from_tags(struct drbd_conf *mdev, \
56 unsigned short *tags, struct name *arg) \
57{ \
58 int tag; \
59 int dlen; \
60 \
61 while ((tag = get_unaligned(tags++)) != TT_END) { \
62 dlen = get_unaligned(tags++); \
63 switch (tag_number(tag)) { \
64 fields \
65 default: \
66 if (tag & T_MANDATORY) { \
67 dev_err(DEV, "Unknown tag: %d\n", tag_number(tag)); \
68 return 0; \
69 } \
70 } \
71 tags = (unsigned short *)((char *)tags + dlen); \
72 } \
73 return 1; \
74}
75#define NL_INTEGER(pn, pr, member) \
76 case pn: /* D_ASSERT( tag_type(tag) == TT_INTEGER ); */ \
77 arg->member = get_unaligned((int *)(tags)); \
78 break;
79#define NL_INT64(pn, pr, member) \
80 case pn: /* D_ASSERT( tag_type(tag) == TT_INT64 ); */ \
81 arg->member = get_unaligned((u64 *)(tags)); \
82 break;
83#define NL_BIT(pn, pr, member) \
84 case pn: /* D_ASSERT( tag_type(tag) == TT_BIT ); */ \
85 arg->member = *(char *)(tags) ? 1 : 0; \
86 break;
87#define NL_STRING(pn, pr, member, len) \
88 case pn: /* D_ASSERT( tag_type(tag) == TT_STRING ); */ \
89 if (dlen > len) { \
90 dev_err(DEV, "arg too long: %s (%u wanted, max len: %u bytes)\n", \
91 #member, dlen, (unsigned int)len); \
92 return 0; \
93 } \
94 arg->member ## _len = dlen; \
95 memcpy(arg->member, tags, min_t(size_t, dlen, len)); \
96 break;
97#include "linux/drbd_nl.h"
98
99/* Generate the struct to tag_list functions */
100#define NL_PACKET(name, number, fields) \
101static unsigned short* \
102name ## _to_tags(struct drbd_conf *mdev, \
103 struct name *arg, unsigned short *tags) __attribute__ ((unused)); \
104static unsigned short* \
105name ## _to_tags(struct drbd_conf *mdev, \
106 struct name *arg, unsigned short *tags) \
107{ \
108 fields \
109 return tags; \
110}
111
112#define NL_INTEGER(pn, pr, member) \
113 put_unaligned(pn | pr | TT_INTEGER, tags++); \
114 put_unaligned(sizeof(int), tags++); \
115 put_unaligned(arg->member, (int *)tags); \
116 tags = (unsigned short *)((char *)tags+sizeof(int));
117#define NL_INT64(pn, pr, member) \
118 put_unaligned(pn | pr | TT_INT64, tags++); \
119 put_unaligned(sizeof(u64), tags++); \
120 put_unaligned(arg->member, (u64 *)tags); \
121 tags = (unsigned short *)((char *)tags+sizeof(u64));
122#define NL_BIT(pn, pr, member) \
123 put_unaligned(pn | pr | TT_BIT, tags++); \
124 put_unaligned(sizeof(char), tags++); \
125 *(char *)tags = arg->member; \
126 tags = (unsigned short *)((char *)tags+sizeof(char));
127#define NL_STRING(pn, pr, member, len) \
128 put_unaligned(pn | pr | TT_STRING, tags++); \
129 put_unaligned(arg->member ## _len, tags++); \
130 memcpy(tags, arg->member, arg->member ## _len); \
131 tags = (unsigned short *)((char *)tags + arg->member ## _len);
132#include "linux/drbd_nl.h"
133
134void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name);
135void drbd_nl_send_reply(struct cn_msg *, int);
136
137int drbd_khelper(struct drbd_conf *mdev, char *cmd)
138{
139 char *envp[] = { "HOME=/",
140 "TERM=linux",
141 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
142 NULL, /* Will be set to address family */
143 NULL, /* Will be set to address */
144 NULL };
145
146 char mb[12], af[20], ad[60], *afs;
147 char *argv[] = {usermode_helper, cmd, mb, NULL };
148 int ret;
149
150 snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev));
151
152 if (get_net_conf(mdev)) {
153 switch (((struct sockaddr *)mdev->net_conf->peer_addr)->sa_family) {
154 case AF_INET6:
155 afs = "ipv6";
156 snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI6",
157 &((struct sockaddr_in6 *)mdev->net_conf->peer_addr)->sin6_addr);
158 break;
159 case AF_INET:
160 afs = "ipv4";
161 snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI4",
162 &((struct sockaddr_in *)mdev->net_conf->peer_addr)->sin_addr);
163 break;
164 default:
165 afs = "ssocks";
166 snprintf(ad, 60, "DRBD_PEER_ADDRESS=%pI4",
167 &((struct sockaddr_in *)mdev->net_conf->peer_addr)->sin_addr);
168 }
169 snprintf(af, 20, "DRBD_PEER_AF=%s", afs);
170 envp[3]=af;
171 envp[4]=ad;
172 put_net_conf(mdev);
173 }
174
Lars Ellenberg1090c052010-07-19 17:41:04 +0200175 /* The helper may take some time.
176 * write out any unsynced meta data changes now */
177 drbd_md_sync(mdev);
178
Philipp Reisnerb411b362009-09-25 16:07:19 -0700179 dev_info(DEV, "helper command: %s %s %s\n", usermode_helper, cmd, mb);
180
181 drbd_bcast_ev_helper(mdev, cmd);
182 ret = call_usermodehelper(usermode_helper, argv, envp, 1);
183 if (ret)
184 dev_warn(DEV, "helper command: %s %s %s exit code %u (0x%x)\n",
185 usermode_helper, cmd, mb,
186 (ret >> 8) & 0xff, ret);
187 else
188 dev_info(DEV, "helper command: %s %s %s exit code %u (0x%x)\n",
189 usermode_helper, cmd, mb,
190 (ret >> 8) & 0xff, ret);
191
192 if (ret < 0) /* Ignore any ERRNOs we got. */
193 ret = 0;
194
195 return ret;
196}
197
198enum drbd_disk_state drbd_try_outdate_peer(struct drbd_conf *mdev)
199{
200 char *ex_to_string;
201 int r;
202 enum drbd_disk_state nps;
203 enum drbd_fencing_p fp;
204
205 D_ASSERT(mdev->state.pdsk == D_UNKNOWN);
206
207 if (get_ldev_if_state(mdev, D_CONSISTENT)) {
208 fp = mdev->ldev->dc.fencing;
209 put_ldev(mdev);
210 } else {
211 dev_warn(DEV, "Not fencing peer, I'm not even Consistent myself.\n");
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200212 nps = mdev->state.pdsk;
213 goto out;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700214 }
215
Philipp Reisnerb411b362009-09-25 16:07:19 -0700216 r = drbd_khelper(mdev, "fence-peer");
217
218 switch ((r>>8) & 0xff) {
219 case 3: /* peer is inconsistent */
220 ex_to_string = "peer is inconsistent or worse";
221 nps = D_INCONSISTENT;
222 break;
223 case 4: /* peer got outdated, or was already outdated */
224 ex_to_string = "peer was fenced";
225 nps = D_OUTDATED;
226 break;
227 case 5: /* peer was down */
228 if (mdev->state.disk == D_UP_TO_DATE) {
229 /* we will(have) create(d) a new UUID anyways... */
230 ex_to_string = "peer is unreachable, assumed to be dead";
231 nps = D_OUTDATED;
232 } else {
233 ex_to_string = "peer unreachable, doing nothing since disk != UpToDate";
234 nps = mdev->state.pdsk;
235 }
236 break;
237 case 6: /* Peer is primary, voluntarily outdate myself.
238 * This is useful when an unconnected R_SECONDARY is asked to
239 * become R_PRIMARY, but finds the other peer being active. */
240 ex_to_string = "peer is active";
241 dev_warn(DEV, "Peer is primary, outdating myself.\n");
242 nps = D_UNKNOWN;
243 _drbd_request_state(mdev, NS(disk, D_OUTDATED), CS_WAIT_COMPLETE);
244 break;
245 case 7:
246 if (fp != FP_STONITH)
247 dev_err(DEV, "fence-peer() = 7 && fencing != Stonith !!!\n");
248 ex_to_string = "peer was stonithed";
249 nps = D_OUTDATED;
250 break;
251 default:
252 /* The script is broken ... */
253 nps = D_UNKNOWN;
254 dev_err(DEV, "fence-peer helper broken, returned %d\n", (r>>8)&0xff);
255 return nps;
256 }
257
258 dev_info(DEV, "fence-peer helper returned %d (%s)\n",
259 (r>>8) & 0xff, ex_to_string);
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200260
261out:
262 if (mdev->state.susp_fen && nps >= D_UNKNOWN) {
263 /* The handler was not successful... unfreeze here, the
264 state engine can not unfreeze... */
265 _drbd_request_state(mdev, NS(susp_fen, 0), CS_VERBOSE);
266 }
267
Philipp Reisnerb411b362009-09-25 16:07:19 -0700268 return nps;
269}
270
Philipp Reisner87f7be42010-06-11 13:56:33 +0200271static int _try_outdate_peer_async(void *data)
272{
273 struct drbd_conf *mdev = (struct drbd_conf *)data;
274 enum drbd_disk_state nps;
275
276 nps = drbd_try_outdate_peer(mdev);
277 drbd_request_state(mdev, NS(pdsk, nps));
278
279 return 0;
280}
281
282void drbd_try_outdate_peer_async(struct drbd_conf *mdev)
283{
284 struct task_struct *opa;
285
286 opa = kthread_run(_try_outdate_peer_async, mdev, "drbd%d_a_helper", mdev_to_minor(mdev));
287 if (IS_ERR(opa))
288 dev_err(DEV, "out of mem, failed to invoke fence-peer helper\n");
289}
Philipp Reisnerb411b362009-09-25 16:07:19 -0700290
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100291enum drbd_state_rv
292drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700293{
294 const int max_tries = 4;
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100295 enum drbd_state_rv rv = SS_UNKNOWN_ERROR;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700296 int try = 0;
297 int forced = 0;
298 union drbd_state mask, val;
299 enum drbd_disk_state nps;
300
301 if (new_role == R_PRIMARY)
302 request_ping(mdev); /* Detect a dead peer ASAP */
303
304 mutex_lock(&mdev->state_mutex);
305
306 mask.i = 0; mask.role = R_MASK;
307 val.i = 0; val.role = new_role;
308
309 while (try++ < max_tries) {
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100310 rv = _drbd_request_state(mdev, mask, val, CS_WAIT_COMPLETE);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700311
312 /* in case we first succeeded to outdate,
313 * but now suddenly could establish a connection */
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100314 if (rv == SS_CW_FAILED_BY_PEER && mask.pdsk != 0) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700315 val.pdsk = 0;
316 mask.pdsk = 0;
317 continue;
318 }
319
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100320 if (rv == SS_NO_UP_TO_DATE_DISK && force &&
Philipp Reisnerd10a33c2010-03-04 15:11:39 +0100321 (mdev->state.disk < D_UP_TO_DATE &&
322 mdev->state.disk >= D_INCONSISTENT)) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700323 mask.disk = D_MASK;
324 val.disk = D_UP_TO_DATE;
325 forced = 1;
326 continue;
327 }
328
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100329 if (rv == SS_NO_UP_TO_DATE_DISK &&
Philipp Reisnerb411b362009-09-25 16:07:19 -0700330 mdev->state.disk == D_CONSISTENT && mask.pdsk == 0) {
331 D_ASSERT(mdev->state.pdsk == D_UNKNOWN);
332 nps = drbd_try_outdate_peer(mdev);
333
334 if (nps == D_OUTDATED || nps == D_INCONSISTENT) {
335 val.disk = D_UP_TO_DATE;
336 mask.disk = D_MASK;
337 }
338
339 val.pdsk = nps;
340 mask.pdsk = D_MASK;
341
342 continue;
343 }
344
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100345 if (rv == SS_NOTHING_TO_DO)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700346 goto fail;
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100347 if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700348 nps = drbd_try_outdate_peer(mdev);
349
350 if (force && nps > D_OUTDATED) {
351 dev_warn(DEV, "Forced into split brain situation!\n");
352 nps = D_OUTDATED;
353 }
354
355 mask.pdsk = D_MASK;
356 val.pdsk = nps;
357
358 continue;
359 }
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100360 if (rv == SS_TWO_PRIMARIES) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700361 /* Maybe the peer is detected as dead very soon...
362 retry at most once more in this case. */
363 __set_current_state(TASK_INTERRUPTIBLE);
364 schedule_timeout((mdev->net_conf->ping_timeo+1)*HZ/10);
365 if (try < max_tries)
366 try = max_tries - 1;
367 continue;
368 }
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100369 if (rv < SS_SUCCESS) {
370 rv = _drbd_request_state(mdev, mask, val,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700371 CS_VERBOSE + CS_WAIT_COMPLETE);
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100372 if (rv < SS_SUCCESS)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700373 goto fail;
374 }
375 break;
376 }
377
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100378 if (rv < SS_SUCCESS)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700379 goto fail;
380
381 if (forced)
382 dev_warn(DEV, "Forced to consider local data as UpToDate!\n");
383
384 /* Wait until nothing is on the fly :) */
385 wait_event(mdev->misc_wait, atomic_read(&mdev->ap_pending_cnt) == 0);
386
387 if (new_role == R_SECONDARY) {
388 set_disk_ro(mdev->vdisk, TRUE);
389 if (get_ldev(mdev)) {
390 mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
391 put_ldev(mdev);
392 }
393 } else {
394 if (get_net_conf(mdev)) {
395 mdev->net_conf->want_lose = 0;
396 put_net_conf(mdev);
397 }
398 set_disk_ro(mdev->vdisk, FALSE);
399 if (get_ldev(mdev)) {
400 if (((mdev->state.conn < C_CONNECTED ||
401 mdev->state.pdsk <= D_FAILED)
402 && mdev->ldev->md.uuid[UI_BITMAP] == 0) || forced)
403 drbd_uuid_new_current(mdev);
404
405 mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1;
406 put_ldev(mdev);
407 }
408 }
409
410 if ((new_role == R_SECONDARY) && get_ldev(mdev)) {
411 drbd_al_to_on_disk_bm(mdev);
412 put_ldev(mdev);
413 }
414
415 if (mdev->state.conn >= C_WF_REPORT_PARAMS) {
416 /* if this was forced, we should consider sync */
417 if (forced)
418 drbd_send_uuids(mdev);
419 drbd_send_state(mdev);
420 }
421
422 drbd_md_sync(mdev);
423
424 kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
425 fail:
426 mutex_unlock(&mdev->state_mutex);
Andreas Gruenbacherbf885f82010-12-08 00:39:32 +0100427 return rv;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700428}
429
Lars Ellenbergef50a3e2010-09-01 14:39:30 +0200430static struct drbd_conf *ensure_mdev(int minor, int create)
431{
432 struct drbd_conf *mdev;
433
434 if (minor >= minor_count)
435 return NULL;
436
437 mdev = minor_to_mdev(minor);
438
439 if (!mdev && create) {
440 struct gendisk *disk = NULL;
441 mdev = drbd_new_device(minor);
442
443 spin_lock_irq(&drbd_pp_lock);
444 if (minor_table[minor] == NULL) {
445 minor_table[minor] = mdev;
446 disk = mdev->vdisk;
447 mdev = NULL;
448 } /* else: we lost the race */
449 spin_unlock_irq(&drbd_pp_lock);
450
451 if (disk) /* we won the race above */
452 /* in case we ever add a drbd_delete_device(),
453 * don't forget the del_gendisk! */
454 add_disk(disk);
455 else /* we lost the race above */
456 drbd_free_mdev(mdev);
457
458 mdev = minor_to_mdev(minor);
459 }
460
461 return mdev;
462}
Philipp Reisnerb411b362009-09-25 16:07:19 -0700463
464static int drbd_nl_primary(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
465 struct drbd_nl_cfg_reply *reply)
466{
467 struct primary primary_args;
468
469 memset(&primary_args, 0, sizeof(struct primary));
470 if (!primary_from_tags(mdev, nlp->tag_list, &primary_args)) {
471 reply->ret_code = ERR_MANDATORY_TAG;
472 return 0;
473 }
474
475 reply->ret_code =
Philipp Reisner1f552432010-03-04 15:51:01 +0100476 drbd_set_role(mdev, R_PRIMARY, primary_args.primary_force);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700477
478 return 0;
479}
480
481static int drbd_nl_secondary(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
482 struct drbd_nl_cfg_reply *reply)
483{
484 reply->ret_code = drbd_set_role(mdev, R_SECONDARY, 0);
485
486 return 0;
487}
488
489/* initializes the md.*_offset members, so we are able to find
490 * the on disk meta data */
491static void drbd_md_set_sector_offsets(struct drbd_conf *mdev,
492 struct drbd_backing_dev *bdev)
493{
494 sector_t md_size_sect = 0;
495 switch (bdev->dc.meta_dev_idx) {
496 default:
497 /* v07 style fixed size indexed meta data */
498 bdev->md.md_size_sect = MD_RESERVED_SECT;
499 bdev->md.md_offset = drbd_md_ss__(mdev, bdev);
500 bdev->md.al_offset = MD_AL_OFFSET;
501 bdev->md.bm_offset = MD_BM_OFFSET;
502 break;
503 case DRBD_MD_INDEX_FLEX_EXT:
504 /* just occupy the full device; unit: sectors */
505 bdev->md.md_size_sect = drbd_get_capacity(bdev->md_bdev);
506 bdev->md.md_offset = 0;
507 bdev->md.al_offset = MD_AL_OFFSET;
508 bdev->md.bm_offset = MD_BM_OFFSET;
509 break;
510 case DRBD_MD_INDEX_INTERNAL:
511 case DRBD_MD_INDEX_FLEX_INT:
512 bdev->md.md_offset = drbd_md_ss__(mdev, bdev);
513 /* al size is still fixed */
514 bdev->md.al_offset = -MD_AL_MAX_SIZE;
515 /* we need (slightly less than) ~ this much bitmap sectors: */
516 md_size_sect = drbd_get_capacity(bdev->backing_bdev);
517 md_size_sect = ALIGN(md_size_sect, BM_SECT_PER_EXT);
518 md_size_sect = BM_SECT_TO_EXT(md_size_sect);
519 md_size_sect = ALIGN(md_size_sect, 8);
520
521 /* plus the "drbd meta data super block",
522 * and the activity log; */
523 md_size_sect += MD_BM_OFFSET;
524
525 bdev->md.md_size_sect = md_size_sect;
526 /* bitmap offset is adjusted by 'super' block size */
527 bdev->md.bm_offset = -md_size_sect + MD_AL_OFFSET;
528 break;
529 }
530}
531
532char *ppsize(char *buf, unsigned long long size)
533{
534 /* Needs 9 bytes at max. */
535 static char units[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
536 int base = 0;
537 while (size >= 10000) {
538 /* shift + round */
539 size = (size >> 10) + !!(size & (1<<9));
540 base++;
541 }
542 sprintf(buf, "%lu %cB", (long)size, units[base]);
543
544 return buf;
545}
546
547/* there is still a theoretical deadlock when called from receiver
548 * on an D_INCONSISTENT R_PRIMARY:
549 * remote READ does inc_ap_bio, receiver would need to receive answer
550 * packet from remote to dec_ap_bio again.
551 * receiver receive_sizes(), comes here,
552 * waits for ap_bio_cnt == 0. -> deadlock.
553 * but this cannot happen, actually, because:
554 * R_PRIMARY D_INCONSISTENT, and peer's disk is unreachable
555 * (not connected, or bad/no disk on peer):
556 * see drbd_fail_request_early, ap_bio_cnt is zero.
557 * R_PRIMARY D_INCONSISTENT, and C_SYNC_TARGET:
558 * peer may not initiate a resize.
559 */
560void drbd_suspend_io(struct drbd_conf *mdev)
561{
562 set_bit(SUSPEND_IO, &mdev->flags);
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200563 if (is_susp(mdev->state))
Philipp Reisner265be2d2010-05-31 10:14:17 +0200564 return;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700565 wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_bio_cnt));
566}
567
568void drbd_resume_io(struct drbd_conf *mdev)
569{
570 clear_bit(SUSPEND_IO, &mdev->flags);
571 wake_up(&mdev->misc_wait);
572}
573
574/**
575 * drbd_determine_dev_size() - Sets the right device size obeying all constraints
576 * @mdev: DRBD device.
577 *
578 * Returns 0 on success, negative return values indicate errors.
579 * You should call drbd_md_sync() after calling this function.
580 */
Philipp Reisnerd8450302010-03-24 15:51:26 +0100581enum determine_dev_size drbd_determin_dev_size(struct drbd_conf *mdev, enum dds_flags flags) __must_hold(local)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700582{
583 sector_t prev_first_sect, prev_size; /* previous meta location */
584 sector_t la_size;
585 sector_t size;
586 char ppb[10];
587
588 int md_moved, la_size_changed;
589 enum determine_dev_size rv = unchanged;
590
591 /* race:
592 * application request passes inc_ap_bio,
593 * but then cannot get an AL-reference.
594 * this function later may wait on ap_bio_cnt == 0. -> deadlock.
595 *
596 * to avoid that:
597 * Suspend IO right here.
598 * still lock the act_log to not trigger ASSERTs there.
599 */
600 drbd_suspend_io(mdev);
601
602 /* no wait necessary anymore, actually we could assert that */
603 wait_event(mdev->al_wait, lc_try_lock(mdev->act_log));
604
605 prev_first_sect = drbd_md_first_sector(mdev->ldev);
606 prev_size = mdev->ldev->md.md_size_sect;
607 la_size = mdev->ldev->md.la_size_sect;
608
609 /* TODO: should only be some assert here, not (re)init... */
610 drbd_md_set_sector_offsets(mdev, mdev->ldev);
611
Philipp Reisnerd8450302010-03-24 15:51:26 +0100612 size = drbd_new_dev_size(mdev, mdev->ldev, flags & DDSF_FORCED);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700613
614 if (drbd_get_capacity(mdev->this_bdev) != size ||
615 drbd_bm_capacity(mdev) != size) {
616 int err;
Philipp Reisner02d9a942010-03-24 16:23:03 +0100617 err = drbd_bm_resize(mdev, size, !(flags & DDSF_NO_RESYNC));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700618 if (unlikely(err)) {
619 /* currently there is only one error: ENOMEM! */
620 size = drbd_bm_capacity(mdev)>>1;
621 if (size == 0) {
622 dev_err(DEV, "OUT OF MEMORY! "
623 "Could not allocate bitmap!\n");
624 } else {
625 dev_err(DEV, "BM resizing failed. "
626 "Leaving size unchanged at size = %lu KB\n",
627 (unsigned long)size);
628 }
629 rv = dev_size_error;
630 }
631 /* racy, see comments above. */
632 drbd_set_my_capacity(mdev, size);
633 mdev->ldev->md.la_size_sect = size;
634 dev_info(DEV, "size = %s (%llu KB)\n", ppsize(ppb, size>>1),
635 (unsigned long long)size>>1);
636 }
637 if (rv == dev_size_error)
638 goto out;
639
640 la_size_changed = (la_size != mdev->ldev->md.la_size_sect);
641
642 md_moved = prev_first_sect != drbd_md_first_sector(mdev->ldev)
643 || prev_size != mdev->ldev->md.md_size_sect;
644
645 if (la_size_changed || md_moved) {
646 drbd_al_shrink(mdev); /* All extents inactive. */
647 dev_info(DEV, "Writing the whole bitmap, %s\n",
648 la_size_changed && md_moved ? "size changed and md moved" :
649 la_size_changed ? "size changed" : "md moved");
650 rv = drbd_bitmap_io(mdev, &drbd_bm_write, "size changed"); /* does drbd_resume_io() ! */
651 drbd_md_mark_dirty(mdev);
652 }
653
654 if (size > la_size)
655 rv = grew;
656 if (size < la_size)
657 rv = shrunk;
658out:
659 lc_unlock(mdev->act_log);
660 wake_up(&mdev->al_wait);
661 drbd_resume_io(mdev);
662
663 return rv;
664}
665
666sector_t
Philipp Reisnera393db62009-12-22 13:35:52 +0100667drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, int assume_peer_has_space)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700668{
669 sector_t p_size = mdev->p_size; /* partner's disk size. */
670 sector_t la_size = bdev->md.la_size_sect; /* last agreed size. */
671 sector_t m_size; /* my size */
672 sector_t u_size = bdev->dc.disk_size; /* size requested by user. */
673 sector_t size = 0;
674
675 m_size = drbd_get_max_capacity(bdev);
676
Philipp Reisnera393db62009-12-22 13:35:52 +0100677 if (mdev->state.conn < C_CONNECTED && assume_peer_has_space) {
678 dev_warn(DEV, "Resize while not connected was forced by the user!\n");
679 p_size = m_size;
680 }
681
Philipp Reisnerb411b362009-09-25 16:07:19 -0700682 if (p_size && m_size) {
683 size = min_t(sector_t, p_size, m_size);
684 } else {
685 if (la_size) {
686 size = la_size;
687 if (m_size && m_size < size)
688 size = m_size;
689 if (p_size && p_size < size)
690 size = p_size;
691 } else {
692 if (m_size)
693 size = m_size;
694 if (p_size)
695 size = p_size;
696 }
697 }
698
699 if (size == 0)
700 dev_err(DEV, "Both nodes diskless!\n");
701
702 if (u_size) {
703 if (u_size > size)
704 dev_err(DEV, "Requested disk size is too big (%lu > %lu)\n",
705 (unsigned long)u_size>>1, (unsigned long)size>>1);
706 else
707 size = u_size;
708 }
709
710 return size;
711}
712
713/**
714 * drbd_check_al_size() - Ensures that the AL is of the right size
715 * @mdev: DRBD device.
716 *
717 * Returns -EBUSY if current al lru is still used, -ENOMEM when allocation
718 * failed, and 0 on success. You should call drbd_md_sync() after you called
719 * this function.
720 */
721static int drbd_check_al_size(struct drbd_conf *mdev)
722{
723 struct lru_cache *n, *t;
724 struct lc_element *e;
725 unsigned int in_use;
726 int i;
727
728 ERR_IF(mdev->sync_conf.al_extents < 7)
729 mdev->sync_conf.al_extents = 127;
730
731 if (mdev->act_log &&
732 mdev->act_log->nr_elements == mdev->sync_conf.al_extents)
733 return 0;
734
735 in_use = 0;
736 t = mdev->act_log;
737 n = lc_create("act_log", drbd_al_ext_cache,
738 mdev->sync_conf.al_extents, sizeof(struct lc_element), 0);
739
740 if (n == NULL) {
741 dev_err(DEV, "Cannot allocate act_log lru!\n");
742 return -ENOMEM;
743 }
744 spin_lock_irq(&mdev->al_lock);
745 if (t) {
746 for (i = 0; i < t->nr_elements; i++) {
747 e = lc_element_by_index(t, i);
748 if (e->refcnt)
749 dev_err(DEV, "refcnt(%d)==%d\n",
750 e->lc_number, e->refcnt);
751 in_use += e->refcnt;
752 }
753 }
754 if (!in_use)
755 mdev->act_log = n;
756 spin_unlock_irq(&mdev->al_lock);
757 if (in_use) {
758 dev_err(DEV, "Activity log still in use!\n");
759 lc_destroy(n);
760 return -EBUSY;
761 } else {
762 if (t)
763 lc_destroy(t);
764 }
765 drbd_md_mark_dirty(mdev); /* we changed mdev->act_log->nr_elemens */
766 return 0;
767}
768
Lars Ellenberg1816a2b2010-11-11 15:19:07 +0100769void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int max_bio_size) __must_hold(local)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700770{
771 struct request_queue * const q = mdev->rq_queue;
772 struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue;
773 int max_segments = mdev->ldev->dc.max_bio_bvecs;
Lars Ellenberg1816a2b2010-11-11 15:19:07 +0100774 int max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700775
Philipp Reisnerb411b362009-09-25 16:07:19 -0700776 blk_queue_logical_block_size(q, 512);
Lars Ellenberg1816a2b2010-11-11 15:19:07 +0100777 blk_queue_max_hw_sectors(q, max_hw_sectors);
778 /* This is the workaround for "bio would need to, but cannot, be split" */
779 blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
780 blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1);
781 blk_queue_stack_limits(q, b);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700782
Lars Ellenberg1816a2b2010-11-11 15:19:07 +0100783 dev_info(DEV, "max BIO size = %u\n", queue_max_hw_sectors(q) << 9);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700784
785 if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) {
786 dev_info(DEV, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
787 q->backing_dev_info.ra_pages,
788 b->backing_dev_info.ra_pages);
789 q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages;
790 }
791}
792
793/* serialize deconfig (worker exiting, doing cleanup)
794 * and reconfig (drbdsetup disk, drbdsetup net)
795 *
Lars Ellenbergc518d042010-09-01 09:50:23 +0200796 * Wait for a potentially exiting worker, then restart it,
797 * or start a new one. Flush any pending work, there may still be an
798 * after_state_change queued.
Philipp Reisnerb411b362009-09-25 16:07:19 -0700799 */
800static void drbd_reconfig_start(struct drbd_conf *mdev)
801{
Lars Ellenberg6c6c7952009-11-16 15:48:54 +0100802 wait_event(mdev->state_wait, !test_and_set_bit(CONFIG_PENDING, &mdev->flags));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700803 wait_event(mdev->state_wait, !test_bit(DEVICE_DYING, &mdev->flags));
804 drbd_thread_start(&mdev->worker);
Lars Ellenbergc518d042010-09-01 09:50:23 +0200805 drbd_flush_workqueue(mdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700806}
807
808/* if still unconfigured, stops worker again.
809 * if configured now, clears CONFIG_PENDING.
810 * wakes potential waiters */
811static void drbd_reconfig_done(struct drbd_conf *mdev)
812{
813 spin_lock_irq(&mdev->req_lock);
814 if (mdev->state.disk == D_DISKLESS &&
815 mdev->state.conn == C_STANDALONE &&
816 mdev->state.role == R_SECONDARY) {
817 set_bit(DEVICE_DYING, &mdev->flags);
818 drbd_thread_stop_nowait(&mdev->worker);
819 } else
820 clear_bit(CONFIG_PENDING, &mdev->flags);
821 spin_unlock_irq(&mdev->req_lock);
822 wake_up(&mdev->state_wait);
823}
824
Philipp Reisner07782862010-08-31 12:00:50 +0200825/* Make sure IO is suspended before calling this function(). */
826static void drbd_suspend_al(struct drbd_conf *mdev)
827{
828 int s = 0;
829
830 if (lc_try_lock(mdev->act_log)) {
831 drbd_al_shrink(mdev);
832 lc_unlock(mdev->act_log);
833 } else {
834 dev_warn(DEV, "Failed to lock al in drbd_suspend_al()\n");
835 return;
836 }
837
838 spin_lock_irq(&mdev->req_lock);
839 if (mdev->state.conn < C_CONNECTED)
840 s = !test_and_set_bit(AL_SUSPENDED, &mdev->flags);
841
842 spin_unlock_irq(&mdev->req_lock);
843
844 if (s)
845 dev_info(DEV, "Suspended AL updates\n");
846}
847
Philipp Reisnerb411b362009-09-25 16:07:19 -0700848/* does always return 0;
849 * interesting return code is in reply->ret_code */
850static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
851 struct drbd_nl_cfg_reply *reply)
852{
Andreas Gruenbacher116676c2010-12-08 13:33:11 +0100853 enum drbd_ret_code retcode;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700854 enum determine_dev_size dd;
855 sector_t max_possible_sectors;
856 sector_t min_md_device_sectors;
857 struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */
Tejun Heoe525fd82010-11-13 11:55:17 +0100858 struct block_device *bdev;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700859 struct lru_cache *resync_lru = NULL;
860 union drbd_state ns, os;
Lars Ellenberg1816a2b2010-11-11 15:19:07 +0100861 unsigned int max_bio_size;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700862 int rv;
863 int cp_discovered = 0;
864 int logical_block_size;
865
866 drbd_reconfig_start(mdev);
867
868 /* if you want to reconfigure, please tear down first */
869 if (mdev->state.disk > D_DISKLESS) {
870 retcode = ERR_DISK_CONFIGURED;
871 goto fail;
872 }
Lars Ellenberg82f59cc2010-10-16 12:13:47 +0200873 /* It may just now have detached because of IO error. Make sure
874 * drbd_ldev_destroy is done already, we may end up here very fast,
875 * e.g. if someone calls attach from the on-io-error handler,
876 * to realize a "hot spare" feature (not that I'd recommend that) */
877 wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700878
879 /* allocation not in the IO path, cqueue thread context */
880 nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL);
881 if (!nbc) {
882 retcode = ERR_NOMEM;
883 goto fail;
884 }
885
886 nbc->dc.disk_size = DRBD_DISK_SIZE_SECT_DEF;
887 nbc->dc.on_io_error = DRBD_ON_IO_ERROR_DEF;
888 nbc->dc.fencing = DRBD_FENCING_DEF;
889 nbc->dc.max_bio_bvecs = DRBD_MAX_BIO_BVECS_DEF;
890
891 if (!disk_conf_from_tags(mdev, nlp->tag_list, &nbc->dc)) {
892 retcode = ERR_MANDATORY_TAG;
893 goto fail;
894 }
895
896 if (nbc->dc.meta_dev_idx < DRBD_MD_INDEX_FLEX_INT) {
897 retcode = ERR_MD_IDX_INVALID;
898 goto fail;
899 }
900
Philipp Reisner47ff2d02010-06-18 13:56:57 +0200901 if (get_net_conf(mdev)) {
902 int prot = mdev->net_conf->wire_protocol;
903 put_net_conf(mdev);
904 if (nbc->dc.fencing == FP_STONITH && prot == DRBD_PROT_A) {
905 retcode = ERR_STONITH_AND_PROT_A;
906 goto fail;
907 }
908 }
909
Tejun Heod4d77622010-11-13 11:55:18 +0100910 bdev = blkdev_get_by_path(nbc->dc.backing_dev,
911 FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev);
Tejun Heoe525fd82010-11-13 11:55:17 +0100912 if (IS_ERR(bdev)) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700913 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev,
Tejun Heoe525fd82010-11-13 11:55:17 +0100914 PTR_ERR(bdev));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700915 retcode = ERR_OPEN_DISK;
916 goto fail;
917 }
Tejun Heoe525fd82010-11-13 11:55:17 +0100918 nbc->backing_bdev = bdev;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700919
Tejun Heoe525fd82010-11-13 11:55:17 +0100920 /*
921 * meta_dev_idx >= 0: external fixed size, possibly multiple
922 * drbd sharing one meta device. TODO in that case, paranoia
923 * check that [md_bdev, meta_dev_idx] is not yet used by some
924 * other drbd minor! (if you use drbd.conf + drbdadm, that
925 * should check it for you already; but if you don't, or
926 * someone fooled it, we need to double check here)
927 */
Tejun Heod4d77622010-11-13 11:55:18 +0100928 bdev = blkdev_get_by_path(nbc->dc.meta_dev,
929 FMODE_READ | FMODE_WRITE | FMODE_EXCL,
930 (nbc->dc.meta_dev_idx < 0) ?
931 (void *)mdev : (void *)drbd_m_holder);
Tejun Heoe525fd82010-11-13 11:55:17 +0100932 if (IS_ERR(bdev)) {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700933 dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.meta_dev,
Tejun Heoe525fd82010-11-13 11:55:17 +0100934 PTR_ERR(bdev));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700935 retcode = ERR_OPEN_MD_DISK;
936 goto fail;
937 }
Tejun Heoe525fd82010-11-13 11:55:17 +0100938 nbc->md_bdev = bdev;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700939
Tejun Heoe525fd82010-11-13 11:55:17 +0100940 if ((nbc->backing_bdev == nbc->md_bdev) !=
941 (nbc->dc.meta_dev_idx == DRBD_MD_INDEX_INTERNAL ||
942 nbc->dc.meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) {
943 retcode = ERR_MD_IDX_INVALID;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700944 goto fail;
945 }
946
947 resync_lru = lc_create("resync", drbd_bm_ext_cache,
948 61, sizeof(struct bm_extent),
949 offsetof(struct bm_extent, lce));
950 if (!resync_lru) {
951 retcode = ERR_NOMEM;
Tejun Heoe525fd82010-11-13 11:55:17 +0100952 goto fail;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700953 }
954
955 /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */
956 drbd_md_set_sector_offsets(mdev, nbc);
957
958 if (drbd_get_max_capacity(nbc) < nbc->dc.disk_size) {
959 dev_err(DEV, "max capacity %llu smaller than disk size %llu\n",
960 (unsigned long long) drbd_get_max_capacity(nbc),
961 (unsigned long long) nbc->dc.disk_size);
962 retcode = ERR_DISK_TO_SMALL;
Tejun Heoe525fd82010-11-13 11:55:17 +0100963 goto fail;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700964 }
965
966 if (nbc->dc.meta_dev_idx < 0) {
967 max_possible_sectors = DRBD_MAX_SECTORS_FLEX;
968 /* at least one MB, otherwise it does not make sense */
969 min_md_device_sectors = (2<<10);
970 } else {
971 max_possible_sectors = DRBD_MAX_SECTORS;
972 min_md_device_sectors = MD_RESERVED_SECT * (nbc->dc.meta_dev_idx + 1);
973 }
974
Philipp Reisnerb411b362009-09-25 16:07:19 -0700975 if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) {
976 retcode = ERR_MD_DISK_TO_SMALL;
977 dev_warn(DEV, "refusing attach: md-device too small, "
978 "at least %llu sectors needed for this meta-disk type\n",
979 (unsigned long long) min_md_device_sectors);
Tejun Heoe525fd82010-11-13 11:55:17 +0100980 goto fail;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700981 }
982
983 /* Make sure the new disk is big enough
984 * (we may currently be R_PRIMARY with no local disk...) */
985 if (drbd_get_max_capacity(nbc) <
986 drbd_get_capacity(mdev->this_bdev)) {
987 retcode = ERR_DISK_TO_SMALL;
Tejun Heoe525fd82010-11-13 11:55:17 +0100988 goto fail;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700989 }
990
991 nbc->known_size = drbd_get_capacity(nbc->backing_bdev);
992
Lars Ellenberg13529942009-10-12 19:07:49 +0200993 if (nbc->known_size > max_possible_sectors) {
994 dev_warn(DEV, "==> truncating very big lower level device "
995 "to currently maximum possible %llu sectors <==\n",
996 (unsigned long long) max_possible_sectors);
997 if (nbc->dc.meta_dev_idx >= 0)
998 dev_warn(DEV, "==>> using internal or flexible "
999 "meta data may help <<==\n");
1000 }
1001
Philipp Reisnerb411b362009-09-25 16:07:19 -07001002 drbd_suspend_io(mdev);
1003 /* also wait for the last barrier ack. */
Philipp Reisnerfb22c402010-09-08 23:20:21 +02001004 wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_pending_cnt) || is_susp(mdev->state));
Philipp Reisnerb411b362009-09-25 16:07:19 -07001005 /* and for any other previously queued work */
1006 drbd_flush_workqueue(mdev);
1007
1008 retcode = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE);
1009 drbd_resume_io(mdev);
1010 if (retcode < SS_SUCCESS)
Tejun Heoe525fd82010-11-13 11:55:17 +01001011 goto fail;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001012
1013 if (!get_ldev_if_state(mdev, D_ATTACHING))
1014 goto force_diskless;
1015
1016 drbd_md_set_sector_offsets(mdev, nbc);
1017
Lars Ellenberg4aa83b72010-02-26 16:53:24 +01001018 /* allocate a second IO page if logical_block_size != 512 */
1019 logical_block_size = bdev_logical_block_size(nbc->md_bdev);
1020 if (logical_block_size == 0)
1021 logical_block_size = MD_SECTOR_SIZE;
1022
1023 if (logical_block_size != MD_SECTOR_SIZE) {
1024 if (!mdev->md_io_tmpp) {
1025 struct page *page = alloc_page(GFP_NOIO);
1026 if (!page)
1027 goto force_diskless_dec;
1028
1029 dev_warn(DEV, "Meta data's bdev logical_block_size = %d != %d\n",
1030 logical_block_size, MD_SECTOR_SIZE);
1031 dev_warn(DEV, "Workaround engaged (has performance impact).\n");
1032
1033 mdev->md_io_tmpp = page;
1034 }
1035 }
1036
Philipp Reisnerb411b362009-09-25 16:07:19 -07001037 if (!mdev->bitmap) {
1038 if (drbd_bm_init(mdev)) {
1039 retcode = ERR_NOMEM;
1040 goto force_diskless_dec;
1041 }
1042 }
1043
1044 retcode = drbd_md_read(mdev, nbc);
1045 if (retcode != NO_ERROR)
1046 goto force_diskless_dec;
1047
1048 if (mdev->state.conn < C_CONNECTED &&
1049 mdev->state.role == R_PRIMARY &&
1050 (mdev->ed_uuid & ~((u64)1)) != (nbc->md.uuid[UI_CURRENT] & ~((u64)1))) {
1051 dev_err(DEV, "Can only attach to data with current UUID=%016llX\n",
1052 (unsigned long long)mdev->ed_uuid);
1053 retcode = ERR_DATA_NOT_CURRENT;
1054 goto force_diskless_dec;
1055 }
1056
1057 /* Since we are diskless, fix the activity log first... */
1058 if (drbd_check_al_size(mdev)) {
1059 retcode = ERR_NOMEM;
1060 goto force_diskless_dec;
1061 }
1062
1063 /* Prevent shrinking of consistent devices ! */
1064 if (drbd_md_test_flag(nbc, MDF_CONSISTENT) &&
Philipp Reisnera393db62009-12-22 13:35:52 +01001065 drbd_new_dev_size(mdev, nbc, 0) < nbc->md.la_size_sect) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001066 dev_warn(DEV, "refusing to truncate a consistent device\n");
1067 retcode = ERR_DISK_TO_SMALL;
1068 goto force_diskless_dec;
1069 }
1070
1071 if (!drbd_al_read_log(mdev, nbc)) {
1072 retcode = ERR_IO_MD_DISK;
1073 goto force_diskless_dec;
1074 }
1075
Philipp Reisnerb411b362009-09-25 16:07:19 -07001076 /* Reset the "barriers don't work" bits here, then force meta data to
1077 * be written, to ensure we determine if barriers are supported. */
1078 if (nbc->dc.no_md_flush)
Philipp Reisnera8a4e512010-08-25 10:21:04 +02001079 set_bit(MD_NO_FUA, &mdev->flags);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001080 else
Philipp Reisnera8a4e512010-08-25 10:21:04 +02001081 clear_bit(MD_NO_FUA, &mdev->flags);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001082
1083 /* Point of no return reached.
1084 * Devices and memory are no longer released by error cleanup below.
1085 * now mdev takes over responsibility, and the state engine should
1086 * clean it up somewhere. */
1087 D_ASSERT(mdev->ldev == NULL);
1088 mdev->ldev = nbc;
1089 mdev->resync = resync_lru;
1090 nbc = NULL;
1091 resync_lru = NULL;
1092
Philipp Reisner2451fc32010-08-24 13:43:11 +02001093 mdev->write_ordering = WO_bdev_flush;
1094 drbd_bump_write_ordering(mdev, WO_bdev_flush);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001095
1096 if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY))
1097 set_bit(CRASHED_PRIMARY, &mdev->flags);
1098 else
1099 clear_bit(CRASHED_PRIMARY, &mdev->flags);
1100
Philipp Reisner894c6a92010-06-18 16:03:20 +02001101 if (drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) &&
Philipp Reisnerfb22c402010-09-08 23:20:21 +02001102 !(mdev->state.role == R_PRIMARY && mdev->state.susp_nod)) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001103 set_bit(CRASHED_PRIMARY, &mdev->flags);
1104 cp_discovered = 1;
1105 }
1106
1107 mdev->send_cnt = 0;
1108 mdev->recv_cnt = 0;
1109 mdev->read_cnt = 0;
1110 mdev->writ_cnt = 0;
1111
Lars Ellenberg1816a2b2010-11-11 15:19:07 +01001112 max_bio_size = DRBD_MAX_BIO_SIZE;
Lars Ellenberg8979d9c2010-09-14 15:56:29 +02001113 if (mdev->state.conn == C_CONNECTED) {
1114 /* We are Primary, Connected, and now attach a new local
1115 * backing store. We must not increase the user visible maximum
1116 * bio size on this device to something the peer may not be
1117 * able to handle. */
1118 if (mdev->agreed_pro_version < 94)
Lars Ellenberg1816a2b2010-11-11 15:19:07 +01001119 max_bio_size = queue_max_hw_sectors(mdev->rq_queue) << 9;
Lars Ellenberg8979d9c2010-09-14 15:56:29 +02001120 else if (mdev->agreed_pro_version == 94)
Lars Ellenberg1816a2b2010-11-11 15:19:07 +01001121 max_bio_size = DRBD_MAX_SIZE_H80_PACKET;
Lars Ellenberg8979d9c2010-09-14 15:56:29 +02001122 /* else: drbd 8.3.9 and later, stay with default */
1123 }
1124
Lars Ellenberg1816a2b2010-11-11 15:19:07 +01001125 drbd_setup_queue_param(mdev, max_bio_size);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001126
1127 /* If I am currently not R_PRIMARY,
1128 * but meta data primary indicator is set,
1129 * I just now recover from a hard crash,
1130 * and have been R_PRIMARY before that crash.
1131 *
1132 * Now, if I had no connection before that crash
1133 * (have been degraded R_PRIMARY), chances are that
1134 * I won't find my peer now either.
1135 *
1136 * In that case, and _only_ in that case,
1137 * we use the degr-wfc-timeout instead of the default,
1138 * so we can automatically recover from a crash of a
1139 * degraded but active "cluster" after a certain timeout.
1140 */
1141 clear_bit(USE_DEGR_WFC_T, &mdev->flags);
1142 if (mdev->state.role != R_PRIMARY &&
1143 drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) &&
1144 !drbd_md_test_flag(mdev->ldev, MDF_CONNECTED_IND))
1145 set_bit(USE_DEGR_WFC_T, &mdev->flags);
1146
Philipp Reisnera393db62009-12-22 13:35:52 +01001147 dd = drbd_determin_dev_size(mdev, 0);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001148 if (dd == dev_size_error) {
1149 retcode = ERR_NOMEM_BITMAP;
1150 goto force_diskless_dec;
1151 } else if (dd == grew)
1152 set_bit(RESYNC_AFTER_NEG, &mdev->flags);
1153
1154 if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC)) {
1155 dev_info(DEV, "Assuming that all blocks are out of sync "
1156 "(aka FullSync)\n");
1157 if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, "set_n_write from attaching")) {
1158 retcode = ERR_IO_MD_DISK;
1159 goto force_diskless_dec;
1160 }
1161 } else {
1162 if (drbd_bitmap_io(mdev, &drbd_bm_read, "read from attaching") < 0) {
1163 retcode = ERR_IO_MD_DISK;
1164 goto force_diskless_dec;
1165 }
1166 }
1167
1168 if (cp_discovered) {
1169 drbd_al_apply_to_bm(mdev);
1170 drbd_al_to_on_disk_bm(mdev);
1171 }
1172
Philipp Reisner07782862010-08-31 12:00:50 +02001173 if (_drbd_bm_total_weight(mdev) == drbd_bm_bits(mdev))
1174 drbd_suspend_al(mdev); /* IO is still suspended here... */
1175
Philipp Reisnerb411b362009-09-25 16:07:19 -07001176 spin_lock_irq(&mdev->req_lock);
1177 os = mdev->state;
1178 ns.i = os.i;
1179 /* If MDF_CONSISTENT is not set go into inconsistent state,
1180 otherwise investigate MDF_WasUpToDate...
1181 If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state,
1182 otherwise into D_CONSISTENT state.
1183 */
1184 if (drbd_md_test_flag(mdev->ldev, MDF_CONSISTENT)) {
1185 if (drbd_md_test_flag(mdev->ldev, MDF_WAS_UP_TO_DATE))
1186 ns.disk = D_CONSISTENT;
1187 else
1188 ns.disk = D_OUTDATED;
1189 } else {
1190 ns.disk = D_INCONSISTENT;
1191 }
1192
1193 if (drbd_md_test_flag(mdev->ldev, MDF_PEER_OUT_DATED))
1194 ns.pdsk = D_OUTDATED;
1195
1196 if ( ns.disk == D_CONSISTENT &&
1197 (ns.pdsk == D_OUTDATED || mdev->ldev->dc.fencing == FP_DONT_CARE))
1198 ns.disk = D_UP_TO_DATE;
1199
1200 /* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND,
1201 MDF_CONSISTENT and MDF_WAS_UP_TO_DATE must happen before
1202 this point, because drbd_request_state() modifies these
1203 flags. */
1204
1205 /* In case we are C_CONNECTED postpone any decision on the new disk
1206 state after the negotiation phase. */
1207 if (mdev->state.conn == C_CONNECTED) {
1208 mdev->new_state_tmp.i = ns.i;
1209 ns.i = os.i;
1210 ns.disk = D_NEGOTIATING;
Philipp Reisnerdc66c742010-06-02 14:31:29 +02001211
1212 /* We expect to receive up-to-date UUIDs soon.
1213 To avoid a race in receive_state, free p_uuid while
1214 holding req_lock. I.e. atomic with the state change */
1215 kfree(mdev->p_uuid);
1216 mdev->p_uuid = NULL;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001217 }
1218
1219 rv = _drbd_set_state(mdev, ns, CS_VERBOSE, NULL);
1220 ns = mdev->state;
1221 spin_unlock_irq(&mdev->req_lock);
1222
1223 if (rv < SS_SUCCESS)
1224 goto force_diskless_dec;
1225
1226 if (mdev->state.role == R_PRIMARY)
1227 mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1;
1228 else
1229 mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
1230
1231 drbd_md_mark_dirty(mdev);
1232 drbd_md_sync(mdev);
1233
1234 kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
1235 put_ldev(mdev);
1236 reply->ret_code = retcode;
1237 drbd_reconfig_done(mdev);
1238 return 0;
1239
1240 force_diskless_dec:
1241 put_ldev(mdev);
1242 force_diskless:
Lars Ellenberg82f59cc2010-10-16 12:13:47 +02001243 drbd_force_state(mdev, NS(disk, D_FAILED));
Philipp Reisnerb411b362009-09-25 16:07:19 -07001244 drbd_md_sync(mdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001245 fail:
1246 if (nbc) {
Tejun Heoe525fd82010-11-13 11:55:17 +01001247 if (nbc->backing_bdev)
1248 blkdev_put(nbc->backing_bdev,
1249 FMODE_READ | FMODE_WRITE | FMODE_EXCL);
1250 if (nbc->md_bdev)
1251 blkdev_put(nbc->md_bdev,
1252 FMODE_READ | FMODE_WRITE | FMODE_EXCL);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001253 kfree(nbc);
1254 }
1255 lc_destroy(resync_lru);
1256
1257 reply->ret_code = retcode;
1258 drbd_reconfig_done(mdev);
1259 return 0;
1260}
1261
Lars Ellenberg82f59cc2010-10-16 12:13:47 +02001262/* Detaching the disk is a process in multiple stages. First we need to lock
1263 * out application IO, in-flight IO, IO stuck in drbd_al_begin_io.
1264 * Then we transition to D_DISKLESS, and wait for put_ldev() to return all
1265 * internal references as well.
1266 * Only then we have finally detached. */
Philipp Reisnerb411b362009-09-25 16:07:19 -07001267static int drbd_nl_detach(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1268 struct drbd_nl_cfg_reply *reply)
1269{
Lars Ellenberg82f59cc2010-10-16 12:13:47 +02001270 drbd_suspend_io(mdev); /* so no-one is stuck in drbd_al_begin_io */
Philipp Reisnerb411b362009-09-25 16:07:19 -07001271 reply->ret_code = drbd_request_state(mdev, NS(disk, D_DISKLESS));
Lars Ellenberg82f59cc2010-10-16 12:13:47 +02001272 if (mdev->state.disk == D_DISKLESS)
1273 wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
1274 drbd_resume_io(mdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001275 return 0;
1276}
1277
1278static int drbd_nl_net_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1279 struct drbd_nl_cfg_reply *reply)
1280{
1281 int i, ns;
Andreas Gruenbacher116676c2010-12-08 13:33:11 +01001282 enum drbd_ret_code retcode;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001283 struct net_conf *new_conf = NULL;
1284 struct crypto_hash *tfm = NULL;
1285 struct crypto_hash *integrity_w_tfm = NULL;
1286 struct crypto_hash *integrity_r_tfm = NULL;
1287 struct hlist_head *new_tl_hash = NULL;
1288 struct hlist_head *new_ee_hash = NULL;
1289 struct drbd_conf *odev;
1290 char hmac_name[CRYPTO_MAX_ALG_NAME];
1291 void *int_dig_out = NULL;
1292 void *int_dig_in = NULL;
1293 void *int_dig_vv = NULL;
1294 struct sockaddr *new_my_addr, *new_peer_addr, *taken_addr;
1295
1296 drbd_reconfig_start(mdev);
1297
1298 if (mdev->state.conn > C_STANDALONE) {
1299 retcode = ERR_NET_CONFIGURED;
1300 goto fail;
1301 }
1302
1303 /* allocation not in the IO path, cqueue thread context */
Julia Lawall2db4e422010-05-13 22:02:21 +02001304 new_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001305 if (!new_conf) {
1306 retcode = ERR_NOMEM;
1307 goto fail;
1308 }
1309
Philipp Reisnerb411b362009-09-25 16:07:19 -07001310 new_conf->timeout = DRBD_TIMEOUT_DEF;
1311 new_conf->try_connect_int = DRBD_CONNECT_INT_DEF;
1312 new_conf->ping_int = DRBD_PING_INT_DEF;
1313 new_conf->max_epoch_size = DRBD_MAX_EPOCH_SIZE_DEF;
1314 new_conf->max_buffers = DRBD_MAX_BUFFERS_DEF;
1315 new_conf->unplug_watermark = DRBD_UNPLUG_WATERMARK_DEF;
1316 new_conf->sndbuf_size = DRBD_SNDBUF_SIZE_DEF;
1317 new_conf->rcvbuf_size = DRBD_RCVBUF_SIZE_DEF;
1318 new_conf->ko_count = DRBD_KO_COUNT_DEF;
1319 new_conf->after_sb_0p = DRBD_AFTER_SB_0P_DEF;
1320 new_conf->after_sb_1p = DRBD_AFTER_SB_1P_DEF;
1321 new_conf->after_sb_2p = DRBD_AFTER_SB_2P_DEF;
1322 new_conf->want_lose = 0;
1323 new_conf->two_primaries = 0;
1324 new_conf->wire_protocol = DRBD_PROT_C;
1325 new_conf->ping_timeo = DRBD_PING_TIMEO_DEF;
1326 new_conf->rr_conflict = DRBD_RR_CONFLICT_DEF;
Philipp Reisner422028b2010-10-27 11:12:07 +02001327 new_conf->on_congestion = DRBD_ON_CONGESTION_DEF;
1328 new_conf->cong_extents = DRBD_CONG_EXTENTS_DEF;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001329
1330 if (!net_conf_from_tags(mdev, nlp->tag_list, new_conf)) {
1331 retcode = ERR_MANDATORY_TAG;
1332 goto fail;
1333 }
1334
1335 if (new_conf->two_primaries
1336 && (new_conf->wire_protocol != DRBD_PROT_C)) {
1337 retcode = ERR_NOT_PROTO_C;
1338 goto fail;
Philipp Reisner47ff2d02010-06-18 13:56:57 +02001339 }
1340
1341 if (get_ldev(mdev)) {
1342 enum drbd_fencing_p fp = mdev->ldev->dc.fencing;
1343 put_ldev(mdev);
1344 if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) {
1345 retcode = ERR_STONITH_AND_PROT_A;
1346 goto fail;
1347 }
1348 }
Philipp Reisnerb411b362009-09-25 16:07:19 -07001349
Philipp Reisner422028b2010-10-27 11:12:07 +02001350 if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) {
1351 retcode = ERR_CONG_NOT_PROTO_A;
1352 goto fail;
1353 }
1354
Philipp Reisnerb411b362009-09-25 16:07:19 -07001355 if (mdev->state.role == R_PRIMARY && new_conf->want_lose) {
1356 retcode = ERR_DISCARD;
1357 goto fail;
1358 }
1359
1360 retcode = NO_ERROR;
1361
1362 new_my_addr = (struct sockaddr *)&new_conf->my_addr;
1363 new_peer_addr = (struct sockaddr *)&new_conf->peer_addr;
1364 for (i = 0; i < minor_count; i++) {
1365 odev = minor_to_mdev(i);
1366 if (!odev || odev == mdev)
1367 continue;
1368 if (get_net_conf(odev)) {
1369 taken_addr = (struct sockaddr *)&odev->net_conf->my_addr;
1370 if (new_conf->my_addr_len == odev->net_conf->my_addr_len &&
1371 !memcmp(new_my_addr, taken_addr, new_conf->my_addr_len))
1372 retcode = ERR_LOCAL_ADDR;
1373
1374 taken_addr = (struct sockaddr *)&odev->net_conf->peer_addr;
1375 if (new_conf->peer_addr_len == odev->net_conf->peer_addr_len &&
1376 !memcmp(new_peer_addr, taken_addr, new_conf->peer_addr_len))
1377 retcode = ERR_PEER_ADDR;
1378
1379 put_net_conf(odev);
1380 if (retcode != NO_ERROR)
1381 goto fail;
1382 }
1383 }
1384
1385 if (new_conf->cram_hmac_alg[0] != 0) {
1386 snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)",
1387 new_conf->cram_hmac_alg);
1388 tfm = crypto_alloc_hash(hmac_name, 0, CRYPTO_ALG_ASYNC);
1389 if (IS_ERR(tfm)) {
1390 tfm = NULL;
1391 retcode = ERR_AUTH_ALG;
1392 goto fail;
1393 }
1394
Philipp Reisner07982192009-12-28 16:58:38 +01001395 if (!drbd_crypto_is_hash(crypto_hash_tfm(tfm))) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001396 retcode = ERR_AUTH_ALG_ND;
1397 goto fail;
1398 }
1399 }
1400
1401 if (new_conf->integrity_alg[0]) {
1402 integrity_w_tfm = crypto_alloc_hash(new_conf->integrity_alg, 0, CRYPTO_ALG_ASYNC);
1403 if (IS_ERR(integrity_w_tfm)) {
1404 integrity_w_tfm = NULL;
1405 retcode=ERR_INTEGRITY_ALG;
1406 goto fail;
1407 }
1408
1409 if (!drbd_crypto_is_hash(crypto_hash_tfm(integrity_w_tfm))) {
1410 retcode=ERR_INTEGRITY_ALG_ND;
1411 goto fail;
1412 }
1413
1414 integrity_r_tfm = crypto_alloc_hash(new_conf->integrity_alg, 0, CRYPTO_ALG_ASYNC);
1415 if (IS_ERR(integrity_r_tfm)) {
1416 integrity_r_tfm = NULL;
1417 retcode=ERR_INTEGRITY_ALG;
1418 goto fail;
1419 }
1420 }
1421
1422 ns = new_conf->max_epoch_size/8;
1423 if (mdev->tl_hash_s != ns) {
1424 new_tl_hash = kzalloc(ns*sizeof(void *), GFP_KERNEL);
1425 if (!new_tl_hash) {
1426 retcode = ERR_NOMEM;
1427 goto fail;
1428 }
1429 }
1430
1431 ns = new_conf->max_buffers/8;
1432 if (new_conf->two_primaries && (mdev->ee_hash_s != ns)) {
1433 new_ee_hash = kzalloc(ns*sizeof(void *), GFP_KERNEL);
1434 if (!new_ee_hash) {
1435 retcode = ERR_NOMEM;
1436 goto fail;
1437 }
1438 }
1439
1440 ((char *)new_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0;
1441
1442 if (integrity_w_tfm) {
1443 i = crypto_hash_digestsize(integrity_w_tfm);
1444 int_dig_out = kmalloc(i, GFP_KERNEL);
1445 if (!int_dig_out) {
1446 retcode = ERR_NOMEM;
1447 goto fail;
1448 }
1449 int_dig_in = kmalloc(i, GFP_KERNEL);
1450 if (!int_dig_in) {
1451 retcode = ERR_NOMEM;
1452 goto fail;
1453 }
1454 int_dig_vv = kmalloc(i, GFP_KERNEL);
1455 if (!int_dig_vv) {
1456 retcode = ERR_NOMEM;
1457 goto fail;
1458 }
1459 }
1460
1461 if (!mdev->bitmap) {
1462 if(drbd_bm_init(mdev)) {
1463 retcode = ERR_NOMEM;
1464 goto fail;
1465 }
1466 }
1467
Philipp Reisnerf70b35112010-06-24 14:34:40 +02001468 drbd_flush_workqueue(mdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001469 spin_lock_irq(&mdev->req_lock);
1470 if (mdev->net_conf != NULL) {
1471 retcode = ERR_NET_CONFIGURED;
1472 spin_unlock_irq(&mdev->req_lock);
1473 goto fail;
1474 }
1475 mdev->net_conf = new_conf;
1476
1477 mdev->send_cnt = 0;
1478 mdev->recv_cnt = 0;
1479
1480 if (new_tl_hash) {
1481 kfree(mdev->tl_hash);
1482 mdev->tl_hash_s = mdev->net_conf->max_epoch_size/8;
1483 mdev->tl_hash = new_tl_hash;
1484 }
1485
1486 if (new_ee_hash) {
1487 kfree(mdev->ee_hash);
1488 mdev->ee_hash_s = mdev->net_conf->max_buffers/8;
1489 mdev->ee_hash = new_ee_hash;
1490 }
1491
1492 crypto_free_hash(mdev->cram_hmac_tfm);
1493 mdev->cram_hmac_tfm = tfm;
1494
1495 crypto_free_hash(mdev->integrity_w_tfm);
1496 mdev->integrity_w_tfm = integrity_w_tfm;
1497
1498 crypto_free_hash(mdev->integrity_r_tfm);
1499 mdev->integrity_r_tfm = integrity_r_tfm;
1500
1501 kfree(mdev->int_dig_out);
1502 kfree(mdev->int_dig_in);
1503 kfree(mdev->int_dig_vv);
1504 mdev->int_dig_out=int_dig_out;
1505 mdev->int_dig_in=int_dig_in;
1506 mdev->int_dig_vv=int_dig_vv;
Philipp Reisnerf70b35112010-06-24 14:34:40 +02001507 retcode = _drbd_set_state(_NS(mdev, conn, C_UNCONNECTED), CS_VERBOSE, NULL);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001508 spin_unlock_irq(&mdev->req_lock);
1509
Philipp Reisnerb411b362009-09-25 16:07:19 -07001510 kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
1511 reply->ret_code = retcode;
1512 drbd_reconfig_done(mdev);
1513 return 0;
1514
1515fail:
1516 kfree(int_dig_out);
1517 kfree(int_dig_in);
1518 kfree(int_dig_vv);
1519 crypto_free_hash(tfm);
1520 crypto_free_hash(integrity_w_tfm);
1521 crypto_free_hash(integrity_r_tfm);
1522 kfree(new_tl_hash);
1523 kfree(new_ee_hash);
1524 kfree(new_conf);
1525
1526 reply->ret_code = retcode;
1527 drbd_reconfig_done(mdev);
1528 return 0;
1529}
1530
1531static int drbd_nl_disconnect(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1532 struct drbd_nl_cfg_reply *reply)
1533{
1534 int retcode;
Philipp Reisner2561b9c2010-12-03 15:22:48 +01001535 struct disconnect dc;
1536
1537 memset(&dc, 0, sizeof(struct disconnect));
1538 if (!disconnect_from_tags(mdev, nlp->tag_list, &dc)) {
1539 retcode = ERR_MANDATORY_TAG;
1540 goto fail;
1541 }
1542
1543 if (dc.force) {
1544 spin_lock_irq(&mdev->req_lock);
1545 if (mdev->state.conn >= C_WF_CONNECTION)
1546 _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), CS_HARD, NULL);
1547 spin_unlock_irq(&mdev->req_lock);
1548 goto done;
1549 }
Philipp Reisnerb411b362009-09-25 16:07:19 -07001550
1551 retcode = _drbd_request_state(mdev, NS(conn, C_DISCONNECTING), CS_ORDERED);
1552
1553 if (retcode == SS_NOTHING_TO_DO)
1554 goto done;
1555 else if (retcode == SS_ALREADY_STANDALONE)
1556 goto done;
1557 else if (retcode == SS_PRIMARY_NOP) {
1558 /* Our statche checking code wants to see the peer outdated. */
1559 retcode = drbd_request_state(mdev, NS2(conn, C_DISCONNECTING,
1560 pdsk, D_OUTDATED));
1561 } else if (retcode == SS_CW_FAILED_BY_PEER) {
1562 /* The peer probably wants to see us outdated. */
1563 retcode = _drbd_request_state(mdev, NS2(conn, C_DISCONNECTING,
1564 disk, D_OUTDATED),
1565 CS_ORDERED);
1566 if (retcode == SS_IS_DISKLESS || retcode == SS_LOWER_THAN_OUTDATED) {
1567 drbd_force_state(mdev, NS(conn, C_DISCONNECTING));
1568 retcode = SS_SUCCESS;
1569 }
1570 }
1571
1572 if (retcode < SS_SUCCESS)
1573 goto fail;
1574
1575 if (wait_event_interruptible(mdev->state_wait,
1576 mdev->state.conn != C_DISCONNECTING)) {
1577 /* Do not test for mdev->state.conn == C_STANDALONE, since
1578 someone else might connect us in the mean time! */
1579 retcode = ERR_INTR;
1580 goto fail;
1581 }
1582
1583 done:
1584 retcode = NO_ERROR;
1585 fail:
1586 drbd_md_sync(mdev);
1587 reply->ret_code = retcode;
1588 return 0;
1589}
1590
1591void resync_after_online_grow(struct drbd_conf *mdev)
1592{
1593 int iass; /* I am sync source */
1594
1595 dev_info(DEV, "Resync of new storage after online grow\n");
1596 if (mdev->state.role != mdev->state.peer)
1597 iass = (mdev->state.role == R_PRIMARY);
1598 else
1599 iass = test_bit(DISCARD_CONCURRENT, &mdev->flags);
1600
1601 if (iass)
1602 drbd_start_resync(mdev, C_SYNC_SOURCE);
1603 else
1604 _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE);
1605}
1606
1607static int drbd_nl_resize(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1608 struct drbd_nl_cfg_reply *reply)
1609{
1610 struct resize rs;
1611 int retcode = NO_ERROR;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001612 enum determine_dev_size dd;
Philipp Reisner6495d2c2010-03-24 16:07:04 +01001613 enum dds_flags ddsf;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001614
1615 memset(&rs, 0, sizeof(struct resize));
1616 if (!resize_from_tags(mdev, nlp->tag_list, &rs)) {
1617 retcode = ERR_MANDATORY_TAG;
1618 goto fail;
1619 }
1620
1621 if (mdev->state.conn > C_CONNECTED) {
1622 retcode = ERR_RESIZE_RESYNC;
1623 goto fail;
1624 }
1625
1626 if (mdev->state.role == R_SECONDARY &&
1627 mdev->state.peer == R_SECONDARY) {
1628 retcode = ERR_NO_PRIMARY;
1629 goto fail;
1630 }
1631
1632 if (!get_ldev(mdev)) {
1633 retcode = ERR_NO_DISK;
1634 goto fail;
1635 }
1636
Philipp Reisner6495d2c2010-03-24 16:07:04 +01001637 if (rs.no_resync && mdev->agreed_pro_version < 93) {
1638 retcode = ERR_NEED_APV_93;
1639 goto fail;
1640 }
1641
Philipp Reisner087c2492010-03-26 13:49:56 +01001642 if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev))
Philipp Reisnerb411b362009-09-25 16:07:19 -07001643 mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001644
1645 mdev->ldev->dc.disk_size = (sector_t)rs.resize_size;
Philipp Reisner6495d2c2010-03-24 16:07:04 +01001646 ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0);
1647 dd = drbd_determin_dev_size(mdev, ddsf);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001648 drbd_md_sync(mdev);
1649 put_ldev(mdev);
1650 if (dd == dev_size_error) {
1651 retcode = ERR_NOMEM_BITMAP;
1652 goto fail;
1653 }
1654
Philipp Reisner087c2492010-03-26 13:49:56 +01001655 if (mdev->state.conn == C_CONNECTED) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07001656 if (dd == grew)
1657 set_bit(RESIZE_PENDING, &mdev->flags);
1658
1659 drbd_send_uuids(mdev);
Philipp Reisner6495d2c2010-03-24 16:07:04 +01001660 drbd_send_sizes(mdev, 1, ddsf);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001661 }
1662
1663 fail:
1664 reply->ret_code = retcode;
1665 return 0;
1666}
1667
1668static int drbd_nl_syncer_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1669 struct drbd_nl_cfg_reply *reply)
1670{
1671 int retcode = NO_ERROR;
1672 int err;
1673 int ovr; /* online verify running */
1674 int rsr; /* re-sync running */
1675 struct crypto_hash *verify_tfm = NULL;
1676 struct crypto_hash *csums_tfm = NULL;
1677 struct syncer_conf sc;
1678 cpumask_var_t new_cpu_mask;
Philipp Reisner778f2712010-07-06 11:14:00 +02001679 int *rs_plan_s = NULL;
1680 int fifo_size;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001681
1682 if (!zalloc_cpumask_var(&new_cpu_mask, GFP_KERNEL)) {
1683 retcode = ERR_NOMEM;
1684 goto fail;
1685 }
1686
1687 if (nlp->flags & DRBD_NL_SET_DEFAULTS) {
1688 memset(&sc, 0, sizeof(struct syncer_conf));
1689 sc.rate = DRBD_RATE_DEF;
1690 sc.after = DRBD_AFTER_DEF;
1691 sc.al_extents = DRBD_AL_EXTENTS_DEF;
Philipp Reisner265be2d2010-05-31 10:14:17 +02001692 sc.on_no_data = DRBD_ON_NO_DATA_DEF;
Philipp Reisner9a31d712010-07-05 13:42:03 +02001693 sc.c_plan_ahead = DRBD_C_PLAN_AHEAD_DEF;
1694 sc.c_delay_target = DRBD_C_DELAY_TARGET_DEF;
1695 sc.c_fill_target = DRBD_C_FILL_TARGET_DEF;
Lars Ellenberg0f0601f2010-08-11 23:40:24 +02001696 sc.c_max_rate = DRBD_C_MAX_RATE_DEF;
1697 sc.c_min_rate = DRBD_C_MIN_RATE_DEF;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001698 } else
1699 memcpy(&sc, &mdev->sync_conf, sizeof(struct syncer_conf));
1700
1701 if (!syncer_conf_from_tags(mdev, nlp->tag_list, &sc)) {
1702 retcode = ERR_MANDATORY_TAG;
1703 goto fail;
1704 }
1705
1706 /* re-sync running */
1707 rsr = ( mdev->state.conn == C_SYNC_SOURCE ||
1708 mdev->state.conn == C_SYNC_TARGET ||
1709 mdev->state.conn == C_PAUSED_SYNC_S ||
1710 mdev->state.conn == C_PAUSED_SYNC_T );
1711
1712 if (rsr && strcmp(sc.csums_alg, mdev->sync_conf.csums_alg)) {
1713 retcode = ERR_CSUMS_RESYNC_RUNNING;
1714 goto fail;
1715 }
1716
1717 if (!rsr && sc.csums_alg[0]) {
1718 csums_tfm = crypto_alloc_hash(sc.csums_alg, 0, CRYPTO_ALG_ASYNC);
1719 if (IS_ERR(csums_tfm)) {
1720 csums_tfm = NULL;
1721 retcode = ERR_CSUMS_ALG;
1722 goto fail;
1723 }
1724
1725 if (!drbd_crypto_is_hash(crypto_hash_tfm(csums_tfm))) {
1726 retcode = ERR_CSUMS_ALG_ND;
1727 goto fail;
1728 }
1729 }
1730
1731 /* online verify running */
1732 ovr = (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T);
1733
1734 if (ovr) {
1735 if (strcmp(sc.verify_alg, mdev->sync_conf.verify_alg)) {
1736 retcode = ERR_VERIFY_RUNNING;
1737 goto fail;
1738 }
1739 }
1740
1741 if (!ovr && sc.verify_alg[0]) {
1742 verify_tfm = crypto_alloc_hash(sc.verify_alg, 0, CRYPTO_ALG_ASYNC);
1743 if (IS_ERR(verify_tfm)) {
1744 verify_tfm = NULL;
1745 retcode = ERR_VERIFY_ALG;
1746 goto fail;
1747 }
1748
1749 if (!drbd_crypto_is_hash(crypto_hash_tfm(verify_tfm))) {
1750 retcode = ERR_VERIFY_ALG_ND;
1751 goto fail;
1752 }
1753 }
1754
1755 /* silently ignore cpu mask on UP kernel */
1756 if (nr_cpu_ids > 1 && sc.cpu_mask[0] != 0) {
1757 err = __bitmap_parse(sc.cpu_mask, 32, 0,
1758 cpumask_bits(new_cpu_mask), nr_cpu_ids);
1759 if (err) {
1760 dev_warn(DEV, "__bitmap_parse() failed with %d\n", err);
1761 retcode = ERR_CPU_MASK_PARSE;
1762 goto fail;
1763 }
1764 }
1765
1766 ERR_IF (sc.rate < 1) sc.rate = 1;
1767 ERR_IF (sc.al_extents < 7) sc.al_extents = 127; /* arbitrary minimum */
1768#define AL_MAX ((MD_AL_MAX_SIZE-1) * AL_EXTENTS_PT)
1769 if (sc.al_extents > AL_MAX) {
1770 dev_err(DEV, "sc.al_extents > %d\n", AL_MAX);
1771 sc.al_extents = AL_MAX;
1772 }
1773#undef AL_MAX
1774
Lars Ellenbergef50a3e2010-09-01 14:39:30 +02001775 /* to avoid spurious errors when configuring minors before configuring
1776 * the minors they depend on: if necessary, first create the minor we
1777 * depend on */
1778 if (sc.after >= 0)
1779 ensure_mdev(sc.after, 1);
1780
Philipp Reisnerb411b362009-09-25 16:07:19 -07001781 /* most sanity checks done, try to assign the new sync-after
1782 * dependency. need to hold the global lock in there,
1783 * to avoid a race in the dependency loop check. */
1784 retcode = drbd_alter_sa(mdev, sc.after);
1785 if (retcode != NO_ERROR)
1786 goto fail;
1787
Philipp Reisner778f2712010-07-06 11:14:00 +02001788 fifo_size = (sc.c_plan_ahead * 10 * SLEEP_TIME) / HZ;
1789 if (fifo_size != mdev->rs_plan_s.size && fifo_size > 0) {
1790 rs_plan_s = kzalloc(sizeof(int) * fifo_size, GFP_KERNEL);
1791 if (!rs_plan_s) {
1792 dev_err(DEV, "kmalloc of fifo_buffer failed");
1793 retcode = ERR_NOMEM;
1794 goto fail;
1795 }
1796 }
1797
Philipp Reisnerb411b362009-09-25 16:07:19 -07001798 /* ok, assign the rest of it as well.
1799 * lock against receive_SyncParam() */
1800 spin_lock(&mdev->peer_seq_lock);
1801 mdev->sync_conf = sc;
1802
1803 if (!rsr) {
1804 crypto_free_hash(mdev->csums_tfm);
1805 mdev->csums_tfm = csums_tfm;
1806 csums_tfm = NULL;
1807 }
1808
1809 if (!ovr) {
1810 crypto_free_hash(mdev->verify_tfm);
1811 mdev->verify_tfm = verify_tfm;
1812 verify_tfm = NULL;
1813 }
Philipp Reisner778f2712010-07-06 11:14:00 +02001814
1815 if (fifo_size != mdev->rs_plan_s.size) {
1816 kfree(mdev->rs_plan_s.values);
1817 mdev->rs_plan_s.values = rs_plan_s;
1818 mdev->rs_plan_s.size = fifo_size;
1819 mdev->rs_planed = 0;
1820 rs_plan_s = NULL;
1821 }
1822
Philipp Reisnerb411b362009-09-25 16:07:19 -07001823 spin_unlock(&mdev->peer_seq_lock);
1824
1825 if (get_ldev(mdev)) {
1826 wait_event(mdev->al_wait, lc_try_lock(mdev->act_log));
1827 drbd_al_shrink(mdev);
1828 err = drbd_check_al_size(mdev);
1829 lc_unlock(mdev->act_log);
1830 wake_up(&mdev->al_wait);
1831
1832 put_ldev(mdev);
1833 drbd_md_sync(mdev);
1834
1835 if (err) {
1836 retcode = ERR_NOMEM;
1837 goto fail;
1838 }
1839 }
1840
1841 if (mdev->state.conn >= C_CONNECTED)
1842 drbd_send_sync_param(mdev, &sc);
1843
1844 if (!cpumask_equal(mdev->cpu_mask, new_cpu_mask)) {
1845 cpumask_copy(mdev->cpu_mask, new_cpu_mask);
1846 drbd_calc_cpu_mask(mdev);
1847 mdev->receiver.reset_cpu_mask = 1;
1848 mdev->asender.reset_cpu_mask = 1;
1849 mdev->worker.reset_cpu_mask = 1;
1850 }
1851
1852 kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
1853fail:
Philipp Reisner778f2712010-07-06 11:14:00 +02001854 kfree(rs_plan_s);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001855 free_cpumask_var(new_cpu_mask);
1856 crypto_free_hash(csums_tfm);
1857 crypto_free_hash(verify_tfm);
1858 reply->ret_code = retcode;
1859 return 0;
1860}
1861
1862static int drbd_nl_invalidate(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1863 struct drbd_nl_cfg_reply *reply)
1864{
1865 int retcode;
1866
1867 retcode = _drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T), CS_ORDERED);
1868
1869 if (retcode < SS_SUCCESS && retcode != SS_NEED_CONNECTION)
1870 retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T));
1871
1872 while (retcode == SS_NEED_CONNECTION) {
1873 spin_lock_irq(&mdev->req_lock);
1874 if (mdev->state.conn < C_CONNECTED)
1875 retcode = _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_VERBOSE, NULL);
1876 spin_unlock_irq(&mdev->req_lock);
1877
1878 if (retcode != SS_NEED_CONNECTION)
1879 break;
1880
1881 retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T));
1882 }
1883
1884 reply->ret_code = retcode;
1885 return 0;
1886}
1887
Philipp Reisner07782862010-08-31 12:00:50 +02001888static int drbd_bmio_set_susp_al(struct drbd_conf *mdev)
1889{
1890 int rv;
1891
1892 rv = drbd_bmio_set_n_write(mdev);
1893 drbd_suspend_al(mdev);
1894 return rv;
1895}
1896
Philipp Reisnerb411b362009-09-25 16:07:19 -07001897static int drbd_nl_invalidate_peer(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1898 struct drbd_nl_cfg_reply *reply)
1899{
Philipp Reisner07782862010-08-31 12:00:50 +02001900 int retcode;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001901
Philipp Reisner07782862010-08-31 12:00:50 +02001902 retcode = _drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S), CS_ORDERED);
Philipp Reisnerb411b362009-09-25 16:07:19 -07001903
Philipp Reisner07782862010-08-31 12:00:50 +02001904 if (retcode < SS_SUCCESS) {
1905 if (retcode == SS_NEED_CONNECTION && mdev->state.role == R_PRIMARY) {
1906 /* The peer will get a resync upon connect anyways. Just make that
1907 into a full resync. */
1908 retcode = drbd_request_state(mdev, NS(pdsk, D_INCONSISTENT));
1909 if (retcode >= SS_SUCCESS) {
1910 /* open coded drbd_bitmap_io() */
1911 if (drbd_bitmap_io(mdev, &drbd_bmio_set_susp_al,
1912 "set_n_write from invalidate_peer"))
1913 retcode = ERR_IO_MD_DISK;
1914 }
1915 } else
1916 retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S));
1917 }
1918
1919 reply->ret_code = retcode;
Philipp Reisnerb411b362009-09-25 16:07:19 -07001920 return 0;
1921}
1922
1923static int drbd_nl_pause_sync(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1924 struct drbd_nl_cfg_reply *reply)
1925{
1926 int retcode = NO_ERROR;
1927
1928 if (drbd_request_state(mdev, NS(user_isp, 1)) == SS_NOTHING_TO_DO)
1929 retcode = ERR_PAUSE_IS_SET;
1930
1931 reply->ret_code = retcode;
1932 return 0;
1933}
1934
1935static int drbd_nl_resume_sync(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1936 struct drbd_nl_cfg_reply *reply)
1937{
1938 int retcode = NO_ERROR;
1939
1940 if (drbd_request_state(mdev, NS(user_isp, 0)) == SS_NOTHING_TO_DO)
1941 retcode = ERR_PAUSE_IS_CLEAR;
1942
1943 reply->ret_code = retcode;
1944 return 0;
1945}
1946
1947static int drbd_nl_suspend_io(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1948 struct drbd_nl_cfg_reply *reply)
1949{
1950 reply->ret_code = drbd_request_state(mdev, NS(susp, 1));
1951
1952 return 0;
1953}
1954
1955static int drbd_nl_resume_io(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1956 struct drbd_nl_cfg_reply *reply)
1957{
Philipp Reisner43a51822010-06-11 11:26:34 +02001958 if (test_bit(NEW_CUR_UUID, &mdev->flags)) {
1959 drbd_uuid_new_current(mdev);
1960 clear_bit(NEW_CUR_UUID, &mdev->flags);
Philipp Reisner43a51822010-06-11 11:26:34 +02001961 }
Philipp Reisner265be2d2010-05-31 10:14:17 +02001962 drbd_suspend_io(mdev);
Philipp Reisnerfb22c402010-09-08 23:20:21 +02001963 reply->ret_code = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0));
Philipp Reisner265be2d2010-05-31 10:14:17 +02001964 if (reply->ret_code == SS_SUCCESS) {
1965 if (mdev->state.conn < C_CONNECTED)
1966 tl_clear(mdev);
1967 if (mdev->state.disk == D_DISKLESS || mdev->state.disk == D_FAILED)
1968 tl_restart(mdev, fail_frozen_disk_io);
1969 }
1970 drbd_resume_io(mdev);
1971
Philipp Reisnerb411b362009-09-25 16:07:19 -07001972 return 0;
1973}
1974
1975static int drbd_nl_outdate(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1976 struct drbd_nl_cfg_reply *reply)
1977{
1978 reply->ret_code = drbd_request_state(mdev, NS(disk, D_OUTDATED));
1979 return 0;
1980}
1981
1982static int drbd_nl_get_config(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
1983 struct drbd_nl_cfg_reply *reply)
1984{
1985 unsigned short *tl;
1986
1987 tl = reply->tag_list;
1988
1989 if (get_ldev(mdev)) {
1990 tl = disk_conf_to_tags(mdev, &mdev->ldev->dc, tl);
1991 put_ldev(mdev);
1992 }
1993
1994 if (get_net_conf(mdev)) {
1995 tl = net_conf_to_tags(mdev, mdev->net_conf, tl);
1996 put_net_conf(mdev);
1997 }
1998 tl = syncer_conf_to_tags(mdev, &mdev->sync_conf, tl);
1999
2000 put_unaligned(TT_END, tl++); /* Close the tag list */
2001
2002 return (int)((char *)tl - (char *)reply->tag_list);
2003}
2004
2005static int drbd_nl_get_state(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
2006 struct drbd_nl_cfg_reply *reply)
2007{
2008 unsigned short *tl = reply->tag_list;
2009 union drbd_state s = mdev->state;
2010 unsigned long rs_left;
2011 unsigned int res;
2012
2013 tl = get_state_to_tags(mdev, (struct get_state *)&s, tl);
2014
2015 /* no local ref, no bitmap, no syncer progress. */
2016 if (s.conn >= C_SYNC_SOURCE && s.conn <= C_PAUSED_SYNC_T) {
2017 if (get_ldev(mdev)) {
2018 drbd_get_syncer_progress(mdev, &rs_left, &res);
2019 tl = tl_add_int(tl, T_sync_progress, &res);
2020 put_ldev(mdev);
2021 }
2022 }
2023 put_unaligned(TT_END, tl++); /* Close the tag list */
2024
2025 return (int)((char *)tl - (char *)reply->tag_list);
2026}
2027
2028static int drbd_nl_get_uuids(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
2029 struct drbd_nl_cfg_reply *reply)
2030{
2031 unsigned short *tl;
2032
2033 tl = reply->tag_list;
2034
2035 if (get_ldev(mdev)) {
2036 tl = tl_add_blob(tl, T_uuids, mdev->ldev->md.uuid, UI_SIZE*sizeof(u64));
2037 tl = tl_add_int(tl, T_uuids_flags, &mdev->ldev->md.flags);
2038 put_ldev(mdev);
2039 }
2040 put_unaligned(TT_END, tl++); /* Close the tag list */
2041
2042 return (int)((char *)tl - (char *)reply->tag_list);
2043}
2044
2045/**
2046 * drbd_nl_get_timeout_flag() - Used by drbdsetup to find out which timeout value to use
2047 * @mdev: DRBD device.
2048 * @nlp: Netlink/connector packet from drbdsetup
2049 * @reply: Reply packet for drbdsetup
2050 */
2051static int drbd_nl_get_timeout_flag(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
2052 struct drbd_nl_cfg_reply *reply)
2053{
2054 unsigned short *tl;
2055 char rv;
2056
2057 tl = reply->tag_list;
2058
2059 rv = mdev->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED :
2060 test_bit(USE_DEGR_WFC_T, &mdev->flags) ? UT_DEGRADED : UT_DEFAULT;
2061
2062 tl = tl_add_blob(tl, T_use_degraded, &rv, sizeof(rv));
2063 put_unaligned(TT_END, tl++); /* Close the tag list */
2064
2065 return (int)((char *)tl - (char *)reply->tag_list);
2066}
2067
2068static int drbd_nl_start_ov(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
2069 struct drbd_nl_cfg_reply *reply)
2070{
2071 /* default to resume from last known position, if possible */
2072 struct start_ov args =
2073 { .start_sector = mdev->ov_start_sector };
2074
2075 if (!start_ov_from_tags(mdev, nlp->tag_list, &args)) {
2076 reply->ret_code = ERR_MANDATORY_TAG;
2077 return 0;
2078 }
2079 /* w_make_ov_request expects position to be aligned */
2080 mdev->ov_start_sector = args.start_sector & ~BM_SECT_PER_BIT;
2081 reply->ret_code = drbd_request_state(mdev,NS(conn,C_VERIFY_S));
2082 return 0;
2083}
2084
2085
2086static int drbd_nl_new_c_uuid(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp,
2087 struct drbd_nl_cfg_reply *reply)
2088{
2089 int retcode = NO_ERROR;
2090 int skip_initial_sync = 0;
2091 int err;
2092
2093 struct new_c_uuid args;
2094
2095 memset(&args, 0, sizeof(struct new_c_uuid));
2096 if (!new_c_uuid_from_tags(mdev, nlp->tag_list, &args)) {
2097 reply->ret_code = ERR_MANDATORY_TAG;
2098 return 0;
2099 }
2100
2101 mutex_lock(&mdev->state_mutex); /* Protects us against serialized state changes. */
2102
2103 if (!get_ldev(mdev)) {
2104 retcode = ERR_NO_DISK;
2105 goto out;
2106 }
2107
2108 /* this is "skip initial sync", assume to be clean */
2109 if (mdev->state.conn == C_CONNECTED && mdev->agreed_pro_version >= 90 &&
2110 mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) {
2111 dev_info(DEV, "Preparing to skip initial sync\n");
2112 skip_initial_sync = 1;
2113 } else if (mdev->state.conn != C_STANDALONE) {
2114 retcode = ERR_CONNECTED;
2115 goto out_dec;
2116 }
2117
2118 drbd_uuid_set(mdev, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */
2119 drbd_uuid_new_current(mdev); /* New current, previous to UI_BITMAP */
2120
2121 if (args.clear_bm) {
2122 err = drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, "clear_n_write from new_c_uuid");
2123 if (err) {
2124 dev_err(DEV, "Writing bitmap failed with %d\n",err);
2125 retcode = ERR_IO_MD_DISK;
2126 }
2127 if (skip_initial_sync) {
2128 drbd_send_uuids_skip_initial_sync(mdev);
2129 _drbd_uuid_set(mdev, UI_BITMAP, 0);
2130 spin_lock_irq(&mdev->req_lock);
2131 _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE),
2132 CS_VERBOSE, NULL);
2133 spin_unlock_irq(&mdev->req_lock);
2134 }
2135 }
2136
2137 drbd_md_sync(mdev);
2138out_dec:
2139 put_ldev(mdev);
2140out:
2141 mutex_unlock(&mdev->state_mutex);
2142
2143 reply->ret_code = retcode;
2144 return 0;
2145}
2146
Philipp Reisnerb411b362009-09-25 16:07:19 -07002147struct cn_handler_struct {
2148 int (*function)(struct drbd_conf *,
2149 struct drbd_nl_cfg_req *,
2150 struct drbd_nl_cfg_reply *);
2151 int reply_body_size;
2152};
2153
2154static struct cn_handler_struct cnd_table[] = {
2155 [ P_primary ] = { &drbd_nl_primary, 0 },
2156 [ P_secondary ] = { &drbd_nl_secondary, 0 },
2157 [ P_disk_conf ] = { &drbd_nl_disk_conf, 0 },
2158 [ P_detach ] = { &drbd_nl_detach, 0 },
2159 [ P_net_conf ] = { &drbd_nl_net_conf, 0 },
2160 [ P_disconnect ] = { &drbd_nl_disconnect, 0 },
2161 [ P_resize ] = { &drbd_nl_resize, 0 },
2162 [ P_syncer_conf ] = { &drbd_nl_syncer_conf, 0 },
2163 [ P_invalidate ] = { &drbd_nl_invalidate, 0 },
2164 [ P_invalidate_peer ] = { &drbd_nl_invalidate_peer, 0 },
2165 [ P_pause_sync ] = { &drbd_nl_pause_sync, 0 },
2166 [ P_resume_sync ] = { &drbd_nl_resume_sync, 0 },
2167 [ P_suspend_io ] = { &drbd_nl_suspend_io, 0 },
2168 [ P_resume_io ] = { &drbd_nl_resume_io, 0 },
2169 [ P_outdate ] = { &drbd_nl_outdate, 0 },
2170 [ P_get_config ] = { &drbd_nl_get_config,
2171 sizeof(struct syncer_conf_tag_len_struct) +
2172 sizeof(struct disk_conf_tag_len_struct) +
2173 sizeof(struct net_conf_tag_len_struct) },
2174 [ P_get_state ] = { &drbd_nl_get_state,
2175 sizeof(struct get_state_tag_len_struct) +
2176 sizeof(struct sync_progress_tag_len_struct) },
2177 [ P_get_uuids ] = { &drbd_nl_get_uuids,
2178 sizeof(struct get_uuids_tag_len_struct) },
2179 [ P_get_timeout_flag ] = { &drbd_nl_get_timeout_flag,
2180 sizeof(struct get_timeout_flag_tag_len_struct)},
2181 [ P_start_ov ] = { &drbd_nl_start_ov, 0 },
2182 [ P_new_c_uuid ] = { &drbd_nl_new_c_uuid, 0 },
2183};
2184
Philipp Reisner9f5180e2009-10-06 09:30:14 +02002185static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms *nsp)
Philipp Reisnerb411b362009-09-25 16:07:19 -07002186{
2187 struct drbd_nl_cfg_req *nlp = (struct drbd_nl_cfg_req *)req->data;
2188 struct cn_handler_struct *cm;
2189 struct cn_msg *cn_reply;
2190 struct drbd_nl_cfg_reply *reply;
2191 struct drbd_conf *mdev;
2192 int retcode, rr;
2193 int reply_size = sizeof(struct cn_msg)
2194 + sizeof(struct drbd_nl_cfg_reply)
2195 + sizeof(short int);
2196
2197 if (!try_module_get(THIS_MODULE)) {
2198 printk(KERN_ERR "drbd: try_module_get() failed!\n");
2199 return;
2200 }
2201
Philipp Reisner9f5180e2009-10-06 09:30:14 +02002202 if (!cap_raised(nsp->eff_cap, CAP_SYS_ADMIN)) {
2203 retcode = ERR_PERM;
2204 goto fail;
2205 }
2206
Lars Ellenbergef50a3e2010-09-01 14:39:30 +02002207 mdev = ensure_mdev(nlp->drbd_minor,
2208 (nlp->flags & DRBD_NL_CREATE_DEVICE));
Philipp Reisnerb411b362009-09-25 16:07:19 -07002209 if (!mdev) {
2210 retcode = ERR_MINOR_INVALID;
2211 goto fail;
2212 }
2213
Lars Ellenberg42ff2692010-11-24 10:11:14 +01002214 if (nlp->packet_type >= P_nl_after_last_packet ||
2215 nlp->packet_type == P_return_code_only) {
Philipp Reisnerb411b362009-09-25 16:07:19 -07002216 retcode = ERR_PACKET_NR;
2217 goto fail;
2218 }
2219
2220 cm = cnd_table + nlp->packet_type;
2221
2222 /* This may happen if packet number is 0: */
2223 if (cm->function == NULL) {
2224 retcode = ERR_PACKET_NR;
2225 goto fail;
2226 }
2227
2228 reply_size += cm->reply_body_size;
2229
2230 /* allocation not in the IO path, cqueue thread context */
Lars Ellenberg3e3a7762010-11-24 10:41:45 +01002231 cn_reply = kzalloc(reply_size, GFP_KERNEL);
Philipp Reisnerb411b362009-09-25 16:07:19 -07002232 if (!cn_reply) {
2233 retcode = ERR_NOMEM;
2234 goto fail;
2235 }
2236 reply = (struct drbd_nl_cfg_reply *) cn_reply->data;
2237
2238 reply->packet_type =
Lars Ellenberg42ff2692010-11-24 10:11:14 +01002239 cm->reply_body_size ? nlp->packet_type : P_return_code_only;
Philipp Reisnerb411b362009-09-25 16:07:19 -07002240 reply->minor = nlp->drbd_minor;
2241 reply->ret_code = NO_ERROR; /* Might by modified by cm->function. */
2242 /* reply->tag_list; might be modified by cm->function. */
2243
2244 rr = cm->function(mdev, nlp, reply);
2245
2246 cn_reply->id = req->id;
2247 cn_reply->seq = req->seq;
2248 cn_reply->ack = req->ack + 1;
2249 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) + rr;
2250 cn_reply->flags = 0;
2251
Philipp Reisnerb411b362009-09-25 16:07:19 -07002252 rr = cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_KERNEL);
2253 if (rr && rr != -ESRCH)
2254 printk(KERN_INFO "drbd: cn_netlink_send()=%d\n", rr);
2255
2256 kfree(cn_reply);
2257 module_put(THIS_MODULE);
2258 return;
2259 fail:
2260 drbd_nl_send_reply(req, retcode);
2261 module_put(THIS_MODULE);
2262}
2263
2264static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
2265
2266static unsigned short *
2267__tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
2268 unsigned short len, int nul_terminated)
2269{
2270 unsigned short l = tag_descriptions[tag_number(tag)].max_len;
2271 len = (len < l) ? len : l;
2272 put_unaligned(tag, tl++);
2273 put_unaligned(len, tl++);
2274 memcpy(tl, data, len);
2275 tl = (unsigned short*)((char*)tl + len);
2276 if (nul_terminated)
2277 *((char*)tl - 1) = 0;
2278 return tl;
2279}
2280
2281static unsigned short *
2282tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data, int len)
2283{
2284 return __tl_add_blob(tl, tag, data, len, 0);
2285}
2286
2287static unsigned short *
2288tl_add_str(unsigned short *tl, enum drbd_tags tag, const char *str)
2289{
2290 return __tl_add_blob(tl, tag, str, strlen(str)+1, 0);
2291}
2292
2293static unsigned short *
2294tl_add_int(unsigned short *tl, enum drbd_tags tag, const void *val)
2295{
2296 put_unaligned(tag, tl++);
2297 switch(tag_type(tag)) {
2298 case TT_INTEGER:
2299 put_unaligned(sizeof(int), tl++);
2300 put_unaligned(*(int *)val, (int *)tl);
2301 tl = (unsigned short*)((char*)tl+sizeof(int));
2302 break;
2303 case TT_INT64:
2304 put_unaligned(sizeof(u64), tl++);
2305 put_unaligned(*(u64 *)val, (u64 *)tl);
2306 tl = (unsigned short*)((char*)tl+sizeof(u64));
2307 break;
2308 default:
2309 /* someone did something stupid. */
2310 ;
2311 }
2312 return tl;
2313}
2314
2315void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
2316{
2317 char buffer[sizeof(struct cn_msg)+
2318 sizeof(struct drbd_nl_cfg_reply)+
2319 sizeof(struct get_state_tag_len_struct)+
2320 sizeof(short int)];
2321 struct cn_msg *cn_reply = (struct cn_msg *) buffer;
2322 struct drbd_nl_cfg_reply *reply =
2323 (struct drbd_nl_cfg_reply *)cn_reply->data;
2324 unsigned short *tl = reply->tag_list;
2325
2326 /* dev_warn(DEV, "drbd_bcast_state() got called\n"); */
2327
2328 tl = get_state_to_tags(mdev, (struct get_state *)&state, tl);
2329
2330 put_unaligned(TT_END, tl++); /* Close the tag list */
2331
2332 cn_reply->id.idx = CN_IDX_DRBD;
2333 cn_reply->id.val = CN_VAL_DRBD;
2334
2335 cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
2336 cn_reply->ack = 0; /* not used here. */
2337 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
2338 (int)((char *)tl - (char *)reply->tag_list);
2339 cn_reply->flags = 0;
2340
2341 reply->packet_type = P_get_state;
2342 reply->minor = mdev_to_minor(mdev);
2343 reply->ret_code = NO_ERROR;
2344
Philipp Reisnerb411b362009-09-25 16:07:19 -07002345 cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_NOIO);
2346}
2347
2348void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
2349{
2350 char buffer[sizeof(struct cn_msg)+
2351 sizeof(struct drbd_nl_cfg_reply)+
2352 sizeof(struct call_helper_tag_len_struct)+
2353 sizeof(short int)];
2354 struct cn_msg *cn_reply = (struct cn_msg *) buffer;
2355 struct drbd_nl_cfg_reply *reply =
2356 (struct drbd_nl_cfg_reply *)cn_reply->data;
2357 unsigned short *tl = reply->tag_list;
2358
2359 /* dev_warn(DEV, "drbd_bcast_state() got called\n"); */
2360
2361 tl = tl_add_str(tl, T_helper, helper_name);
2362 put_unaligned(TT_END, tl++); /* Close the tag list */
2363
2364 cn_reply->id.idx = CN_IDX_DRBD;
2365 cn_reply->id.val = CN_VAL_DRBD;
2366
2367 cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
2368 cn_reply->ack = 0; /* not used here. */
2369 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
2370 (int)((char *)tl - (char *)reply->tag_list);
2371 cn_reply->flags = 0;
2372
2373 reply->packet_type = P_call_helper;
2374 reply->minor = mdev_to_minor(mdev);
2375 reply->ret_code = NO_ERROR;
2376
Philipp Reisnerb411b362009-09-25 16:07:19 -07002377 cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_NOIO);
2378}
2379
2380void drbd_bcast_ee(struct drbd_conf *mdev,
2381 const char *reason, const int dgs,
2382 const char* seen_hash, const char* calc_hash,
2383 const struct drbd_epoch_entry* e)
2384{
2385 struct cn_msg *cn_reply;
2386 struct drbd_nl_cfg_reply *reply;
Philipp Reisnerb411b362009-09-25 16:07:19 -07002387 unsigned short *tl;
Lars Ellenberg45bb9122010-05-14 17:10:48 +02002388 struct page *page;
2389 unsigned len;
Philipp Reisnerb411b362009-09-25 16:07:19 -07002390
2391 if (!e)
2392 return;
2393 if (!reason || !reason[0])
2394 return;
2395
2396 /* apparently we have to memcpy twice, first to prepare the data for the
2397 * struct cn_msg, then within cn_netlink_send from the cn_msg to the
2398 * netlink skb. */
2399 /* receiver thread context, which is not in the writeout path (of this node),
2400 * but may be in the writeout path of the _other_ node.
2401 * GFP_NOIO to avoid potential "distributed deadlock". */
Lars Ellenberg3e3a7762010-11-24 10:41:45 +01002402 cn_reply = kzalloc(
Philipp Reisnerb411b362009-09-25 16:07:19 -07002403 sizeof(struct cn_msg)+
2404 sizeof(struct drbd_nl_cfg_reply)+
2405 sizeof(struct dump_ee_tag_len_struct)+
2406 sizeof(short int),
2407 GFP_NOIO);
2408
2409 if (!cn_reply) {
2410 dev_err(DEV, "could not kmalloc buffer for drbd_bcast_ee, sector %llu, size %u\n",
2411 (unsigned long long)e->sector, e->size);
2412 return;
2413 }
2414
2415 reply = (struct drbd_nl_cfg_reply*)cn_reply->data;
2416 tl = reply->tag_list;
2417
2418 tl = tl_add_str(tl, T_dump_ee_reason, reason);
2419 tl = tl_add_blob(tl, T_seen_digest, seen_hash, dgs);
2420 tl = tl_add_blob(tl, T_calc_digest, calc_hash, dgs);
2421 tl = tl_add_int(tl, T_ee_sector, &e->sector);
2422 tl = tl_add_int(tl, T_ee_block_id, &e->block_id);
2423
Lars Ellenberg3129b1b2010-11-11 10:47:05 +01002424 /* dump the first 32k */
2425 len = min_t(unsigned, e->size, 32 << 10);
Philipp Reisnerb411b362009-09-25 16:07:19 -07002426 put_unaligned(T_ee_data, tl++);
Lars Ellenberg3129b1b2010-11-11 10:47:05 +01002427 put_unaligned(len, tl++);
Philipp Reisnerb411b362009-09-25 16:07:19 -07002428
Lars Ellenberg45bb9122010-05-14 17:10:48 +02002429 page = e->pages;
2430 page_chain_for_each(page) {
2431 void *d = kmap_atomic(page, KM_USER0);
2432 unsigned l = min_t(unsigned, len, PAGE_SIZE);
2433 memcpy(tl, d, l);
2434 kunmap_atomic(d, KM_USER0);
2435 tl = (unsigned short*)((char*)tl + l);
2436 len -= l;
Lars Ellenberg3129b1b2010-11-11 10:47:05 +01002437 if (len == 0)
2438 break;
Philipp Reisnerb411b362009-09-25 16:07:19 -07002439 }
2440 put_unaligned(TT_END, tl++); /* Close the tag list */
2441
2442 cn_reply->id.idx = CN_IDX_DRBD;
2443 cn_reply->id.val = CN_VAL_DRBD;
2444
2445 cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
2446 cn_reply->ack = 0; // not used here.
2447 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
2448 (int)((char*)tl - (char*)reply->tag_list);
2449 cn_reply->flags = 0;
2450
2451 reply->packet_type = P_dump_ee;
2452 reply->minor = mdev_to_minor(mdev);
2453 reply->ret_code = NO_ERROR;
2454
Philipp Reisnerb411b362009-09-25 16:07:19 -07002455 cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_NOIO);
2456 kfree(cn_reply);
2457}
2458
2459void drbd_bcast_sync_progress(struct drbd_conf *mdev)
2460{
2461 char buffer[sizeof(struct cn_msg)+
2462 sizeof(struct drbd_nl_cfg_reply)+
2463 sizeof(struct sync_progress_tag_len_struct)+
2464 sizeof(short int)];
2465 struct cn_msg *cn_reply = (struct cn_msg *) buffer;
2466 struct drbd_nl_cfg_reply *reply =
2467 (struct drbd_nl_cfg_reply *)cn_reply->data;
2468 unsigned short *tl = reply->tag_list;
2469 unsigned long rs_left;
2470 unsigned int res;
2471
2472 /* no local ref, no bitmap, no syncer progress, no broadcast. */
2473 if (!get_ldev(mdev))
2474 return;
2475 drbd_get_syncer_progress(mdev, &rs_left, &res);
2476 put_ldev(mdev);
2477
2478 tl = tl_add_int(tl, T_sync_progress, &res);
2479 put_unaligned(TT_END, tl++); /* Close the tag list */
2480
2481 cn_reply->id.idx = CN_IDX_DRBD;
2482 cn_reply->id.val = CN_VAL_DRBD;
2483
2484 cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
2485 cn_reply->ack = 0; /* not used here. */
2486 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
2487 (int)((char *)tl - (char *)reply->tag_list);
2488 cn_reply->flags = 0;
2489
2490 reply->packet_type = P_sync_progress;
2491 reply->minor = mdev_to_minor(mdev);
2492 reply->ret_code = NO_ERROR;
2493
Philipp Reisnerb411b362009-09-25 16:07:19 -07002494 cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_NOIO);
2495}
2496
2497int __init drbd_nl_init(void)
2498{
2499 static struct cb_id cn_id_drbd;
2500 int err, try=10;
2501
2502 cn_id_drbd.val = CN_VAL_DRBD;
2503 do {
2504 cn_id_drbd.idx = cn_idx;
2505 err = cn_add_callback(&cn_id_drbd, "cn_drbd", &drbd_connector_callback);
2506 if (!err)
2507 break;
2508 cn_idx = (cn_idx + CN_IDX_STEP);
2509 } while (try--);
2510
2511 if (err) {
2512 printk(KERN_ERR "drbd: cn_drbd failed to register\n");
2513 return err;
2514 }
2515
2516 return 0;
2517}
2518
2519void drbd_nl_cleanup(void)
2520{
2521 static struct cb_id cn_id_drbd;
2522
2523 cn_id_drbd.idx = cn_idx;
2524 cn_id_drbd.val = CN_VAL_DRBD;
2525
2526 cn_del_callback(&cn_id_drbd);
2527}
2528
2529void drbd_nl_send_reply(struct cn_msg *req, int ret_code)
2530{
2531 char buffer[sizeof(struct cn_msg)+sizeof(struct drbd_nl_cfg_reply)];
2532 struct cn_msg *cn_reply = (struct cn_msg *) buffer;
2533 struct drbd_nl_cfg_reply *reply =
2534 (struct drbd_nl_cfg_reply *)cn_reply->data;
2535 int rr;
2536
Lars Ellenberg3e3a7762010-11-24 10:41:45 +01002537 memset(buffer, 0, sizeof(buffer));
Philipp Reisnerb411b362009-09-25 16:07:19 -07002538 cn_reply->id = req->id;
2539
2540 cn_reply->seq = req->seq;
2541 cn_reply->ack = req->ack + 1;
2542 cn_reply->len = sizeof(struct drbd_nl_cfg_reply);
2543 cn_reply->flags = 0;
2544
Lars Ellenberg42ff2692010-11-24 10:11:14 +01002545 reply->packet_type = P_return_code_only;
Philipp Reisnerb411b362009-09-25 16:07:19 -07002546 reply->minor = ((struct drbd_nl_cfg_req *)req->data)->drbd_minor;
2547 reply->ret_code = ret_code;
2548
Philipp Reisnerb411b362009-09-25 16:07:19 -07002549 rr = cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_NOIO);
2550 if (rr && rr != -ESRCH)
2551 printk(KERN_INFO "drbd: cn_netlink_send()=%d\n", rr);
2552}
2553