Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1 | /* |
| 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 Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 26 | #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> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 32 | #include <linux/blkpg.h> |
| 33 | #include <linux/cpumask.h> |
| 34 | #include "drbd_int.h" |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 35 | #include "drbd_req.h" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 36 | #include "drbd_wrappers.h" |
| 37 | #include <asm/unaligned.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 38 | #include <linux/drbd_limits.h> |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 39 | #include <linux/kthread.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 40 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 41 | #include <net/genetlink.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 42 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 43 | /* .doit */ |
| 44 | // 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 | |
| 47 | int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info); |
| 48 | int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info); |
| 49 | |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 50 | 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); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 52 | int drbd_adm_down(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 53 | |
| 54 | int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info); |
| 55 | int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 56 | int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 57 | int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info); |
| 58 | int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 59 | int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 60 | int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info); |
| 61 | int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info); |
| 62 | int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info); |
| 63 | int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info); |
| 64 | int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info); |
| 65 | int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info); |
| 66 | int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info); |
| 67 | int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info); |
| 68 | int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info); |
| 69 | int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info); |
| 70 | int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 71 | int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 72 | int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info); |
| 73 | int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info); |
| 74 | /* .dumpit */ |
| 75 | int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb); |
| 76 | |
| 77 | #include <linux/drbd_genl_api.h> |
Andreas Gruenbacher | 01b39b5 | 2011-06-10 12:57:26 +0200 | [diff] [blame] | 78 | #include "drbd_nla.h" |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 79 | #include <linux/genl_magic_func.h> |
| 80 | |
| 81 | /* used blkdev_get_by_path, to claim our meta data device(s) */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 82 | static char *drbd_m_holder = "Hands off! this is DRBD's meta data device."; |
| 83 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 84 | /* Configuration is strictly serialized, because generic netlink message |
| 85 | * processing is strictly serialized by the genl_lock(). |
| 86 | * Which means we can use one static global drbd_config_context struct. |
| 87 | */ |
| 88 | static struct drbd_config_context { |
| 89 | /* assigned from drbd_genlmsghdr */ |
| 90 | unsigned int minor; |
| 91 | /* assigned from request attributes, if present */ |
| 92 | unsigned int volume; |
| 93 | #define VOLUME_UNSPECIFIED (-1U) |
| 94 | /* pointer into the request skb, |
| 95 | * limited lifetime! */ |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 96 | char *resource_name; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 97 | struct nlattr *my_addr; |
| 98 | struct nlattr *peer_addr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 99 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 100 | /* reply buffer */ |
| 101 | struct sk_buff *reply_skb; |
| 102 | /* pointer into reply buffer */ |
| 103 | struct drbd_genlmsghdr *reply_dh; |
| 104 | /* resolved from attributes, if possible */ |
| 105 | struct drbd_conf *mdev; |
| 106 | struct drbd_tconn *tconn; |
| 107 | } adm_ctx; |
| 108 | |
| 109 | static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info) |
| 110 | { |
| 111 | genlmsg_end(skb, genlmsg_data(nlmsg_data(nlmsg_hdr(skb)))); |
| 112 | if (genlmsg_reply(skb, info)) |
| 113 | printk(KERN_ERR "drbd: error sending genl reply\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 116 | /* Used on a fresh "drbd_adm_prepare"d reply_skb, this cannot fail: The only |
| 117 | * reason it could fail was no space in skb, and there are 4k available. */ |
Lars Ellenberg | 8432b31 | 2011-03-08 16:11:16 +0100 | [diff] [blame] | 118 | int drbd_msg_put_info(const char *info) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 119 | { |
| 120 | struct sk_buff *skb = adm_ctx.reply_skb; |
| 121 | struct nlattr *nla; |
| 122 | int err = -EMSGSIZE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 123 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 124 | if (!info || !info[0]) |
| 125 | return 0; |
| 126 | |
| 127 | nla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY); |
| 128 | if (!nla) |
| 129 | return err; |
| 130 | |
| 131 | err = nla_put_string(skb, T_info_text, info); |
| 132 | if (err) { |
| 133 | nla_nest_cancel(skb, nla); |
| 134 | return err; |
| 135 | } else |
| 136 | nla_nest_end(skb, nla); |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /* This would be a good candidate for a "pre_doit" hook, |
| 141 | * and per-family private info->pointers. |
| 142 | * But we need to stay compatible with older kernels. |
| 143 | * If it returns successfully, adm_ctx members are valid. |
| 144 | */ |
| 145 | #define DRBD_ADM_NEED_MINOR 1 |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 146 | #define DRBD_ADM_NEED_RESOURCE 2 |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 147 | #define DRBD_ADM_NEED_CONNECTION 4 |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 148 | static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info, |
| 149 | unsigned flags) |
| 150 | { |
| 151 | struct drbd_genlmsghdr *d_in = info->userhdr; |
| 152 | const u8 cmd = info->genlhdr->cmd; |
| 153 | int err; |
| 154 | |
| 155 | memset(&adm_ctx, 0, sizeof(adm_ctx)); |
| 156 | |
| 157 | /* genl_rcv_msg only checks for CAP_NET_ADMIN on "GENL_ADMIN_PERM" :( */ |
Philipp Reisner | 9868365 | 2012-11-09 14:18:43 +0100 | [diff] [blame] | 158 | if (cmd != DRBD_ADM_GET_STATUS && !capable(CAP_NET_ADMIN)) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 159 | return -EPERM; |
| 160 | |
| 161 | adm_ctx.reply_skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Andreas Gruenbacher | 1e2a255 | 2011-05-24 14:17:08 +0200 | [diff] [blame] | 162 | if (!adm_ctx.reply_skb) { |
| 163 | err = -ENOMEM; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 164 | goto fail; |
Andreas Gruenbacher | 1e2a255 | 2011-05-24 14:17:08 +0200 | [diff] [blame] | 165 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 166 | |
| 167 | adm_ctx.reply_dh = genlmsg_put_reply(adm_ctx.reply_skb, |
| 168 | info, &drbd_genl_family, 0, cmd); |
| 169 | /* put of a few bytes into a fresh skb of >= 4k will always succeed. |
| 170 | * but anyways */ |
Andreas Gruenbacher | 1e2a255 | 2011-05-24 14:17:08 +0200 | [diff] [blame] | 171 | if (!adm_ctx.reply_dh) { |
| 172 | err = -ENOMEM; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 173 | goto fail; |
Andreas Gruenbacher | 1e2a255 | 2011-05-24 14:17:08 +0200 | [diff] [blame] | 174 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 175 | |
| 176 | adm_ctx.reply_dh->minor = d_in->minor; |
| 177 | adm_ctx.reply_dh->ret_code = NO_ERROR; |
| 178 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 179 | adm_ctx.volume = VOLUME_UNSPECIFIED; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 180 | if (info->attrs[DRBD_NLA_CFG_CONTEXT]) { |
| 181 | struct nlattr *nla; |
| 182 | /* parse and validate only */ |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 183 | err = drbd_cfg_context_from_attrs(NULL, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 184 | if (err) |
| 185 | goto fail; |
| 186 | |
| 187 | /* It was present, and valid, |
| 188 | * copy it over to the reply skb. */ |
| 189 | err = nla_put_nohdr(adm_ctx.reply_skb, |
| 190 | info->attrs[DRBD_NLA_CFG_CONTEXT]->nla_len, |
| 191 | info->attrs[DRBD_NLA_CFG_CONTEXT]); |
| 192 | if (err) |
| 193 | goto fail; |
| 194 | |
| 195 | /* and assign stuff to the global adm_ctx */ |
| 196 | nla = nested_attr_tb[__nla_type(T_ctx_volume)]; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 197 | if (nla) |
| 198 | adm_ctx.volume = nla_get_u32(nla); |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 199 | nla = nested_attr_tb[__nla_type(T_ctx_resource_name)]; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 200 | if (nla) |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 201 | adm_ctx.resource_name = nla_data(nla); |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 202 | 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)]; |
| 204 | if ((adm_ctx.my_addr && |
| 205 | nla_len(adm_ctx.my_addr) > sizeof(adm_ctx.tconn->my_addr)) || |
| 206 | (adm_ctx.peer_addr && |
| 207 | nla_len(adm_ctx.peer_addr) > sizeof(adm_ctx.tconn->peer_addr))) { |
| 208 | err = -EINVAL; |
| 209 | goto fail; |
| 210 | } |
| 211 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 212 | |
| 213 | adm_ctx.minor = d_in->minor; |
| 214 | adm_ctx.mdev = minor_to_mdev(d_in->minor); |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 215 | adm_ctx.tconn = conn_get_by_name(adm_ctx.resource_name); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 216 | |
| 217 | if (!adm_ctx.mdev && (flags & DRBD_ADM_NEED_MINOR)) { |
| 218 | drbd_msg_put_info("unknown minor"); |
| 219 | return ERR_MINOR_INVALID; |
| 220 | } |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 221 | if (!adm_ctx.tconn && (flags & DRBD_ADM_NEED_RESOURCE)) { |
| 222 | drbd_msg_put_info("unknown resource"); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 223 | return ERR_INVALID_REQUEST; |
| 224 | } |
| 225 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 226 | if (flags & DRBD_ADM_NEED_CONNECTION) { |
| 227 | if (adm_ctx.tconn && !(flags & DRBD_ADM_NEED_RESOURCE)) { |
| 228 | drbd_msg_put_info("no resource name expected"); |
| 229 | return ERR_INVALID_REQUEST; |
| 230 | } |
| 231 | if (adm_ctx.mdev) { |
| 232 | drbd_msg_put_info("no minor number expected"); |
| 233 | return ERR_INVALID_REQUEST; |
| 234 | } |
| 235 | if (adm_ctx.my_addr && adm_ctx.peer_addr) |
| 236 | adm_ctx.tconn = conn_get_by_addrs(nla_data(adm_ctx.my_addr), |
| 237 | nla_len(adm_ctx.my_addr), |
| 238 | nla_data(adm_ctx.peer_addr), |
| 239 | nla_len(adm_ctx.peer_addr)); |
| 240 | if (!adm_ctx.tconn) { |
| 241 | drbd_msg_put_info("unknown connection"); |
| 242 | return ERR_INVALID_REQUEST; |
| 243 | } |
| 244 | } |
| 245 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 246 | /* some more paranoia, if the request was over-determined */ |
Lars Ellenberg | 527f4b2 | 2011-03-14 13:58:03 +0100 | [diff] [blame] | 247 | if (adm_ctx.mdev && adm_ctx.tconn && |
| 248 | adm_ctx.mdev->tconn != adm_ctx.tconn) { |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 249 | pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n", |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 250 | adm_ctx.minor, adm_ctx.resource_name, |
| 251 | adm_ctx.mdev->tconn->name); |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 252 | drbd_msg_put_info("minor exists in different resource"); |
Lars Ellenberg | 527f4b2 | 2011-03-14 13:58:03 +0100 | [diff] [blame] | 253 | return ERR_INVALID_REQUEST; |
| 254 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 255 | if (adm_ctx.mdev && |
| 256 | adm_ctx.volume != VOLUME_UNSPECIFIED && |
| 257 | adm_ctx.volume != adm_ctx.mdev->vnr) { |
| 258 | pr_warning("request: minor=%u, volume=%u; but that minor is volume %u in %s\n", |
| 259 | adm_ctx.minor, adm_ctx.volume, |
| 260 | adm_ctx.mdev->vnr, adm_ctx.mdev->tconn->name); |
Lars Ellenberg | 527f4b2 | 2011-03-14 13:58:03 +0100 | [diff] [blame] | 261 | drbd_msg_put_info("minor exists as different volume"); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 262 | return ERR_INVALID_REQUEST; |
| 263 | } |
Philipp Reisner | 0ace9df | 2011-04-24 10:53:19 +0200 | [diff] [blame] | 264 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 265 | return NO_ERROR; |
| 266 | |
| 267 | fail: |
| 268 | nlmsg_free(adm_ctx.reply_skb); |
| 269 | adm_ctx.reply_skb = NULL; |
Andreas Gruenbacher | 1e2a255 | 2011-05-24 14:17:08 +0200 | [diff] [blame] | 270 | return err; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static int drbd_adm_finish(struct genl_info *info, int retcode) |
| 274 | { |
Philipp Reisner | 0ace9df | 2011-04-24 10:53:19 +0200 | [diff] [blame] | 275 | if (adm_ctx.tconn) { |
| 276 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); |
| 277 | adm_ctx.tconn = NULL; |
| 278 | } |
| 279 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 280 | if (!adm_ctx.reply_skb) |
| 281 | return -ENOMEM; |
| 282 | |
| 283 | adm_ctx.reply_dh->ret_code = retcode; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 284 | drbd_adm_send_reply(adm_ctx.reply_skb, info); |
| 285 | return 0; |
| 286 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 287 | |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 288 | static void setup_khelper_env(struct drbd_tconn *tconn, char **envp) |
| 289 | { |
| 290 | char *afs; |
| 291 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 292 | /* FIXME: A future version will not allow this case. */ |
| 293 | if (tconn->my_addr_len == 0 || tconn->peer_addr_len == 0) |
| 294 | return; |
| 295 | |
| 296 | switch (((struct sockaddr *)&tconn->peer_addr)->sa_family) { |
| 297 | case AF_INET6: |
| 298 | afs = "ipv6"; |
| 299 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI6", |
| 300 | &((struct sockaddr_in6 *)&tconn->peer_addr)->sin6_addr); |
| 301 | break; |
| 302 | case AF_INET: |
| 303 | afs = "ipv4"; |
| 304 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", |
| 305 | &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr); |
| 306 | break; |
| 307 | default: |
| 308 | afs = "ssocks"; |
| 309 | snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4", |
| 310 | &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr); |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 311 | } |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 312 | snprintf(envp[3], 20, "DRBD_PEER_AF=%s", afs); |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 313 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 314 | |
| 315 | int drbd_khelper(struct drbd_conf *mdev, char *cmd) |
| 316 | { |
| 317 | char *envp[] = { "HOME=/", |
| 318 | "TERM=linux", |
| 319 | "PATH=/sbin:/usr/sbin:/bin:/usr/bin", |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 320 | (char[20]) { }, /* address family */ |
| 321 | (char[60]) { }, /* address */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 322 | NULL }; |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 323 | char mb[12]; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 324 | char *argv[] = {usermode_helper, cmd, mb, NULL }; |
Lars Ellenberg | 6f3465e | 2012-07-30 09:08:25 +0200 | [diff] [blame] | 325 | struct drbd_tconn *tconn = mdev->tconn; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 326 | struct sib_info sib; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 327 | int ret; |
| 328 | |
Lars Ellenberg | 6f3465e | 2012-07-30 09:08:25 +0200 | [diff] [blame] | 329 | if (current == tconn->worker.task) |
| 330 | set_bit(CALLBACK_PENDING, &tconn->flags); |
Lars Ellenberg | c2ba686 | 2012-06-14 15:14:06 +0200 | [diff] [blame] | 331 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 332 | snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev)); |
Lars Ellenberg | 6f3465e | 2012-07-30 09:08:25 +0200 | [diff] [blame] | 333 | setup_khelper_env(tconn, envp); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 334 | |
Lars Ellenberg | 1090c05 | 2010-07-19 17:41:04 +0200 | [diff] [blame] | 335 | /* The helper may take some time. |
| 336 | * write out any unsynced meta data changes now */ |
| 337 | drbd_md_sync(mdev); |
| 338 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 339 | dev_info(DEV, "helper command: %s %s %s\n", usermode_helper, cmd, mb); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 340 | sib.sib_reason = SIB_HELPER_PRE; |
| 341 | sib.helper_name = cmd; |
| 342 | drbd_bcast_event(mdev, &sib); |
Oleg Nesterov | 70834d3 | 2012-03-23 15:02:46 -0700 | [diff] [blame] | 343 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 344 | if (ret) |
| 345 | dev_warn(DEV, "helper command: %s %s %s exit code %u (0x%x)\n", |
| 346 | usermode_helper, cmd, mb, |
| 347 | (ret >> 8) & 0xff, ret); |
| 348 | else |
| 349 | dev_info(DEV, "helper command: %s %s %s exit code %u (0x%x)\n", |
| 350 | usermode_helper, cmd, mb, |
| 351 | (ret >> 8) & 0xff, ret); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 352 | sib.sib_reason = SIB_HELPER_POST; |
| 353 | sib.helper_exit_code = ret; |
| 354 | drbd_bcast_event(mdev, &sib); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 355 | |
Lars Ellenberg | 6f3465e | 2012-07-30 09:08:25 +0200 | [diff] [blame] | 356 | if (current == tconn->worker.task) |
| 357 | clear_bit(CALLBACK_PENDING, &tconn->flags); |
Lars Ellenberg | c2ba686 | 2012-06-14 15:14:06 +0200 | [diff] [blame] | 358 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 359 | if (ret < 0) /* Ignore any ERRNOs we got. */ |
| 360 | ret = 0; |
| 361 | |
| 362 | return ret; |
| 363 | } |
| 364 | |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 365 | int conn_khelper(struct drbd_tconn *tconn, char *cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 366 | { |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 367 | char *envp[] = { "HOME=/", |
| 368 | "TERM=linux", |
| 369 | "PATH=/sbin:/usr/sbin:/bin:/usr/bin", |
| 370 | (char[20]) { }, /* address family */ |
| 371 | (char[60]) { }, /* address */ |
| 372 | NULL }; |
| 373 | char *argv[] = {usermode_helper, cmd, tconn->name, NULL }; |
| 374 | int ret; |
| 375 | |
| 376 | setup_khelper_env(tconn, envp); |
| 377 | conn_md_sync(tconn); |
| 378 | |
| 379 | conn_info(tconn, "helper command: %s %s %s\n", usermode_helper, cmd, tconn->name); |
| 380 | /* TODO: conn_bcast_event() ?? */ |
| 381 | |
Philipp Reisner | 9868365 | 2012-11-09 14:18:43 +0100 | [diff] [blame] | 382 | ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC); |
Philipp Reisner | 6b75dce | 2011-03-16 17:39:12 +0100 | [diff] [blame] | 383 | if (ret) |
| 384 | conn_warn(tconn, "helper command: %s %s %s exit code %u (0x%x)\n", |
| 385 | usermode_helper, cmd, tconn->name, |
| 386 | (ret >> 8) & 0xff, ret); |
| 387 | else |
| 388 | conn_info(tconn, "helper command: %s %s %s exit code %u (0x%x)\n", |
| 389 | usermode_helper, cmd, tconn->name, |
| 390 | (ret >> 8) & 0xff, ret); |
| 391 | /* TODO: conn_bcast_event() ?? */ |
| 392 | |
| 393 | if (ret < 0) /* Ignore any ERRNOs we got. */ |
| 394 | ret = 0; |
| 395 | |
| 396 | return ret; |
| 397 | } |
| 398 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 399 | static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 400 | { |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 401 | enum drbd_fencing_p fp = FP_NOT_AVAIL; |
| 402 | struct drbd_conf *mdev; |
| 403 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 404 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 405 | rcu_read_lock(); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 406 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 407 | if (get_ldev_if_state(mdev, D_CONSISTENT)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 408 | fp = max_t(enum drbd_fencing_p, fp, |
| 409 | rcu_dereference(mdev->ldev->disk_conf)->fencing); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 410 | put_ldev(mdev); |
| 411 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 412 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 413 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 414 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 415 | return fp; |
| 416 | } |
| 417 | |
| 418 | bool conn_try_outdate_peer(struct drbd_tconn *tconn) |
| 419 | { |
Philipp Reisner | 28e448b | 2013-06-25 16:50:06 +0200 | [diff] [blame] | 420 | unsigned int connect_cnt; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 421 | union drbd_state mask = { }; |
| 422 | union drbd_state val = { }; |
| 423 | enum drbd_fencing_p fp; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 424 | char *ex_to_string; |
| 425 | int r; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 426 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 427 | if (tconn->cstate >= C_WF_REPORT_PARAMS) { |
| 428 | conn_err(tconn, "Expected cstate < C_WF_REPORT_PARAMS\n"); |
| 429 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Philipp Reisner | 28e448b | 2013-06-25 16:50:06 +0200 | [diff] [blame] | 432 | spin_lock_irq(&tconn->req_lock); |
| 433 | connect_cnt = tconn->connect_cnt; |
| 434 | spin_unlock_irq(&tconn->req_lock); |
| 435 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 436 | fp = highest_fencing_policy(tconn); |
| 437 | switch (fp) { |
| 438 | case FP_NOT_AVAIL: |
| 439 | conn_warn(tconn, "Not fencing peer, I'm not even Consistent myself.\n"); |
| 440 | goto out; |
| 441 | case FP_DONT_CARE: |
| 442 | return true; |
| 443 | default: ; |
| 444 | } |
| 445 | |
| 446 | r = conn_khelper(tconn, "fence-peer"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 447 | |
| 448 | switch ((r>>8) & 0xff) { |
| 449 | case 3: /* peer is inconsistent */ |
| 450 | ex_to_string = "peer is inconsistent or worse"; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 451 | mask.pdsk = D_MASK; |
| 452 | val.pdsk = D_INCONSISTENT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 453 | break; |
| 454 | case 4: /* peer got outdated, or was already outdated */ |
| 455 | ex_to_string = "peer was fenced"; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 456 | mask.pdsk = D_MASK; |
| 457 | val.pdsk = D_OUTDATED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 458 | break; |
| 459 | case 5: /* peer was down */ |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 460 | if (conn_highest_disk(tconn) == D_UP_TO_DATE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 461 | /* we will(have) create(d) a new UUID anyways... */ |
| 462 | ex_to_string = "peer is unreachable, assumed to be dead"; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 463 | mask.pdsk = D_MASK; |
| 464 | val.pdsk = D_OUTDATED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 465 | } else { |
| 466 | ex_to_string = "peer unreachable, doing nothing since disk != UpToDate"; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 467 | } |
| 468 | break; |
| 469 | case 6: /* Peer is primary, voluntarily outdate myself. |
| 470 | * This is useful when an unconnected R_SECONDARY is asked to |
| 471 | * become R_PRIMARY, but finds the other peer being active. */ |
| 472 | ex_to_string = "peer is active"; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 473 | conn_warn(tconn, "Peer is primary, outdating myself.\n"); |
| 474 | mask.disk = D_MASK; |
| 475 | val.disk = D_OUTDATED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 476 | break; |
| 477 | case 7: |
| 478 | if (fp != FP_STONITH) |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 479 | conn_err(tconn, "fence-peer() = 7 && fencing != Stonith !!!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 480 | ex_to_string = "peer was stonithed"; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 481 | mask.pdsk = D_MASK; |
| 482 | val.pdsk = D_OUTDATED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 483 | break; |
| 484 | default: |
| 485 | /* The script is broken ... */ |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 486 | conn_err(tconn, "fence-peer helper broken, returned %d\n", (r>>8)&0xff); |
| 487 | return false; /* Eventually leave IO frozen */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 490 | conn_info(tconn, "fence-peer helper returned %d (%s)\n", |
| 491 | (r>>8) & 0xff, ex_to_string); |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 492 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 493 | out: |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 494 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 495 | /* Not using |
| 496 | conn_request_state(tconn, mask, val, CS_VERBOSE); |
| 497 | here, because we might were able to re-establish the connection in the |
| 498 | meantime. */ |
| 499 | spin_lock_irq(&tconn->req_lock); |
Philipp Reisner | 28e448b | 2013-06-25 16:50:06 +0200 | [diff] [blame] | 500 | if (tconn->cstate < C_WF_REPORT_PARAMS && !test_bit(STATE_SENT, &tconn->flags)) { |
| 501 | if (tconn->connect_cnt != connect_cnt) |
| 502 | /* In case the connection was established and droped |
| 503 | while the fence-peer handler was running, ignore it */ |
| 504 | conn_info(tconn, "Ignoring fence-peer exit code\n"); |
| 505 | else |
| 506 | _conn_request_state(tconn, mask, val, CS_VERBOSE); |
| 507 | } |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 508 | spin_unlock_irq(&tconn->req_lock); |
| 509 | |
| 510 | return conn_highest_pdsk(tconn) <= D_OUTDATED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 513 | static int _try_outdate_peer_async(void *data) |
| 514 | { |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 515 | struct drbd_tconn *tconn = (struct drbd_tconn *)data; |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 516 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 517 | conn_try_outdate_peer(tconn); |
Philipp Reisner | 21423fa | 2011-05-17 14:19:41 +0200 | [diff] [blame] | 518 | |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 519 | kref_put(&tconn->kref, &conn_destroy); |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 523 | void conn_try_outdate_peer_async(struct drbd_tconn *tconn) |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 524 | { |
| 525 | struct task_struct *opa; |
| 526 | |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 527 | kref_get(&tconn->kref); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 528 | opa = kthread_run(_try_outdate_peer_async, tconn, "drbd_async_h"); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 529 | if (IS_ERR(opa)) { |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 530 | conn_err(tconn, "out of mem, failed to invoke fence-peer helper\n"); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 531 | kref_put(&tconn->kref, &conn_destroy); |
| 532 | } |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 533 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 534 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 535 | enum drbd_state_rv |
| 536 | drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 537 | { |
| 538 | const int max_tries = 4; |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 539 | enum drbd_state_rv rv = SS_UNKNOWN_ERROR; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 540 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 541 | int try = 0; |
| 542 | int forced = 0; |
| 543 | union drbd_state mask, val; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 544 | |
| 545 | if (new_role == R_PRIMARY) |
Philipp Reisner | 0625ac1 | 2011-02-07 14:49:19 +0100 | [diff] [blame] | 546 | request_ping(mdev->tconn); /* Detect a dead peer ASAP */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 547 | |
Philipp Reisner | 8410da8f0 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 548 | mutex_lock(mdev->state_mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 549 | |
| 550 | mask.i = 0; mask.role = R_MASK; |
| 551 | val.i = 0; val.role = new_role; |
| 552 | |
| 553 | while (try++ < max_tries) { |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 554 | rv = _drbd_request_state(mdev, mask, val, CS_WAIT_COMPLETE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 555 | |
| 556 | /* in case we first succeeded to outdate, |
| 557 | * but now suddenly could establish a connection */ |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 558 | if (rv == SS_CW_FAILED_BY_PEER && mask.pdsk != 0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 559 | val.pdsk = 0; |
| 560 | mask.pdsk = 0; |
| 561 | continue; |
| 562 | } |
| 563 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 564 | if (rv == SS_NO_UP_TO_DATE_DISK && force && |
Philipp Reisner | d10a33c | 2010-03-04 15:11:39 +0100 | [diff] [blame] | 565 | (mdev->state.disk < D_UP_TO_DATE && |
| 566 | mdev->state.disk >= D_INCONSISTENT)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 567 | mask.disk = D_MASK; |
| 568 | val.disk = D_UP_TO_DATE; |
| 569 | forced = 1; |
| 570 | continue; |
| 571 | } |
| 572 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 573 | if (rv == SS_NO_UP_TO_DATE_DISK && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 574 | mdev->state.disk == D_CONSISTENT && mask.pdsk == 0) { |
| 575 | D_ASSERT(mdev->state.pdsk == D_UNKNOWN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 576 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 577 | if (conn_try_outdate_peer(mdev->tconn)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 578 | val.disk = D_UP_TO_DATE; |
| 579 | mask.disk = D_MASK; |
| 580 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 581 | continue; |
| 582 | } |
| 583 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 584 | if (rv == SS_NOTHING_TO_DO) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 585 | goto out; |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 586 | if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) { |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 587 | if (!conn_try_outdate_peer(mdev->tconn) && force) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 588 | dev_warn(DEV, "Forced into split brain situation!\n"); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 589 | mask.pdsk = D_MASK; |
| 590 | val.pdsk = D_OUTDATED; |
| 591 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 592 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 593 | continue; |
| 594 | } |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 595 | if (rv == SS_TWO_PRIMARIES) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 596 | /* Maybe the peer is detected as dead very soon... |
| 597 | retry at most once more in this case. */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 598 | int timeo; |
| 599 | rcu_read_lock(); |
| 600 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 601 | timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1; |
| 602 | rcu_read_unlock(); |
| 603 | schedule_timeout_interruptible(timeo); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 604 | if (try < max_tries) |
| 605 | try = max_tries - 1; |
| 606 | continue; |
| 607 | } |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 608 | if (rv < SS_SUCCESS) { |
| 609 | rv = _drbd_request_state(mdev, mask, val, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 610 | CS_VERBOSE + CS_WAIT_COMPLETE); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 611 | if (rv < SS_SUCCESS) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 612 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 613 | } |
| 614 | break; |
| 615 | } |
| 616 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 617 | if (rv < SS_SUCCESS) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 618 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 619 | |
| 620 | if (forced) |
| 621 | dev_warn(DEV, "Forced to consider local data as UpToDate!\n"); |
| 622 | |
| 623 | /* Wait until nothing is on the fly :) */ |
| 624 | wait_event(mdev->misc_wait, atomic_read(&mdev->ap_pending_cnt) == 0); |
| 625 | |
Lars Ellenberg | b6dd1a8 | 2011-11-28 15:04:49 +0100 | [diff] [blame] | 626 | /* FIXME also wait for all pending P_BARRIER_ACK? */ |
| 627 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 628 | if (new_role == R_SECONDARY) { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 629 | set_disk_ro(mdev->vdisk, true); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 630 | if (get_ldev(mdev)) { |
| 631 | mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; |
| 632 | put_ldev(mdev); |
| 633 | } |
| 634 | } else { |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 635 | mutex_lock(&mdev->tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 636 | nc = mdev->tconn->net_conf; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 637 | if (nc) |
Andreas Gruenbacher | 6139f60 | 2011-05-06 20:00:02 +0200 | [diff] [blame] | 638 | nc->discard_my_data = 0; /* without copy; single bit op is atomic */ |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 639 | mutex_unlock(&mdev->tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 640 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 641 | set_disk_ro(mdev->vdisk, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 642 | if (get_ldev(mdev)) { |
| 643 | if (((mdev->state.conn < C_CONNECTED || |
| 644 | mdev->state.pdsk <= D_FAILED) |
| 645 | && mdev->ldev->md.uuid[UI_BITMAP] == 0) || forced) |
| 646 | drbd_uuid_new_current(mdev); |
| 647 | |
| 648 | mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1; |
| 649 | put_ldev(mdev); |
| 650 | } |
| 651 | } |
| 652 | |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 653 | /* writeout of activity log covered areas of the bitmap |
| 654 | * to stable storage done in after state change already */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 655 | |
| 656 | if (mdev->state.conn >= C_WF_REPORT_PARAMS) { |
| 657 | /* if this was forced, we should consider sync */ |
| 658 | if (forced) |
| 659 | drbd_send_uuids(mdev); |
Lars Ellenberg | f479ea0 | 2011-10-27 16:52:30 +0200 | [diff] [blame] | 660 | drbd_send_current_state(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | drbd_md_sync(mdev); |
| 664 | |
| 665 | kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 666 | out: |
Philipp Reisner | 8410da8f0 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 667 | mutex_unlock(mdev->state_mutex); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 668 | return rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 671 | static const char *from_attrs_err_to_txt(int err) |
Lars Ellenberg | ef50a3e | 2010-09-01 14:39:30 +0200 | [diff] [blame] | 672 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 673 | return err == -ENOMSG ? "required attribute missing" : |
| 674 | err == -EOPNOTSUPP ? "unknown mandatory attribute" : |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 675 | err == -EEXIST ? "can not change invariant setting" : |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 676 | "invalid attribute value"; |
Lars Ellenberg | ef50a3e | 2010-09-01 14:39:30 +0200 | [diff] [blame] | 677 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 678 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 679 | int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 680 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 681 | struct set_role_parms parms; |
| 682 | int err; |
| 683 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 684 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 685 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 686 | if (!adm_ctx.reply_skb) |
| 687 | return retcode; |
| 688 | if (retcode != NO_ERROR) |
| 689 | goto out; |
| 690 | |
| 691 | memset(&parms, 0, sizeof(parms)); |
| 692 | if (info->attrs[DRBD_NLA_SET_ROLE_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 693 | err = set_role_parms_from_attrs(&parms, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 694 | if (err) { |
| 695 | retcode = ERR_MANDATORY_TAG; |
| 696 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 697 | goto out; |
| 698 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 701 | if (info->genlhdr->cmd == DRBD_ADM_PRIMARY) |
| 702 | retcode = drbd_set_role(adm_ctx.mdev, R_PRIMARY, parms.assume_uptodate); |
| 703 | else |
| 704 | retcode = drbd_set_role(adm_ctx.mdev, R_SECONDARY, 0); |
| 705 | out: |
| 706 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 710 | /* Initializes the md.*_offset members, so we are able to find |
| 711 | * the on disk meta data. |
| 712 | * |
| 713 | * We currently have two possible layouts: |
| 714 | * external: |
| 715 | * |----------- md_size_sect ------------------| |
| 716 | * [ 4k superblock ][ activity log ][ Bitmap ] |
| 717 | * | al_offset == 8 | |
| 718 | * | bm_offset = al_offset + X | |
| 719 | * ==> bitmap sectors = md_size_sect - bm_offset |
| 720 | * |
| 721 | * internal: |
| 722 | * |----------- md_size_sect ------------------| |
| 723 | * [data.....][ Bitmap ][ activity log ][ 4k superblock ] |
| 724 | * | al_offset < 0 | |
| 725 | * | bm_offset = al_offset - Y | |
| 726 | * ==> bitmap sectors = Y = al_offset - bm_offset |
| 727 | * |
| 728 | * Activity log size used to be fixed 32kB, |
| 729 | * but is about to become configurable. |
| 730 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 731 | static void drbd_md_set_sector_offsets(struct drbd_conf *mdev, |
| 732 | struct drbd_backing_dev *bdev) |
| 733 | { |
| 734 | sector_t md_size_sect = 0; |
Lars Ellenberg | c04ccaa | 2013-03-19 18:16:47 +0100 | [diff] [blame] | 735 | unsigned int al_size_sect = bdev->md.al_size_4k * 8; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 736 | |
Lars Ellenberg | 3a4d4eb | 2013-03-19 18:16:44 +0100 | [diff] [blame] | 737 | bdev->md.md_offset = drbd_md_ss(bdev); |
| 738 | |
Lars Ellenberg | 68e41a4 | 2013-03-19 18:16:45 +0100 | [diff] [blame] | 739 | switch (bdev->md.meta_dev_idx) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 740 | default: |
| 741 | /* v07 style fixed size indexed meta data */ |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 742 | bdev->md.md_size_sect = MD_128MB_SECT; |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 743 | bdev->md.al_offset = MD_4kB_SECT; |
| 744 | bdev->md.bm_offset = MD_4kB_SECT + al_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 745 | break; |
| 746 | case DRBD_MD_INDEX_FLEX_EXT: |
| 747 | /* just occupy the full device; unit: sectors */ |
| 748 | bdev->md.md_size_sect = drbd_get_capacity(bdev->md_bdev); |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 749 | bdev->md.al_offset = MD_4kB_SECT; |
| 750 | bdev->md.bm_offset = MD_4kB_SECT + al_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 751 | break; |
| 752 | case DRBD_MD_INDEX_INTERNAL: |
| 753 | case DRBD_MD_INDEX_FLEX_INT: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 754 | /* al size is still fixed */ |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 755 | bdev->md.al_offset = -al_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 756 | /* we need (slightly less than) ~ this much bitmap sectors: */ |
| 757 | md_size_sect = drbd_get_capacity(bdev->backing_bdev); |
| 758 | md_size_sect = ALIGN(md_size_sect, BM_SECT_PER_EXT); |
| 759 | md_size_sect = BM_SECT_TO_EXT(md_size_sect); |
| 760 | md_size_sect = ALIGN(md_size_sect, 8); |
| 761 | |
| 762 | /* plus the "drbd meta data super block", |
| 763 | * and the activity log; */ |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 764 | md_size_sect += MD_4kB_SECT + al_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 765 | |
| 766 | bdev->md.md_size_sect = md_size_sect; |
| 767 | /* bitmap offset is adjusted by 'super' block size */ |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 768 | bdev->md.bm_offset = -md_size_sect + MD_4kB_SECT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | } |
| 772 | |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 773 | /* input size is expected to be in KB */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 774 | char *ppsize(char *buf, unsigned long long size) |
| 775 | { |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 776 | /* Needs 9 bytes at max including trailing NUL: |
| 777 | * -1ULL ==> "16384 EB" */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 778 | static char units[] = { 'K', 'M', 'G', 'T', 'P', 'E' }; |
| 779 | int base = 0; |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 780 | while (size >= 10000 && base < sizeof(units)-1) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 781 | /* shift + round */ |
| 782 | size = (size >> 10) + !!(size & (1<<9)); |
| 783 | base++; |
| 784 | } |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 785 | sprintf(buf, "%u %cB", (unsigned)size, units[base]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 786 | |
| 787 | return buf; |
| 788 | } |
| 789 | |
| 790 | /* there is still a theoretical deadlock when called from receiver |
| 791 | * on an D_INCONSISTENT R_PRIMARY: |
| 792 | * remote READ does inc_ap_bio, receiver would need to receive answer |
| 793 | * packet from remote to dec_ap_bio again. |
| 794 | * receiver receive_sizes(), comes here, |
| 795 | * waits for ap_bio_cnt == 0. -> deadlock. |
| 796 | * but this cannot happen, actually, because: |
| 797 | * R_PRIMARY D_INCONSISTENT, and peer's disk is unreachable |
| 798 | * (not connected, or bad/no disk on peer): |
| 799 | * see drbd_fail_request_early, ap_bio_cnt is zero. |
| 800 | * R_PRIMARY D_INCONSISTENT, and C_SYNC_TARGET: |
| 801 | * peer may not initiate a resize. |
| 802 | */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 803 | /* Note these are not to be confused with |
| 804 | * drbd_adm_suspend_io/drbd_adm_resume_io, |
| 805 | * which are (sub) state changes triggered by admin (drbdsetup), |
| 806 | * and can be long lived. |
| 807 | * This changes an mdev->flag, is triggered by drbd internals, |
| 808 | * and should be short-lived. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 809 | void drbd_suspend_io(struct drbd_conf *mdev) |
| 810 | { |
| 811 | set_bit(SUSPEND_IO, &mdev->flags); |
Philipp Reisner | 2aebfab | 2011-03-28 16:48:11 +0200 | [diff] [blame] | 812 | if (drbd_suspended(mdev)) |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 813 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 814 | wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_bio_cnt)); |
| 815 | } |
| 816 | |
| 817 | void drbd_resume_io(struct drbd_conf *mdev) |
| 818 | { |
| 819 | clear_bit(SUSPEND_IO, &mdev->flags); |
| 820 | wake_up(&mdev->misc_wait); |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * drbd_determine_dev_size() - Sets the right device size obeying all constraints |
| 825 | * @mdev: DRBD device. |
| 826 | * |
| 827 | * Returns 0 on success, negative return values indicate errors. |
| 828 | * You should call drbd_md_sync() after calling this function. |
| 829 | */ |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 830 | enum determine_dev_size |
| 831 | drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags, struct resize_parms *rs) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 832 | { |
| 833 | sector_t prev_first_sect, prev_size; /* previous meta location */ |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 834 | sector_t la_size_sect, u_size; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 835 | struct drbd_md *md = &mdev->ldev->md; |
| 836 | u32 prev_al_stripe_size_4k; |
| 837 | u32 prev_al_stripes; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 838 | sector_t size; |
| 839 | char ppb[10]; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 840 | void *buffer; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 841 | |
| 842 | int md_moved, la_size_changed; |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 843 | enum determine_dev_size rv = DS_UNCHANGED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 844 | |
| 845 | /* race: |
| 846 | * application request passes inc_ap_bio, |
| 847 | * but then cannot get an AL-reference. |
| 848 | * this function later may wait on ap_bio_cnt == 0. -> deadlock. |
| 849 | * |
| 850 | * to avoid that: |
| 851 | * Suspend IO right here. |
| 852 | * still lock the act_log to not trigger ASSERTs there. |
| 853 | */ |
| 854 | drbd_suspend_io(mdev); |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 855 | buffer = drbd_md_get_buffer(mdev); /* Lock meta-data IO */ |
| 856 | if (!buffer) { |
| 857 | drbd_resume_io(mdev); |
| 858 | return DS_ERROR; |
| 859 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 860 | |
| 861 | /* no wait necessary anymore, actually we could assert that */ |
| 862 | wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); |
| 863 | |
| 864 | prev_first_sect = drbd_md_first_sector(mdev->ldev); |
| 865 | prev_size = mdev->ldev->md.md_size_sect; |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 866 | la_size_sect = mdev->ldev->md.la_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 867 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 868 | if (rs) { |
| 869 | /* rs is non NULL if we should change the AL layout only */ |
| 870 | |
| 871 | prev_al_stripes = md->al_stripes; |
| 872 | prev_al_stripe_size_4k = md->al_stripe_size_4k; |
| 873 | |
| 874 | md->al_stripes = rs->al_stripes; |
| 875 | md->al_stripe_size_4k = rs->al_stripe_size / 4; |
| 876 | md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4; |
| 877 | } |
| 878 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 879 | drbd_md_set_sector_offsets(mdev, mdev->ldev); |
| 880 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 881 | rcu_read_lock(); |
| 882 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; |
| 883 | rcu_read_unlock(); |
Philipp Reisner | ef5e44a | 2011-05-03 13:27:43 +0200 | [diff] [blame] | 884 | size = drbd_new_dev_size(mdev, mdev->ldev, u_size, flags & DDSF_FORCED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 885 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 886 | if (size < la_size_sect) { |
| 887 | if (rs && u_size == 0) { |
| 888 | /* Remove "rs &&" later. This check should always be active, but |
| 889 | right now the receiver expects the permissive behavior */ |
| 890 | dev_warn(DEV, "Implicit shrink not allowed. " |
| 891 | "Use --size=%llus for explicit shrink.\n", |
| 892 | (unsigned long long)size); |
| 893 | rv = DS_ERROR_SHRINK; |
| 894 | } |
| 895 | if (u_size > size) |
| 896 | rv = DS_ERROR_SPACE_MD; |
| 897 | if (rv != DS_UNCHANGED) |
| 898 | goto err_out; |
| 899 | } |
| 900 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 901 | if (drbd_get_capacity(mdev->this_bdev) != size || |
| 902 | drbd_bm_capacity(mdev) != size) { |
| 903 | int err; |
Philipp Reisner | 02d9a94 | 2010-03-24 16:23:03 +0100 | [diff] [blame] | 904 | err = drbd_bm_resize(mdev, size, !(flags & DDSF_NO_RESYNC)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 905 | if (unlikely(err)) { |
| 906 | /* currently there is only one error: ENOMEM! */ |
| 907 | size = drbd_bm_capacity(mdev)>>1; |
| 908 | if (size == 0) { |
| 909 | dev_err(DEV, "OUT OF MEMORY! " |
| 910 | "Could not allocate bitmap!\n"); |
| 911 | } else { |
| 912 | dev_err(DEV, "BM resizing failed. " |
| 913 | "Leaving size unchanged at size = %lu KB\n", |
| 914 | (unsigned long)size); |
| 915 | } |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 916 | rv = DS_ERROR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 917 | } |
| 918 | /* racy, see comments above. */ |
| 919 | drbd_set_my_capacity(mdev, size); |
| 920 | mdev->ldev->md.la_size_sect = size; |
| 921 | dev_info(DEV, "size = %s (%llu KB)\n", ppsize(ppb, size>>1), |
| 922 | (unsigned long long)size>>1); |
| 923 | } |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 924 | if (rv <= DS_ERROR) |
| 925 | goto err_out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 926 | |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 927 | la_size_changed = (la_size_sect != mdev->ldev->md.la_size_sect); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 928 | |
| 929 | md_moved = prev_first_sect != drbd_md_first_sector(mdev->ldev) |
| 930 | || prev_size != mdev->ldev->md.md_size_sect; |
| 931 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 932 | if (la_size_changed || md_moved || rs) { |
| 933 | u32 prev_flags; |
Andreas Gruenbacher | 24dccab | 2010-12-12 17:45:41 +0100 | [diff] [blame] | 934 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 935 | drbd_al_shrink(mdev); /* All extents inactive. */ |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 936 | |
| 937 | prev_flags = md->flags; |
| 938 | md->flags &= ~MDF_PRIMARY_IND; |
| 939 | drbd_md_write(mdev, buffer); |
| 940 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 941 | dev_info(DEV, "Writing the whole bitmap, %s\n", |
| 942 | la_size_changed && md_moved ? "size changed and md moved" : |
| 943 | la_size_changed ? "size changed" : "md moved"); |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 944 | /* next line implicitly does drbd_suspend_io()+drbd_resume_io() */ |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 945 | drbd_bitmap_io(mdev, md_moved ? &drbd_bm_write_all : &drbd_bm_write, |
| 946 | "size changed", BM_LOCKED_MASK); |
| 947 | drbd_initialize_al(mdev, buffer); |
| 948 | |
| 949 | md->flags = prev_flags; |
| 950 | drbd_md_write(mdev, buffer); |
| 951 | |
| 952 | if (rs) |
| 953 | dev_info(DEV, "Changed AL layout to al-stripes = %d, al-stripe-size-kB = %d\n", |
| 954 | md->al_stripes, md->al_stripe_size_4k * 4); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 957 | if (size > la_size_sect) |
Philipp Reisner | 57737ad | 2013-10-23 10:59:17 +0200 | [diff] [blame] | 958 | rv = la_size_sect ? DS_GREW : DS_GREW_FROM_ZERO; |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 959 | if (size < la_size_sect) |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 960 | rv = DS_SHRUNK; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 961 | |
| 962 | if (0) { |
| 963 | err_out: |
| 964 | if (rs) { |
| 965 | md->al_stripes = prev_al_stripes; |
| 966 | md->al_stripe_size_4k = prev_al_stripe_size_4k; |
| 967 | md->al_size_4k = (u64)prev_al_stripes * prev_al_stripe_size_4k; |
| 968 | |
| 969 | drbd_md_set_sector_offsets(mdev, mdev->ldev); |
| 970 | } |
| 971 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 972 | lc_unlock(mdev->act_log); |
| 973 | wake_up(&mdev->al_wait); |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 974 | drbd_md_put_buffer(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 975 | drbd_resume_io(mdev); |
| 976 | |
| 977 | return rv; |
| 978 | } |
| 979 | |
| 980 | sector_t |
Philipp Reisner | ef5e44a | 2011-05-03 13:27:43 +0200 | [diff] [blame] | 981 | drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev, |
| 982 | sector_t u_size, int assume_peer_has_space) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 983 | { |
| 984 | sector_t p_size = mdev->p_size; /* partner's disk size. */ |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 985 | sector_t la_size_sect = bdev->md.la_size_sect; /* last agreed size. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 986 | sector_t m_size; /* my size */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 987 | sector_t size = 0; |
| 988 | |
| 989 | m_size = drbd_get_max_capacity(bdev); |
| 990 | |
Philipp Reisner | a393db6 | 2009-12-22 13:35:52 +0100 | [diff] [blame] | 991 | if (mdev->state.conn < C_CONNECTED && assume_peer_has_space) { |
| 992 | dev_warn(DEV, "Resize while not connected was forced by the user!\n"); |
| 993 | p_size = m_size; |
| 994 | } |
| 995 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 996 | if (p_size && m_size) { |
| 997 | size = min_t(sector_t, p_size, m_size); |
| 998 | } else { |
Lars Ellenberg | cccac98 | 2013-03-19 18:16:46 +0100 | [diff] [blame] | 999 | if (la_size_sect) { |
| 1000 | size = la_size_sect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1001 | if (m_size && m_size < size) |
| 1002 | size = m_size; |
| 1003 | if (p_size && p_size < size) |
| 1004 | size = p_size; |
| 1005 | } else { |
| 1006 | if (m_size) |
| 1007 | size = m_size; |
| 1008 | if (p_size) |
| 1009 | size = p_size; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if (size == 0) |
| 1014 | dev_err(DEV, "Both nodes diskless!\n"); |
| 1015 | |
| 1016 | if (u_size) { |
| 1017 | if (u_size > size) |
| 1018 | dev_err(DEV, "Requested disk size is too big (%lu > %lu)\n", |
| 1019 | (unsigned long)u_size>>1, (unsigned long)size>>1); |
| 1020 | else |
| 1021 | size = u_size; |
| 1022 | } |
| 1023 | |
| 1024 | return size; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
| 1028 | * drbd_check_al_size() - Ensures that the AL is of the right size |
| 1029 | * @mdev: DRBD device. |
| 1030 | * |
| 1031 | * 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 |
| 1033 | * this function. |
| 1034 | */ |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1035 | static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1036 | { |
| 1037 | struct lru_cache *n, *t; |
| 1038 | struct lc_element *e; |
| 1039 | unsigned int in_use; |
| 1040 | int i; |
| 1041 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1042 | if (mdev->act_log && |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1043 | mdev->act_log->nr_elements == dc->al_extents) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1044 | return 0; |
| 1045 | |
| 1046 | in_use = 0; |
| 1047 | t = mdev->act_log; |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 1048 | n = lc_create("act_log", drbd_al_ext_cache, AL_UPDATES_PER_TRANSACTION, |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1049 | dc->al_extents, sizeof(struct lc_element), 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1050 | |
| 1051 | if (n == NULL) { |
| 1052 | dev_err(DEV, "Cannot allocate act_log lru!\n"); |
| 1053 | return -ENOMEM; |
| 1054 | } |
| 1055 | spin_lock_irq(&mdev->al_lock); |
| 1056 | if (t) { |
| 1057 | for (i = 0; i < t->nr_elements; i++) { |
| 1058 | e = lc_element_by_index(t, i); |
| 1059 | if (e->refcnt) |
| 1060 | dev_err(DEV, "refcnt(%d)==%d\n", |
| 1061 | e->lc_number, e->refcnt); |
| 1062 | in_use += e->refcnt; |
| 1063 | } |
| 1064 | } |
| 1065 | if (!in_use) |
| 1066 | mdev->act_log = n; |
| 1067 | spin_unlock_irq(&mdev->al_lock); |
| 1068 | if (in_use) { |
| 1069 | dev_err(DEV, "Activity log still in use!\n"); |
| 1070 | lc_destroy(n); |
| 1071 | return -EBUSY; |
| 1072 | } else { |
| 1073 | if (t) |
| 1074 | lc_destroy(t); |
| 1075 | } |
| 1076 | drbd_md_mark_dirty(mdev); /* we changed mdev->act_log->nr_elemens */ |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1080 | static void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int max_bio_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1081 | { |
| 1082 | struct request_queue * const q = mdev->rq_queue; |
Lars Ellenberg | db141b2 | 2012-06-25 19:15:58 +0200 | [diff] [blame] | 1083 | unsigned int max_hw_sectors = max_bio_size >> 9; |
| 1084 | unsigned int max_segments = 0; |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1085 | |
| 1086 | if (get_ldev_if_state(mdev, D_ATTACHING)) { |
| 1087 | struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue; |
| 1088 | |
| 1089 | max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1090 | rcu_read_lock(); |
| 1091 | max_segments = rcu_dereference(mdev->ldev->disk_conf)->max_bio_bvecs; |
| 1092 | rcu_read_unlock(); |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1093 | put_ldev(mdev); |
| 1094 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1095 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1096 | blk_queue_logical_block_size(q, 512); |
Lars Ellenberg | 1816a2b | 2010-11-11 15:19:07 +0100 | [diff] [blame] | 1097 | blk_queue_max_hw_sectors(q, max_hw_sectors); |
| 1098 | /* This is the workaround for "bio would need to, but cannot, be split" */ |
| 1099 | blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS); |
| 1100 | blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1101 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1102 | if (get_ldev_if_state(mdev, D_ATTACHING)) { |
| 1103 | struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1104 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1105 | blk_queue_stack_limits(q, b); |
| 1106 | |
| 1107 | 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", |
| 1109 | q->backing_dev_info.ra_pages, |
| 1110 | b->backing_dev_info.ra_pages); |
| 1111 | q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages; |
| 1112 | } |
| 1113 | put_ldev(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1117 | void drbd_reconsider_max_bio_size(struct drbd_conf *mdev) |
| 1118 | { |
Lars Ellenberg | db141b2 | 2012-06-25 19:15:58 +0200 | [diff] [blame] | 1119 | unsigned int now, new, local, peer; |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1120 | |
| 1121 | now = queue_max_hw_sectors(mdev->rq_queue) << 9; |
| 1122 | local = mdev->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 */ |
| 1124 | |
| 1125 | if (get_ldev_if_state(mdev, D_ATTACHING)) { |
| 1126 | local = queue_max_hw_sectors(mdev->ldev->backing_bdev->bd_disk->queue) << 9; |
| 1127 | mdev->local_max_bio_size = local; |
| 1128 | put_ldev(mdev); |
| 1129 | } |
Lars Ellenberg | db141b2 | 2012-06-25 19:15:58 +0200 | [diff] [blame] | 1130 | local = min(local, DRBD_MAX_BIO_SIZE); |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1131 | |
| 1132 | /* We may ignore peer limits if the peer is modern enough. |
| 1133 | Because new from 8.3.8 onwards the peer can use multiple |
| 1134 | BIOs for a single peer_request */ |
Lars Ellenberg | 35f47ef | 2013-10-23 10:59:19 +0200 | [diff] [blame] | 1135 | if (mdev->state.conn >= C_WF_REPORT_PARAMS) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 1136 | if (mdev->tconn->agreed_pro_version < 94) |
Lars Ellenberg | 35f47ef | 2013-10-23 10:59:19 +0200 | [diff] [blame] | 1137 | peer = min(mdev->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET); |
Philipp Reisner | 6809384 | 2011-06-30 15:43:06 +0200 | [diff] [blame] | 1138 | /* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */ |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 1139 | else if (mdev->tconn->agreed_pro_version == 94) |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1140 | peer = DRBD_MAX_SIZE_H80_PACKET; |
Philipp Reisner | 2ffca4f | 2011-06-30 15:43:06 +0200 | [diff] [blame] | 1141 | else if (mdev->tconn->agreed_pro_version < 100) |
| 1142 | peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */ |
| 1143 | else |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1144 | peer = DRBD_MAX_BIO_SIZE; |
| 1145 | } |
| 1146 | |
Lars Ellenberg | db141b2 | 2012-06-25 19:15:58 +0200 | [diff] [blame] | 1147 | new = min(local, peer); |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1148 | |
| 1149 | if (mdev->state.role == R_PRIMARY && new < now) |
Lars Ellenberg | db141b2 | 2012-06-25 19:15:58 +0200 | [diff] [blame] | 1150 | dev_err(DEV, "ASSERT FAILED new < now; (%u < %u)\n", new, now); |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1151 | |
| 1152 | if (new != now) |
| 1153 | dev_info(DEV, "max BIO size = %u\n", new); |
| 1154 | |
| 1155 | drbd_setup_queue_param(mdev, new); |
| 1156 | } |
| 1157 | |
Philipp Reisner | a18e9d1 | 2011-04-24 11:09:55 +0200 | [diff] [blame] | 1158 | /* Starts the worker thread */ |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1159 | static void conn_reconfig_start(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1160 | { |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1161 | drbd_thread_start(&tconn->worker); |
| 1162 | conn_flush_workqueue(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Philipp Reisner | a18e9d1 | 2011-04-24 11:09:55 +0200 | [diff] [blame] | 1165 | /* if still unconfigured, stops worker again. */ |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1166 | static void conn_reconfig_done(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1167 | { |
Lars Ellenberg | 992d6e9 | 2011-05-02 11:47:18 +0200 | [diff] [blame] | 1168 | bool stop_threads; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1169 | spin_lock_irq(&tconn->req_lock); |
Philipp Reisner | e0e1665 | 2011-07-11 17:04:23 +0200 | [diff] [blame] | 1170 | stop_threads = conn_all_vols_unconf(tconn) && |
| 1171 | tconn->cstate == C_STANDALONE; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1172 | spin_unlock_irq(&tconn->req_lock); |
Lars Ellenberg | 992d6e9 | 2011-05-02 11:47:18 +0200 | [diff] [blame] | 1173 | if (stop_threads) { |
| 1174 | /* asender is implicitly stopped by receiver |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 1175 | * in conn_disconnect() */ |
Lars Ellenberg | 992d6e9 | 2011-05-02 11:47:18 +0200 | [diff] [blame] | 1176 | drbd_thread_stop(&tconn->receiver); |
| 1177 | drbd_thread_stop(&tconn->worker); |
| 1178 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1181 | /* Make sure IO is suspended before calling this function(). */ |
| 1182 | static void drbd_suspend_al(struct drbd_conf *mdev) |
| 1183 | { |
| 1184 | int s = 0; |
| 1185 | |
Lars Ellenberg | 6161042 | 2011-02-21 13:20:54 +0100 | [diff] [blame] | 1186 | if (!lc_try_lock(mdev->act_log)) { |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1187 | dev_warn(DEV, "Failed to lock al in drbd_suspend_al()\n"); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
Lars Ellenberg | 6161042 | 2011-02-21 13:20:54 +0100 | [diff] [blame] | 1191 | drbd_al_shrink(mdev); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1192 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1193 | if (mdev->state.conn < C_CONNECTED) |
| 1194 | s = !test_and_set_bit(AL_SUSPENDED, &mdev->flags); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1195 | spin_unlock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 6161042 | 2011-02-21 13:20:54 +0100 | [diff] [blame] | 1196 | lc_unlock(mdev->act_log); |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1197 | |
| 1198 | if (s) |
| 1199 | dev_info(DEV, "Suspended AL updates\n"); |
| 1200 | } |
| 1201 | |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 1202 | |
| 1203 | static bool should_set_defaults(struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1204 | { |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 1205 | unsigned flags = ((struct drbd_genlmsghdr*)info->userhdr)->flags; |
| 1206 | return 0 != (flags & DRBD_GENL_F_SET_DEFAULTS); |
| 1207 | } |
| 1208 | |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1209 | static unsigned int drbd_al_extents_max(struct drbd_backing_dev *bdev) |
Philipp Reisner | d589a21 | 2011-05-04 10:06:52 +0200 | [diff] [blame] | 1210 | { |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1211 | /* This is limited by 16 bit "slot" numbers, |
| 1212 | * and by available on-disk context storage. |
| 1213 | * |
| 1214 | * Also (u16)~0 is special (denotes a "free" extent). |
| 1215 | * |
| 1216 | * One transaction occupies one 4kB on-disk block, |
| 1217 | * we have n such blocks in the on disk ring buffer, |
| 1218 | * the "current" transaction may fail (n-1), |
| 1219 | * and there is 919 slot numbers context information per transaction. |
| 1220 | * |
| 1221 | * 72 transaction blocks amounts to more than 2**16 context slots, |
| 1222 | * so cap there first. |
| 1223 | */ |
| 1224 | const unsigned int max_al_nr = DRBD_AL_EXTENTS_MAX; |
| 1225 | const unsigned int sufficient_on_disk = |
| 1226 | (max_al_nr + AL_CONTEXT_PER_TRANSACTION -1) |
| 1227 | /AL_CONTEXT_PER_TRANSACTION; |
Philipp Reisner | d589a21 | 2011-05-04 10:06:52 +0200 | [diff] [blame] | 1228 | |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1229 | unsigned int al_size_4k = bdev->md.al_size_4k; |
| 1230 | |
| 1231 | if (al_size_4k > sufficient_on_disk) |
| 1232 | return max_al_nr; |
| 1233 | |
| 1234 | return (al_size_4k - 1) * AL_CONTEXT_PER_TRANSACTION; |
Philipp Reisner | d589a21 | 2011-05-04 10:06:52 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1237 | int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) |
| 1238 | { |
| 1239 | enum drbd_ret_code retcode; |
| 1240 | struct drbd_conf *mdev; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1241 | struct disk_conf *new_disk_conf, *old_disk_conf; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 1242 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1243 | int err, fifo_size; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1244 | |
| 1245 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 1246 | if (!adm_ctx.reply_skb) |
| 1247 | return retcode; |
| 1248 | if (retcode != NO_ERROR) |
| 1249 | goto out; |
| 1250 | |
| 1251 | mdev = adm_ctx.mdev; |
| 1252 | |
| 1253 | /* we also need a disk |
| 1254 | * to change the options on */ |
| 1255 | if (!get_ldev(mdev)) { |
| 1256 | retcode = ERR_NO_DISK; |
| 1257 | goto out; |
| 1258 | } |
| 1259 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1260 | new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL); |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1261 | if (!new_disk_conf) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1262 | retcode = ERR_NOMEM; |
| 1263 | goto fail; |
| 1264 | } |
| 1265 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1266 | mutex_lock(&mdev->tconn->conf_update); |
| 1267 | old_disk_conf = mdev->ldev->disk_conf; |
| 1268 | *new_disk_conf = *old_disk_conf; |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 1269 | if (should_set_defaults(info)) |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 1270 | set_disk_conf_defaults(new_disk_conf); |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 1271 | |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1272 | err = disk_conf_from_attrs_for_change(new_disk_conf, info); |
Andreas Gruenbacher | c75b9b1 | 2011-05-24 14:18:31 +0200 | [diff] [blame] | 1273 | if (err && err != -ENOMSG) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1274 | retcode = ERR_MANDATORY_TAG; |
| 1275 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 1276 | } |
| 1277 | |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1278 | if (!expect(new_disk_conf->resync_rate >= 1)) |
| 1279 | new_disk_conf->resync_rate = 1; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1280 | |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1281 | if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN) |
| 1282 | new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN; |
| 1283 | if (new_disk_conf->al_extents > drbd_al_extents_max(mdev->ldev)) |
| 1284 | new_disk_conf->al_extents = drbd_al_extents_max(mdev->ldev); |
| 1285 | |
| 1286 | if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX) |
| 1287 | new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1288 | |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1289 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1290 | if (fifo_size != mdev->rs_plan_s->size) { |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 1291 | new_plan = fifo_alloc(fifo_size); |
| 1292 | if (!new_plan) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1293 | dev_err(DEV, "kmalloc of fifo_buffer failed"); |
| 1294 | retcode = ERR_NOMEM; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1295 | goto fail_unlock; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
Lars Ellenberg | 0ee98e2 | 2012-08-20 14:54:48 +0200 | [diff] [blame] | 1299 | drbd_suspend_io(mdev); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1300 | wait_event(mdev->al_wait, lc_try_lock(mdev->act_log)); |
| 1301 | drbd_al_shrink(mdev); |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1302 | err = drbd_check_al_size(mdev, new_disk_conf); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1303 | lc_unlock(mdev->act_log); |
| 1304 | wake_up(&mdev->al_wait); |
Lars Ellenberg | 0ee98e2 | 2012-08-20 14:54:48 +0200 | [diff] [blame] | 1305 | drbd_resume_io(mdev); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1306 | |
| 1307 | if (err) { |
| 1308 | retcode = ERR_NOMEM; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1309 | goto fail_unlock; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Philipp Reisner | dc97b70 | 2011-05-03 14:27:15 +0200 | [diff] [blame] | 1312 | write_lock_irq(&global_state_lock); |
Andreas Gruenbacher | 95f8efd | 2011-05-12 11:15:34 +0200 | [diff] [blame] | 1313 | retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after); |
Philipp Reisner | dc97b70 | 2011-05-03 14:27:15 +0200 | [diff] [blame] | 1314 | if (retcode == NO_ERROR) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1315 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); |
Andreas Gruenbacher | 95f8efd | 2011-05-12 11:15:34 +0200 | [diff] [blame] | 1316 | drbd_resync_after_changed(mdev); |
Philipp Reisner | dc97b70 | 2011-05-03 14:27:15 +0200 | [diff] [blame] | 1317 | } |
| 1318 | write_unlock_irq(&global_state_lock); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1319 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1320 | if (retcode != NO_ERROR) |
| 1321 | goto fail_unlock; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1322 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 1323 | if (new_plan) { |
| 1324 | old_plan = mdev->rs_plan_s; |
| 1325 | rcu_assign_pointer(mdev->rs_plan_s, new_plan); |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1326 | } |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1327 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 1328 | mutex_unlock(&mdev->tconn->conf_update); |
Philipp Reisner | 27eb13e | 2012-03-30 14:12:15 +0200 | [diff] [blame] | 1329 | |
Philipp Reisner | 9a51ab1 | 2012-02-20 21:53:28 +0100 | [diff] [blame] | 1330 | if (new_disk_conf->al_updates) |
Philipp Reisner | 4035e4c | 2012-10-01 18:04:12 +0200 | [diff] [blame] | 1331 | mdev->ldev->md.flags &= ~MDF_AL_DISABLED; |
Philipp Reisner | 9a51ab1 | 2012-02-20 21:53:28 +0100 | [diff] [blame] | 1332 | else |
| 1333 | mdev->ldev->md.flags |= MDF_AL_DISABLED; |
| 1334 | |
Lars Ellenberg | 691631c | 2012-10-26 00:41:50 +0200 | [diff] [blame] | 1335 | if (new_disk_conf->md_flushes) |
| 1336 | clear_bit(MD_NO_FUA, &mdev->flags); |
| 1337 | else |
| 1338 | set_bit(MD_NO_FUA, &mdev->flags); |
| 1339 | |
Philipp Reisner | 27eb13e | 2012-03-30 14:12:15 +0200 | [diff] [blame] | 1340 | drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush); |
| 1341 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1342 | drbd_md_sync(mdev); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1343 | |
| 1344 | if (mdev->state.conn >= C_CONNECTED) |
| 1345 | drbd_send_sync_param(mdev); |
| 1346 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1347 | synchronize_rcu(); |
| 1348 | kfree(old_disk_conf); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 1349 | kfree(old_plan); |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1350 | mod_timer(&mdev->request_timer, jiffies + HZ); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1351 | goto success; |
| 1352 | |
| 1353 | fail_unlock: |
| 1354 | mutex_unlock(&mdev->tconn->conf_update); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1355 | fail: |
Lars Ellenberg | 5ecc72c | 2011-04-27 21:14:57 +0200 | [diff] [blame] | 1356 | kfree(new_disk_conf); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 1357 | kfree(new_plan); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1358 | success: |
| 1359 | put_ldev(mdev); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1360 | out: |
| 1361 | drbd_adm_finish(info, retcode); |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1365 | int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1366 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1367 | struct drbd_conf *mdev; |
| 1368 | int err; |
Andreas Gruenbacher | 116676c | 2010-12-08 13:33:11 +0100 | [diff] [blame] | 1369 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1370 | enum determine_dev_size dd; |
| 1371 | sector_t max_possible_sectors; |
| 1372 | sector_t min_md_device_sectors; |
| 1373 | struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */ |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1374 | struct disk_conf *new_disk_conf = NULL; |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1375 | struct block_device *bdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1376 | struct lru_cache *resync_lru = NULL; |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1377 | struct fifo_buffer *new_plan = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1378 | union drbd_state ns, os; |
Andreas Gruenbacher | f2024e7 | 2010-12-10 13:44:05 +0100 | [diff] [blame] | 1379 | enum drbd_state_rv rv; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1380 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1381 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1382 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 1383 | if (!adm_ctx.reply_skb) |
| 1384 | return retcode; |
| 1385 | if (retcode != NO_ERROR) |
Lars Ellenberg | 40cbf08 | 2011-03-16 16:52:10 +0100 | [diff] [blame] | 1386 | goto finish; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1387 | |
| 1388 | mdev = adm_ctx.mdev; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1389 | conn_reconfig_start(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1390 | |
| 1391 | /* if you want to reconfigure, please tear down first */ |
| 1392 | if (mdev->state.disk > D_DISKLESS) { |
| 1393 | retcode = ERR_DISK_CONFIGURED; |
| 1394 | goto fail; |
| 1395 | } |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1396 | /* It may just now have detached because of IO error. Make sure |
| 1397 | * 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, |
| 1399 | * to realize a "hot spare" feature (not that I'd recommend that) */ |
| 1400 | wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1401 | |
Lars Ellenberg | 383606e | 2012-06-14 14:21:32 +0200 | [diff] [blame] | 1402 | /* make sure there is no leftover from previous force-detach attempts */ |
Lars Ellenberg | 0c84966 | 2012-07-30 09:07:28 +0200 | [diff] [blame] | 1403 | clear_bit(FORCE_DETACH, &mdev->flags); |
Lars Ellenberg | edc9f5e | 2012-09-27 15:18:21 +0200 | [diff] [blame] | 1404 | clear_bit(WAS_IO_ERROR, &mdev->flags); |
| 1405 | clear_bit(WAS_READ_ERROR, &mdev->flags); |
Lars Ellenberg | 383606e | 2012-06-14 14:21:32 +0200 | [diff] [blame] | 1406 | |
Lars Ellenberg | 0029d62 | 2012-06-14 18:02:52 +0200 | [diff] [blame] | 1407 | /* and no leftover from previously aborted resync or verify, either */ |
| 1408 | mdev->rs_total = 0; |
| 1409 | mdev->rs_failed = 0; |
| 1410 | atomic_set(&mdev->rs_pending_cnt, 0); |
| 1411 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1412 | /* allocation not in the IO path, drbdsetup context */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1413 | nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL); |
| 1414 | if (!nbc) { |
| 1415 | retcode = ERR_NOMEM; |
| 1416 | goto fail; |
| 1417 | } |
Philipp Reisner | 9f2247b | 2012-08-16 14:25:58 +0200 | [diff] [blame] | 1418 | spin_lock_init(&nbc->md.uuid_lock); |
| 1419 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1420 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 1421 | if (!new_disk_conf) { |
| 1422 | retcode = ERR_NOMEM; |
| 1423 | goto fail; |
| 1424 | } |
| 1425 | nbc->disk_conf = new_disk_conf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1426 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1427 | set_disk_conf_defaults(new_disk_conf); |
| 1428 | err = disk_conf_from_attrs(new_disk_conf, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1429 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1430 | retcode = ERR_MANDATORY_TAG; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1431 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1432 | goto fail; |
| 1433 | } |
| 1434 | |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1435 | if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX) |
| 1436 | new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX; |
Philipp Reisner | d589a21 | 2011-05-04 10:06:52 +0200 | [diff] [blame] | 1437 | |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1438 | new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ); |
| 1439 | if (!new_plan) { |
| 1440 | retcode = ERR_NOMEM; |
| 1441 | goto fail; |
| 1442 | } |
| 1443 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1444 | if (new_disk_conf->meta_dev_idx < DRBD_MD_INDEX_FLEX_INT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1445 | retcode = ERR_MD_IDX_INVALID; |
| 1446 | goto fail; |
| 1447 | } |
| 1448 | |
Lars Ellenberg | a3f8f7d | 2013-03-27 14:08:43 +0100 | [diff] [blame] | 1449 | write_lock_irq(&global_state_lock); |
| 1450 | retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after); |
| 1451 | write_unlock_irq(&global_state_lock); |
| 1452 | if (retcode != NO_ERROR) |
| 1453 | goto fail; |
| 1454 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1455 | rcu_read_lock(); |
| 1456 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 1457 | if (nc) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1458 | if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1459 | rcu_read_unlock(); |
Philipp Reisner | 47ff2d0 | 2010-06-18 13:56:57 +0200 | [diff] [blame] | 1460 | retcode = ERR_STONITH_AND_PROT_A; |
| 1461 | goto fail; |
| 1462 | } |
| 1463 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1464 | rcu_read_unlock(); |
Philipp Reisner | 47ff2d0 | 2010-06-18 13:56:57 +0200 | [diff] [blame] | 1465 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1466 | bdev = blkdev_get_by_path(new_disk_conf->backing_dev, |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 1467 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev); |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1468 | if (IS_ERR(bdev)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1469 | dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->backing_dev, |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1470 | PTR_ERR(bdev)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1471 | retcode = ERR_OPEN_DISK; |
| 1472 | goto fail; |
| 1473 | } |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1474 | nbc->backing_bdev = bdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1475 | |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1476 | /* |
| 1477 | * meta_dev_idx >= 0: external fixed size, possibly multiple |
| 1478 | * drbd sharing one meta device. TODO in that case, paranoia |
| 1479 | * check that [md_bdev, meta_dev_idx] is not yet used by some |
| 1480 | * other drbd minor! (if you use drbd.conf + drbdadm, that |
| 1481 | * should check it for you already; but if you don't, or |
| 1482 | * someone fooled it, we need to double check here) |
| 1483 | */ |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1484 | bdev = blkdev_get_by_path(new_disk_conf->meta_dev, |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 1485 | FMODE_READ | FMODE_WRITE | FMODE_EXCL, |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1486 | (new_disk_conf->meta_dev_idx < 0) ? |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 1487 | (void *)mdev : (void *)drbd_m_holder); |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1488 | if (IS_ERR(bdev)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1489 | dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->meta_dev, |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1490 | PTR_ERR(bdev)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1491 | retcode = ERR_OPEN_MD_DISK; |
| 1492 | goto fail; |
| 1493 | } |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1494 | nbc->md_bdev = bdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1495 | |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1496 | if ((nbc->backing_bdev == nbc->md_bdev) != |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1497 | (new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_INTERNAL || |
| 1498 | new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) { |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1499 | retcode = ERR_MD_IDX_INVALID; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1500 | goto fail; |
| 1501 | } |
| 1502 | |
| 1503 | resync_lru = lc_create("resync", drbd_bm_ext_cache, |
Lars Ellenberg | 46a15bc | 2011-02-21 13:21:01 +0100 | [diff] [blame] | 1504 | 1, 61, sizeof(struct bm_extent), |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1505 | offsetof(struct bm_extent, lce)); |
| 1506 | if (!resync_lru) { |
| 1507 | retcode = ERR_NOMEM; |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1508 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Lars Ellenberg | c04ccaa | 2013-03-19 18:16:47 +0100 | [diff] [blame] | 1511 | /* Read our meta data super block early. |
| 1512 | * This also sets other on-disk offsets. */ |
| 1513 | retcode = drbd_md_read(mdev, nbc); |
| 1514 | if (retcode != NO_ERROR) |
| 1515 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1516 | |
Lars Ellenberg | 5bbcf5e | 2013-03-19 18:16:59 +0100 | [diff] [blame] | 1517 | if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN) |
| 1518 | new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN; |
| 1519 | if (new_disk_conf->al_extents > drbd_al_extents_max(nbc)) |
| 1520 | new_disk_conf->al_extents = drbd_al_extents_max(nbc); |
| 1521 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1522 | if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1523 | dev_err(DEV, "max capacity %llu smaller than disk size %llu\n", |
| 1524 | (unsigned long long) drbd_get_max_capacity(nbc), |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1525 | (unsigned long long) new_disk_conf->disk_size); |
Lars Ellenberg | 7948bcd | 2011-06-06 15:36:04 +0200 | [diff] [blame] | 1526 | retcode = ERR_DISK_TOO_SMALL; |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1527 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1530 | if (new_disk_conf->meta_dev_idx < 0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1531 | max_possible_sectors = DRBD_MAX_SECTORS_FLEX; |
| 1532 | /* at least one MB, otherwise it does not make sense */ |
| 1533 | min_md_device_sectors = (2<<10); |
| 1534 | } else { |
| 1535 | max_possible_sectors = DRBD_MAX_SECTORS; |
Lars Ellenberg | ae8bf31 | 2013-03-19 18:16:43 +0100 | [diff] [blame] | 1536 | min_md_device_sectors = MD_128MB_SECT * (new_disk_conf->meta_dev_idx + 1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1539 | if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) { |
Lars Ellenberg | 7948bcd | 2011-06-06 15:36:04 +0200 | [diff] [blame] | 1540 | retcode = ERR_MD_DISK_TOO_SMALL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1541 | dev_warn(DEV, "refusing attach: md-device too small, " |
| 1542 | "at least %llu sectors needed for this meta-disk type\n", |
| 1543 | (unsigned long long) min_md_device_sectors); |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1544 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | /* Make sure the new disk is big enough |
| 1548 | * (we may currently be R_PRIMARY with no local disk...) */ |
| 1549 | if (drbd_get_max_capacity(nbc) < |
| 1550 | drbd_get_capacity(mdev->this_bdev)) { |
Lars Ellenberg | 7948bcd | 2011-06-06 15:36:04 +0200 | [diff] [blame] | 1551 | retcode = ERR_DISK_TOO_SMALL; |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1552 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | nbc->known_size = drbd_get_capacity(nbc->backing_bdev); |
| 1556 | |
Lars Ellenberg | 1352994 | 2009-10-12 19:07:49 +0200 | [diff] [blame] | 1557 | if (nbc->known_size > max_possible_sectors) { |
| 1558 | dev_warn(DEV, "==> truncating very big lower level device " |
| 1559 | "to currently maximum possible %llu sectors <==\n", |
| 1560 | (unsigned long long) max_possible_sectors); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1561 | if (new_disk_conf->meta_dev_idx >= 0) |
Lars Ellenberg | 1352994 | 2009-10-12 19:07:49 +0200 | [diff] [blame] | 1562 | dev_warn(DEV, "==>> using internal or flexible " |
| 1563 | "meta data may help <<==\n"); |
| 1564 | } |
| 1565 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1566 | drbd_suspend_io(mdev); |
| 1567 | /* also wait for the last barrier ack. */ |
Lars Ellenberg | b6dd1a8 | 2011-11-28 15:04:49 +0100 | [diff] [blame] | 1568 | /* 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 |
| 1570 | * was attached, or a way to wait for all pending barrier acks to come in. |
| 1571 | * As barriers are counted per resource, |
| 1572 | * we'd need to suspend io on all devices of a resource. |
| 1573 | */ |
Philipp Reisner | 2aebfab | 2011-03-28 16:48:11 +0200 | [diff] [blame] | 1574 | wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_pending_cnt) || drbd_suspended(mdev)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1575 | /* and for any other previously queued work */ |
| 1576 | drbd_flush_workqueue(mdev); |
| 1577 | |
Andreas Gruenbacher | f2024e7 | 2010-12-10 13:44:05 +0100 | [diff] [blame] | 1578 | rv = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE); |
| 1579 | retcode = rv; /* FIXME: Type mismatch. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1580 | drbd_resume_io(mdev); |
Andreas Gruenbacher | f2024e7 | 2010-12-10 13:44:05 +0100 | [diff] [blame] | 1581 | if (rv < SS_SUCCESS) |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1582 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1583 | |
| 1584 | if (!get_ldev_if_state(mdev, D_ATTACHING)) |
| 1585 | goto force_diskless; |
| 1586 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1587 | if (!mdev->bitmap) { |
| 1588 | if (drbd_bm_init(mdev)) { |
| 1589 | retcode = ERR_NOMEM; |
| 1590 | goto force_diskless_dec; |
| 1591 | } |
| 1592 | } |
| 1593 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1594 | if (mdev->state.conn < C_CONNECTED && |
| 1595 | mdev->state.role == R_PRIMARY && |
| 1596 | (mdev->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", |
| 1598 | (unsigned long long)mdev->ed_uuid); |
| 1599 | retcode = ERR_DATA_NOT_CURRENT; |
| 1600 | goto force_diskless_dec; |
| 1601 | } |
| 1602 | |
| 1603 | /* Since we are diskless, fix the activity log first... */ |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1604 | if (drbd_check_al_size(mdev, new_disk_conf)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1605 | retcode = ERR_NOMEM; |
| 1606 | goto force_diskless_dec; |
| 1607 | } |
| 1608 | |
| 1609 | /* Prevent shrinking of consistent devices ! */ |
| 1610 | if (drbd_md_test_flag(nbc, MDF_CONSISTENT) && |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1611 | drbd_new_dev_size(mdev, nbc, nbc->disk_conf->disk_size, 0) < nbc->md.la_size_sect) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1612 | dev_warn(DEV, "refusing to truncate a consistent device\n"); |
Lars Ellenberg | 7948bcd | 2011-06-06 15:36:04 +0200 | [diff] [blame] | 1613 | retcode = ERR_DISK_TOO_SMALL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1614 | goto force_diskless_dec; |
| 1615 | } |
| 1616 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1617 | /* Reset the "barriers don't work" bits here, then force meta data to |
| 1618 | * be written, to ensure we determine if barriers are supported. */ |
Andreas Gruenbacher | e544046 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 1619 | if (new_disk_conf->md_flushes) |
Philipp Reisner | a8a4e51 | 2010-08-25 10:21:04 +0200 | [diff] [blame] | 1620 | clear_bit(MD_NO_FUA, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1621 | else |
Andreas Gruenbacher | e544046 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 1622 | set_bit(MD_NO_FUA, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1623 | |
| 1624 | /* Point of no return reached. |
| 1625 | * Devices and memory are no longer released by error cleanup below. |
| 1626 | * now mdev takes over responsibility, and the state engine should |
| 1627 | * clean it up somewhere. */ |
| 1628 | D_ASSERT(mdev->ldev == NULL); |
| 1629 | mdev->ldev = nbc; |
| 1630 | mdev->resync = resync_lru; |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1631 | mdev->rs_plan_s = new_plan; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1632 | nbc = NULL; |
| 1633 | resync_lru = NULL; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1634 | new_disk_conf = NULL; |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1635 | new_plan = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1636 | |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1637 | drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY)) |
| 1640 | set_bit(CRASHED_PRIMARY, &mdev->flags); |
| 1641 | else |
| 1642 | clear_bit(CRASHED_PRIMARY, &mdev->flags); |
| 1643 | |
Philipp Reisner | 894c6a9 | 2010-06-18 16:03:20 +0200 | [diff] [blame] | 1644 | if (drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) && |
Lars Ellenberg | d5d7ebd | 2011-07-05 20:59:26 +0200 | [diff] [blame] | 1645 | !(mdev->state.role == R_PRIMARY && mdev->tconn->susp_nod)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1646 | set_bit(CRASHED_PRIMARY, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1647 | |
| 1648 | mdev->send_cnt = 0; |
| 1649 | mdev->recv_cnt = 0; |
| 1650 | mdev->read_cnt = 0; |
| 1651 | mdev->writ_cnt = 0; |
| 1652 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1653 | drbd_reconsider_max_bio_size(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1654 | |
| 1655 | /* If I am currently not R_PRIMARY, |
| 1656 | * but meta data primary indicator is set, |
| 1657 | * I just now recover from a hard crash, |
| 1658 | * and have been R_PRIMARY before that crash. |
| 1659 | * |
| 1660 | * Now, if I had no connection before that crash |
| 1661 | * (have been degraded R_PRIMARY), chances are that |
| 1662 | * I won't find my peer now either. |
| 1663 | * |
| 1664 | * In that case, and _only_ in that case, |
| 1665 | * we use the degr-wfc-timeout instead of the default, |
| 1666 | * so we can automatically recover from a crash of a |
| 1667 | * degraded but active "cluster" after a certain timeout. |
| 1668 | */ |
| 1669 | clear_bit(USE_DEGR_WFC_T, &mdev->flags); |
| 1670 | if (mdev->state.role != R_PRIMARY && |
| 1671 | drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) && |
| 1672 | !drbd_md_test_flag(mdev->ldev, MDF_CONNECTED_IND)) |
| 1673 | set_bit(USE_DEGR_WFC_T, &mdev->flags); |
| 1674 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 1675 | dd = drbd_determine_dev_size(mdev, 0, NULL); |
| 1676 | if (dd <= DS_ERROR) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1677 | retcode = ERR_NOMEM_BITMAP; |
| 1678 | goto force_diskless_dec; |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 1679 | } else if (dd == DS_GREW) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1680 | set_bit(RESYNC_AFTER_NEG, &mdev->flags); |
| 1681 | |
Philipp Reisner | 9a51ab1 | 2012-02-20 21:53:28 +0100 | [diff] [blame] | 1682 | if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC) || |
| 1683 | (test_bit(CRASHED_PRIMARY, &mdev->flags) && |
| 1684 | drbd_md_test_flag(mdev->ldev, MDF_AL_DISABLED))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1685 | dev_info(DEV, "Assuming that all blocks are out of sync " |
| 1686 | "(aka FullSync)\n"); |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 1687 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, |
| 1688 | "set_n_write from attaching", BM_LOCKED_MASK)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1689 | retcode = ERR_IO_MD_DISK; |
| 1690 | goto force_diskless_dec; |
| 1691 | } |
| 1692 | } else { |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 1693 | if (drbd_bitmap_io(mdev, &drbd_bm_read, |
Andreas Gruenbacher | 22ab6a3 | 2010-12-13 01:44:11 +0100 | [diff] [blame] | 1694 | "read from attaching", BM_LOCKED_MASK)) { |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 1695 | retcode = ERR_IO_MD_DISK; |
| 1696 | goto force_diskless_dec; |
| 1697 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1700 | if (_drbd_bm_total_weight(mdev) == drbd_bm_bits(mdev)) |
| 1701 | drbd_suspend_al(mdev); /* IO is still suspended here... */ |
| 1702 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1703 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 78bae59 | 2011-03-28 15:40:12 +0200 | [diff] [blame] | 1704 | os = drbd_read_state(mdev); |
| 1705 | ns = os; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1706 | /* If MDF_CONSISTENT is not set go into inconsistent state, |
| 1707 | otherwise investigate MDF_WasUpToDate... |
| 1708 | If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state, |
| 1709 | otherwise into D_CONSISTENT state. |
| 1710 | */ |
| 1711 | if (drbd_md_test_flag(mdev->ldev, MDF_CONSISTENT)) { |
| 1712 | if (drbd_md_test_flag(mdev->ldev, MDF_WAS_UP_TO_DATE)) |
| 1713 | ns.disk = D_CONSISTENT; |
| 1714 | else |
| 1715 | ns.disk = D_OUTDATED; |
| 1716 | } else { |
| 1717 | ns.disk = D_INCONSISTENT; |
| 1718 | } |
| 1719 | |
| 1720 | if (drbd_md_test_flag(mdev->ldev, MDF_PEER_OUT_DATED)) |
| 1721 | ns.pdsk = D_OUTDATED; |
| 1722 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1723 | rcu_read_lock(); |
| 1724 | if (ns.disk == D_CONSISTENT && |
| 1725 | (ns.pdsk == D_OUTDATED || rcu_dereference(mdev->ldev->disk_conf)->fencing == FP_DONT_CARE)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1726 | ns.disk = D_UP_TO_DATE; |
| 1727 | |
| 1728 | /* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND, |
| 1729 | MDF_CONSISTENT and MDF_WAS_UP_TO_DATE must happen before |
| 1730 | this point, because drbd_request_state() modifies these |
| 1731 | flags. */ |
| 1732 | |
Philipp Reisner | 9a51ab1 | 2012-02-20 21:53:28 +0100 | [diff] [blame] | 1733 | if (rcu_dereference(mdev->ldev->disk_conf)->al_updates) |
Philipp Reisner | 4035e4c | 2012-10-01 18:04:12 +0200 | [diff] [blame] | 1734 | mdev->ldev->md.flags &= ~MDF_AL_DISABLED; |
Philipp Reisner | 9a51ab1 | 2012-02-20 21:53:28 +0100 | [diff] [blame] | 1735 | else |
| 1736 | mdev->ldev->md.flags |= MDF_AL_DISABLED; |
| 1737 | |
| 1738 | rcu_read_unlock(); |
| 1739 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1740 | /* In case we are C_CONNECTED postpone any decision on the new disk |
| 1741 | state after the negotiation phase. */ |
| 1742 | if (mdev->state.conn == C_CONNECTED) { |
| 1743 | mdev->new_state_tmp.i = ns.i; |
| 1744 | ns.i = os.i; |
| 1745 | ns.disk = D_NEGOTIATING; |
Philipp Reisner | dc66c74 | 2010-06-02 14:31:29 +0200 | [diff] [blame] | 1746 | |
| 1747 | /* We expect to receive up-to-date UUIDs soon. |
| 1748 | To avoid a race in receive_state, free p_uuid while |
| 1749 | holding req_lock. I.e. atomic with the state change */ |
| 1750 | kfree(mdev->p_uuid); |
| 1751 | mdev->p_uuid = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | rv = _drbd_set_state(mdev, ns, CS_VERBOSE, NULL); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1755 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1756 | |
| 1757 | if (rv < SS_SUCCESS) |
| 1758 | goto force_diskless_dec; |
| 1759 | |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1760 | mod_timer(&mdev->request_timer, jiffies + HZ); |
| 1761 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1762 | if (mdev->state.role == R_PRIMARY) |
| 1763 | mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1; |
| 1764 | else |
| 1765 | mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1; |
| 1766 | |
| 1767 | drbd_md_mark_dirty(mdev); |
| 1768 | drbd_md_sync(mdev); |
| 1769 | |
| 1770 | kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE); |
| 1771 | put_ldev(mdev); |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 1772 | conn_reconfig_done(mdev->tconn); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1773 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1774 | return 0; |
| 1775 | |
| 1776 | force_diskless_dec: |
| 1777 | put_ldev(mdev); |
| 1778 | force_diskless: |
Philipp Reisner | 9510b24 | 2011-07-01 17:00:57 +0200 | [diff] [blame] | 1779 | drbd_force_state(mdev, NS(disk, D_DISKLESS)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1780 | drbd_md_sync(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1781 | fail: |
Lars Ellenberg | 40cbf08 | 2011-03-16 16:52:10 +0100 | [diff] [blame] | 1782 | conn_reconfig_done(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1783 | if (nbc) { |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 1784 | if (nbc->backing_bdev) |
| 1785 | blkdev_put(nbc->backing_bdev, |
| 1786 | FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
| 1787 | if (nbc->md_bdev) |
| 1788 | blkdev_put(nbc->md_bdev, |
| 1789 | FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1790 | kfree(nbc); |
| 1791 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1792 | kfree(new_disk_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1793 | lc_destroy(resync_lru); |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 1794 | kfree(new_plan); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1795 | |
Lars Ellenberg | 40cbf08 | 2011-03-16 16:52:10 +0100 | [diff] [blame] | 1796 | finish: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1797 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1798 | return 0; |
| 1799 | } |
| 1800 | |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1801 | static int adm_detach(struct drbd_conf *mdev, int force) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1802 | { |
Philipp Reisner | 19f83c7 | 2011-03-29 14:21:03 +0200 | [diff] [blame] | 1803 | enum drbd_state_rv retcode; |
Lars Ellenberg | 9a0d9d0 | 2011-05-02 11:51:31 +0200 | [diff] [blame] | 1804 | int ret; |
Philipp Reisner | 02ee8f9 | 2011-03-14 11:54:47 +0100 | [diff] [blame] | 1805 | |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1806 | if (force) { |
Lars Ellenberg | 0c84966 | 2012-07-30 09:07:28 +0200 | [diff] [blame] | 1807 | set_bit(FORCE_DETACH, &mdev->flags); |
Philipp Reisner | 02ee8f9 | 2011-03-14 11:54:47 +0100 | [diff] [blame] | 1808 | drbd_force_state(mdev, NS(disk, D_FAILED)); |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1809 | retcode = SS_SUCCESS; |
Philipp Reisner | 02ee8f9 | 2011-03-14 11:54:47 +0100 | [diff] [blame] | 1810 | goto out; |
| 1811 | } |
| 1812 | |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1813 | drbd_suspend_io(mdev); /* so no-one is stuck in drbd_al_begin_io */ |
Lars Ellenberg | a2e9138 | 2011-10-06 17:30:26 +0200 | [diff] [blame] | 1814 | drbd_md_get_buffer(mdev); /* make sure there is no in-flight meta-data IO */ |
Lars Ellenberg | 9a0d9d0 | 2011-05-02 11:51:31 +0200 | [diff] [blame] | 1815 | retcode = drbd_request_state(mdev, NS(disk, D_FAILED)); |
Lars Ellenberg | a2e9138 | 2011-10-06 17:30:26 +0200 | [diff] [blame] | 1816 | drbd_md_put_buffer(mdev); |
Lars Ellenberg | 9a0d9d0 | 2011-05-02 11:51:31 +0200 | [diff] [blame] | 1817 | /* D_FAILED will transition to DISKLESS. */ |
| 1818 | ret = wait_event_interruptible(mdev->misc_wait, |
| 1819 | mdev->state.disk != D_FAILED); |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1820 | drbd_resume_io(mdev); |
Philipp Reisner | 9b2f61a | 2011-05-24 10:27:38 +0200 | [diff] [blame] | 1821 | if ((int)retcode == (int)SS_IS_DISKLESS) |
Lars Ellenberg | 9a0d9d0 | 2011-05-02 11:51:31 +0200 | [diff] [blame] | 1822 | retcode = SS_NOTHING_TO_DO; |
| 1823 | if (ret) |
| 1824 | retcode = ERR_INTR; |
Philipp Reisner | 02ee8f9 | 2011-03-14 11:54:47 +0100 | [diff] [blame] | 1825 | out: |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 1826 | return retcode; |
| 1827 | } |
| 1828 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1829 | /* Detaching the disk is a process in multiple stages. First we need to lock |
| 1830 | * out application IO, in-flight IO, IO stuck in drbd_al_begin_io. |
| 1831 | * Then we transition to D_DISKLESS, and wait for put_ldev() to return all |
| 1832 | * internal references as well. |
| 1833 | * Only then we have finally detached. */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1834 | int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1835 | { |
| 1836 | enum drbd_ret_code retcode; |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1837 | struct detach_parms parms = { }; |
| 1838 | int err; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1839 | |
| 1840 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 1841 | if (!adm_ctx.reply_skb) |
| 1842 | return retcode; |
| 1843 | if (retcode != NO_ERROR) |
| 1844 | goto out; |
| 1845 | |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1846 | if (info->attrs[DRBD_NLA_DETACH_PARMS]) { |
| 1847 | err = detach_parms_from_attrs(&parms, info); |
| 1848 | if (err) { |
| 1849 | retcode = ERR_MANDATORY_TAG; |
| 1850 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 1851 | goto out; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | retcode = adm_detach(adm_ctx.mdev, parms.force_detach); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1856 | out: |
| 1857 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1858 | return 0; |
| 1859 | } |
| 1860 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1861 | static bool conn_resync_running(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1862 | { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1863 | struct drbd_conf *mdev; |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1864 | bool rv = false; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1865 | int vnr; |
| 1866 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1867 | rcu_read_lock(); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1868 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 1869 | if (mdev->state.conn == C_SYNC_SOURCE || |
| 1870 | mdev->state.conn == C_SYNC_TARGET || |
| 1871 | mdev->state.conn == C_PAUSED_SYNC_S || |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1872 | mdev->state.conn == C_PAUSED_SYNC_T) { |
| 1873 | rv = true; |
| 1874 | break; |
| 1875 | } |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1876 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1877 | rcu_read_unlock(); |
| 1878 | |
| 1879 | return rv; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | static bool conn_ov_running(struct drbd_tconn *tconn) |
| 1883 | { |
| 1884 | struct drbd_conf *mdev; |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1885 | bool rv = false; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1886 | int vnr; |
| 1887 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1888 | rcu_read_lock(); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1889 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 1890 | if (mdev->state.conn == C_VERIFY_S || |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1891 | mdev->state.conn == C_VERIFY_T) { |
| 1892 | rv = true; |
| 1893 | break; |
| 1894 | } |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1895 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1896 | rcu_read_unlock(); |
| 1897 | |
| 1898 | return rv; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1901 | static enum drbd_ret_code |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1902 | _check_net_options(struct drbd_tconn *tconn, struct net_conf *old_conf, struct net_conf *new_conf) |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1903 | { |
| 1904 | struct drbd_conf *mdev; |
| 1905 | int i; |
| 1906 | |
Philipp Reisner | dcb20d1 | 2011-05-16 14:30:24 +0200 | [diff] [blame] | 1907 | if (old_conf && tconn->cstate == C_WF_REPORT_PARAMS && tconn->agreed_pro_version < 100) { |
| 1908 | if (new_conf->wire_protocol != old_conf->wire_protocol) |
| 1909 | return ERR_NEED_APV_100; |
| 1910 | |
| 1911 | if (new_conf->two_primaries != old_conf->two_primaries) |
| 1912 | return ERR_NEED_APV_100; |
| 1913 | |
Philipp Reisner | dcb20d1 | 2011-05-16 14:30:24 +0200 | [diff] [blame] | 1914 | if (strcmp(new_conf->integrity_alg, old_conf->integrity_alg)) |
| 1915 | return ERR_NEED_APV_100; |
| 1916 | } |
| 1917 | |
| 1918 | if (!new_conf->two_primaries && |
| 1919 | conn_highest_role(tconn) == R_PRIMARY && |
| 1920 | conn_highest_peer(tconn) == R_PRIMARY) |
| 1921 | return ERR_NEED_ALLOW_TWO_PRI; |
Philipp Reisner | b032b6f | 2011-04-13 18:16:10 -0700 | [diff] [blame] | 1922 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1923 | if (new_conf->two_primaries && |
| 1924 | (new_conf->wire_protocol != DRBD_PROT_C)) |
| 1925 | return ERR_NOT_PROTO_C; |
| 1926 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1927 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 1928 | if (get_ldev(mdev)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1929 | enum drbd_fencing_p fp = rcu_dereference(mdev->ldev->disk_conf)->fencing; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1930 | put_ldev(mdev); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1931 | if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1932 | return ERR_STONITH_AND_PROT_A; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1933 | } |
Andreas Gruenbacher | 6139f60 | 2011-05-06 20:00:02 +0200 | [diff] [blame] | 1934 | if (mdev->state.role == R_PRIMARY && new_conf->discard_my_data) |
Lars Ellenberg | eb12010 | 2012-08-01 12:46:20 +0200 | [diff] [blame] | 1935 | return ERR_DISCARD_IMPOSSIBLE; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1936 | } |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1937 | |
| 1938 | if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) |
| 1939 | return ERR_CONG_NOT_PROTO_A; |
| 1940 | |
| 1941 | return NO_ERROR; |
| 1942 | } |
| 1943 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1944 | static enum drbd_ret_code |
| 1945 | check_net_options(struct drbd_tconn *tconn, struct net_conf *new_conf) |
| 1946 | { |
| 1947 | static enum drbd_ret_code rv; |
| 1948 | struct drbd_conf *mdev; |
| 1949 | int i; |
| 1950 | |
| 1951 | rcu_read_lock(); |
| 1952 | rv = _check_net_options(tconn, rcu_dereference(tconn->net_conf), new_conf); |
| 1953 | rcu_read_unlock(); |
| 1954 | |
| 1955 | /* tconn->volumes protected by genl_lock() here */ |
| 1956 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 1957 | if (!mdev->bitmap) { |
| 1958 | if(drbd_bm_init(mdev)) |
| 1959 | return ERR_NOMEM; |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | return rv; |
| 1964 | } |
| 1965 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1966 | struct crypto { |
| 1967 | struct crypto_hash *verify_tfm; |
| 1968 | struct crypto_hash *csums_tfm; |
| 1969 | struct crypto_hash *cram_hmac_tfm; |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 1970 | struct crypto_hash *integrity_tfm; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1971 | }; |
| 1972 | |
| 1973 | static int |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1974 | alloc_hash(struct crypto_hash **tfm, char *tfm_name, int err_alg) |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1975 | { |
| 1976 | if (!tfm_name[0]) |
| 1977 | return NO_ERROR; |
| 1978 | |
| 1979 | *tfm = crypto_alloc_hash(tfm_name, 0, CRYPTO_ALG_ASYNC); |
| 1980 | if (IS_ERR(*tfm)) { |
| 1981 | *tfm = NULL; |
| 1982 | return err_alg; |
| 1983 | } |
| 1984 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1985 | return NO_ERROR; |
| 1986 | } |
| 1987 | |
| 1988 | static enum drbd_ret_code |
| 1989 | alloc_crypto(struct crypto *crypto, struct net_conf *new_conf) |
| 1990 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1991 | char hmac_name[CRYPTO_MAX_ALG_NAME]; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1992 | enum drbd_ret_code rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1993 | |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1994 | rv = alloc_hash(&crypto->csums_tfm, new_conf->csums_alg, |
| 1995 | ERR_CSUMS_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1996 | if (rv != NO_ERROR) |
| 1997 | return rv; |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1998 | rv = alloc_hash(&crypto->verify_tfm, new_conf->verify_alg, |
| 1999 | ERR_VERIFY_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2000 | if (rv != NO_ERROR) |
| 2001 | return rv; |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 2002 | rv = alloc_hash(&crypto->integrity_tfm, new_conf->integrity_alg, |
| 2003 | ERR_INTEGRITY_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2004 | if (rv != NO_ERROR) |
| 2005 | return rv; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2006 | if (new_conf->cram_hmac_alg[0] != 0) { |
| 2007 | snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", |
| 2008 | new_conf->cram_hmac_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2009 | |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 2010 | rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name, |
| 2011 | ERR_AUTH_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2012 | } |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2013 | |
| 2014 | return rv; |
| 2015 | } |
| 2016 | |
| 2017 | static void free_crypto(struct crypto *crypto) |
| 2018 | { |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2019 | crypto_free_hash(crypto->cram_hmac_tfm); |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 2020 | crypto_free_hash(crypto->integrity_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2021 | crypto_free_hash(crypto->csums_tfm); |
| 2022 | crypto_free_hash(crypto->verify_tfm); |
| 2023 | } |
| 2024 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2025 | int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) |
| 2026 | { |
| 2027 | enum drbd_ret_code retcode; |
| 2028 | struct drbd_tconn *tconn; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2029 | struct net_conf *old_conf, *new_conf = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2030 | int err; |
| 2031 | int ovr; /* online verify running */ |
| 2032 | int rsr; /* re-sync running */ |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2033 | struct crypto crypto = { }; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2034 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2035 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2036 | if (!adm_ctx.reply_skb) |
| 2037 | return retcode; |
| 2038 | if (retcode != NO_ERROR) |
| 2039 | goto out; |
| 2040 | |
| 2041 | tconn = adm_ctx.tconn; |
| 2042 | |
| 2043 | new_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 2044 | if (!new_conf) { |
| 2045 | retcode = ERR_NOMEM; |
| 2046 | goto out; |
| 2047 | } |
| 2048 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2049 | conn_reconfig_start(tconn); |
| 2050 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 2051 | mutex_lock(&tconn->data.mutex); |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2052 | mutex_lock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2053 | old_conf = tconn->net_conf; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2054 | |
| 2055 | if (!old_conf) { |
| 2056 | drbd_msg_put_info("net conf missing, try connect"); |
| 2057 | retcode = ERR_INVALID_REQUEST; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2058 | goto fail; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | *new_conf = *old_conf; |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 2062 | if (should_set_defaults(info)) |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2063 | set_net_conf_defaults(new_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2064 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2065 | err = net_conf_from_attrs_for_change(new_conf, info); |
Andreas Gruenbacher | c75b9b1 | 2011-05-24 14:18:31 +0200 | [diff] [blame] | 2066 | if (err && err != -ENOMSG) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2067 | retcode = ERR_MANDATORY_TAG; |
| 2068 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2069 | goto fail; |
| 2070 | } |
| 2071 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 2072 | retcode = check_net_options(tconn, new_conf); |
| 2073 | if (retcode != NO_ERROR) |
| 2074 | goto fail; |
| 2075 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2076 | /* re-sync running */ |
| 2077 | rsr = conn_resync_running(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2078 | if (rsr && strcmp(new_conf->csums_alg, old_conf->csums_alg)) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2079 | retcode = ERR_CSUMS_RESYNC_RUNNING; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2080 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2081 | } |
| 2082 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2083 | /* online verify running */ |
| 2084 | ovr = conn_ov_running(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2085 | if (ovr && strcmp(new_conf->verify_alg, old_conf->verify_alg)) { |
| 2086 | retcode = ERR_VERIFY_RUNNING; |
| 2087 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2088 | } |
| 2089 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2090 | retcode = alloc_crypto(&crypto, new_conf); |
| 2091 | if (retcode != NO_ERROR) |
| 2092 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2093 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2094 | rcu_assign_pointer(tconn->net_conf, new_conf); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2095 | |
| 2096 | if (!rsr) { |
| 2097 | crypto_free_hash(tconn->csums_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2098 | tconn->csums_tfm = crypto.csums_tfm; |
| 2099 | crypto.csums_tfm = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2100 | } |
| 2101 | if (!ovr) { |
| 2102 | crypto_free_hash(tconn->verify_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2103 | tconn->verify_tfm = crypto.verify_tfm; |
| 2104 | crypto.verify_tfm = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 2107 | crypto_free_hash(tconn->integrity_tfm); |
| 2108 | tconn->integrity_tfm = crypto.integrity_tfm; |
Philipp Reisner | d659f2a | 2011-05-16 17:38:45 +0200 | [diff] [blame] | 2109 | if (tconn->cstate >= C_WF_REPORT_PARAMS && tconn->agreed_pro_version >= 100) |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 2110 | /* Do this without trying to take tconn->data.mutex again. */ |
Philipp Reisner | d659f2a | 2011-05-16 17:38:45 +0200 | [diff] [blame] | 2111 | __drbd_send_protocol(tconn, P_PROTOCOL_UPDATE); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2112 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2113 | crypto_free_hash(tconn->cram_hmac_tfm); |
| 2114 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; |
| 2115 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2116 | mutex_unlock(&tconn->conf_update); |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 2117 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2118 | synchronize_rcu(); |
| 2119 | kfree(old_conf); |
| 2120 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2121 | if (tconn->cstate >= C_WF_REPORT_PARAMS) |
| 2122 | drbd_send_sync_param(minor_to_mdev(conn_lowest_minor(tconn))); |
| 2123 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2124 | goto done; |
| 2125 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2126 | fail: |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2127 | mutex_unlock(&tconn->conf_update); |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 2128 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2129 | free_crypto(&crypto); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2130 | kfree(new_conf); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2131 | done: |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2132 | conn_reconfig_done(tconn); |
| 2133 | out: |
| 2134 | drbd_adm_finish(info, retcode); |
| 2135 | return 0; |
| 2136 | } |
| 2137 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2138 | int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2139 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2140 | struct drbd_conf *mdev; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2141 | struct net_conf *old_conf, *new_conf = NULL; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2142 | struct crypto crypto = { }; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2143 | struct drbd_tconn *tconn; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2144 | enum drbd_ret_code retcode; |
| 2145 | int i; |
| 2146 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2147 | |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 2148 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2149 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2150 | if (!adm_ctx.reply_skb) |
| 2151 | return retcode; |
| 2152 | if (retcode != NO_ERROR) |
| 2153 | goto out; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2154 | if (!(adm_ctx.my_addr && adm_ctx.peer_addr)) { |
| 2155 | drbd_msg_put_info("connection endpoint(s) missing"); |
| 2156 | retcode = ERR_INVALID_REQUEST; |
| 2157 | goto out; |
| 2158 | } |
| 2159 | |
| 2160 | /* No need for _rcu here. All reconfiguration is |
| 2161 | * strictly serialized on genl_lock(). We are protected against |
| 2162 | * concurrent reconfiguration/addition/deletion */ |
| 2163 | list_for_each_entry(tconn, &drbd_tconns, all_tconn) { |
| 2164 | if (nla_len(adm_ctx.my_addr) == tconn->my_addr_len && |
| 2165 | !memcmp(nla_data(adm_ctx.my_addr), &tconn->my_addr, tconn->my_addr_len)) { |
| 2166 | retcode = ERR_LOCAL_ADDR; |
| 2167 | goto out; |
| 2168 | } |
| 2169 | |
| 2170 | if (nla_len(adm_ctx.peer_addr) == tconn->peer_addr_len && |
| 2171 | !memcmp(nla_data(adm_ctx.peer_addr), &tconn->peer_addr, tconn->peer_addr_len)) { |
| 2172 | retcode = ERR_PEER_ADDR; |
| 2173 | goto out; |
| 2174 | } |
| 2175 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2176 | |
| 2177 | tconn = adm_ctx.tconn; |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2178 | conn_reconfig_start(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2179 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2180 | if (tconn->cstate > C_STANDALONE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2181 | retcode = ERR_NET_CONFIGURED; |
| 2182 | goto fail; |
| 2183 | } |
| 2184 | |
Andreas Gruenbacher | a209b4a | 2011-08-17 12:43:25 +0200 | [diff] [blame] | 2185 | /* allocation not in the IO path, drbdsetup / netlink process context */ |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 2186 | new_conf = kzalloc(sizeof(*new_conf), GFP_KERNEL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2187 | if (!new_conf) { |
| 2188 | retcode = ERR_NOMEM; |
| 2189 | goto fail; |
| 2190 | } |
| 2191 | |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2192 | set_net_conf_defaults(new_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2193 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2194 | err = net_conf_from_attrs(new_conf, info); |
Lars Ellenberg | 25e4093 | 2011-08-19 10:39:00 +0200 | [diff] [blame] | 2195 | if (err && err != -ENOMSG) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2196 | retcode = ERR_MANDATORY_TAG; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2197 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2198 | goto fail; |
| 2199 | } |
| 2200 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 2201 | retcode = check_net_options(tconn, new_conf); |
| 2202 | if (retcode != NO_ERROR) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2203 | goto fail; |
Philipp Reisner | 47ff2d0 | 2010-06-18 13:56:57 +0200 | [diff] [blame] | 2204 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2205 | retcode = alloc_crypto(&crypto, new_conf); |
| 2206 | if (retcode != NO_ERROR) |
Philipp Reisner | 422028b | 2010-10-27 11:12:07 +0200 | [diff] [blame] | 2207 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2208 | |
| 2209 | ((char *)new_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0; |
| 2210 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2211 | conn_flush_workqueue(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2212 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2213 | mutex_lock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2214 | old_conf = tconn->net_conf; |
| 2215 | if (old_conf) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2216 | retcode = ERR_NET_CONFIGURED; |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2217 | mutex_unlock(&tconn->conf_update); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2218 | goto fail; |
| 2219 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2220 | rcu_assign_pointer(tconn->net_conf, new_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2221 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2222 | conn_free_crypto(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2223 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 2224 | tconn->integrity_tfm = crypto.integrity_tfm; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2225 | tconn->csums_tfm = crypto.csums_tfm; |
| 2226 | tconn->verify_tfm = crypto.verify_tfm; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2227 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2228 | tconn->my_addr_len = nla_len(adm_ctx.my_addr); |
| 2229 | memcpy(&tconn->my_addr, nla_data(adm_ctx.my_addr), tconn->my_addr_len); |
| 2230 | tconn->peer_addr_len = nla_len(adm_ctx.peer_addr); |
| 2231 | memcpy(&tconn->peer_addr, nla_data(adm_ctx.peer_addr), tconn->peer_addr_len); |
| 2232 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2233 | mutex_unlock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2234 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 2235 | rcu_read_lock(); |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2236 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 2237 | mdev->send_cnt = 0; |
| 2238 | mdev->recv_cnt = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2239 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 2240 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2241 | |
Lars Ellenberg | 5ee743e | 2011-04-26 16:22:25 +0200 | [diff] [blame] | 2242 | retcode = conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2243 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2244 | conn_reconfig_done(tconn); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2245 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2246 | return 0; |
| 2247 | |
| 2248 | fail: |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2249 | free_crypto(&crypto); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2250 | kfree(new_conf); |
| 2251 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2252 | conn_reconfig_done(tconn); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2253 | out: |
| 2254 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2255 | return 0; |
| 2256 | } |
| 2257 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2258 | static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool force) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2259 | { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2260 | enum drbd_state_rv rv; |
Philipp Reisner | 2561b9c | 2010-12-03 15:22:48 +0100 | [diff] [blame] | 2261 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2262 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), |
| 2263 | force ? CS_HARD : 0); |
Philipp Reisner | 2561b9c | 2010-12-03 15:22:48 +0100 | [diff] [blame] | 2264 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2265 | switch (rv) { |
| 2266 | case SS_NOTHING_TO_DO: |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2267 | break; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2268 | case SS_ALREADY_STANDALONE: |
| 2269 | return SS_SUCCESS; |
| 2270 | case SS_PRIMARY_NOP: |
| 2271 | /* Our state checking code wants to see the peer outdated. */ |
Philipp Reisner | 2bd5ed5d | 2013-03-27 14:08:40 +0100 | [diff] [blame] | 2272 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, pdsk, D_OUTDATED), 0); |
| 2273 | |
| 2274 | if (rv == SS_OUTDATE_WO_CONN) /* lost connection before graceful disconnect succeeded */ |
| 2275 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_VERBOSE); |
| 2276 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2277 | break; |
| 2278 | case SS_CW_FAILED_BY_PEER: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2279 | /* The peer probably wants to see us outdated. */ |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2280 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, |
| 2281 | disk, D_OUTDATED), 0); |
| 2282 | if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) { |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2283 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), |
| 2284 | CS_HARD); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2285 | } |
| 2286 | break; |
| 2287 | default:; |
| 2288 | /* no special handling necessary */ |
| 2289 | } |
| 2290 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2291 | if (rv >= SS_SUCCESS) { |
| 2292 | enum drbd_state_rv rv2; |
| 2293 | /* No one else can reconfigure the network while I am here. |
| 2294 | * The state handling only uses drbd_thread_stop_nowait(), |
| 2295 | * we want to really wait here until the receiver is no more. |
| 2296 | */ |
| 2297 | drbd_thread_stop(&adm_ctx.tconn->receiver); |
| 2298 | |
| 2299 | /* Race breaker. This additional state change request may be |
| 2300 | * necessary, if this was a forced disconnect during a receiver |
| 2301 | * restart. We may have "killed" the receiver thread just |
| 2302 | * after drbdd_init() returned. Typically, we should be |
| 2303 | * C_STANDALONE already, now, and this becomes a no-op. |
| 2304 | */ |
| 2305 | rv2 = conn_request_state(tconn, NS(conn, C_STANDALONE), |
| 2306 | CS_VERBOSE | CS_HARD); |
| 2307 | if (rv2 < SS_SUCCESS) |
| 2308 | conn_err(tconn, |
| 2309 | "unexpected rv2=%d in conn_try_disconnect()\n", |
| 2310 | rv2); |
| 2311 | } |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2312 | return rv; |
| 2313 | } |
| 2314 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2315 | int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2316 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2317 | struct disconnect_parms parms; |
| 2318 | struct drbd_tconn *tconn; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2319 | enum drbd_state_rv rv; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2320 | enum drbd_ret_code retcode; |
| 2321 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2322 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2323 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2324 | if (!adm_ctx.reply_skb) |
| 2325 | return retcode; |
| 2326 | if (retcode != NO_ERROR) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2327 | goto fail; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2328 | |
| 2329 | tconn = adm_ctx.tconn; |
| 2330 | memset(&parms, 0, sizeof(parms)); |
| 2331 | if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2332 | err = disconnect_parms_from_attrs(&parms, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2333 | if (err) { |
| 2334 | retcode = ERR_MANDATORY_TAG; |
| 2335 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2336 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2340 | rv = conn_try_disconnect(tconn, parms.force_disconnect); |
| 2341 | if (rv < SS_SUCCESS) |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2342 | retcode = rv; /* FIXME: Type mismatch. */ |
| 2343 | else |
| 2344 | retcode = NO_ERROR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2345 | fail: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2346 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | void resync_after_online_grow(struct drbd_conf *mdev) |
| 2351 | { |
| 2352 | int iass; /* I am sync source */ |
| 2353 | |
| 2354 | dev_info(DEV, "Resync of new storage after online grow\n"); |
| 2355 | if (mdev->state.role != mdev->state.peer) |
| 2356 | iass = (mdev->state.role == R_PRIMARY); |
| 2357 | else |
Lars Ellenberg | 427c043 | 2012-08-01 12:43:01 +0200 | [diff] [blame] | 2358 | iass = test_bit(RESOLVE_CONFLICTS, &mdev->tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2359 | |
| 2360 | if (iass) |
| 2361 | drbd_start_resync(mdev, C_SYNC_SOURCE); |
| 2362 | else |
| 2363 | _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE); |
| 2364 | } |
| 2365 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2366 | int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2367 | { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2368 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2369 | struct resize_parms rs; |
| 2370 | struct drbd_conf *mdev; |
| 2371 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2372 | enum determine_dev_size dd; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2373 | bool change_al_layout = false; |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2374 | enum dds_flags ddsf; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2375 | sector_t u_size; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2376 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2377 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2378 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2379 | if (!adm_ctx.reply_skb) |
| 2380 | return retcode; |
| 2381 | if (retcode != NO_ERROR) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2382 | goto fail; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2383 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2384 | mdev = adm_ctx.mdev; |
| 2385 | if (!get_ldev(mdev)) { |
| 2386 | retcode = ERR_NO_DISK; |
| 2387 | goto fail; |
| 2388 | } |
| 2389 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2390 | memset(&rs, 0, sizeof(struct resize_parms)); |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2391 | rs.al_stripes = mdev->ldev->md.al_stripes; |
| 2392 | rs.al_stripe_size = mdev->ldev->md.al_stripe_size_4k * 4; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2393 | if (info->attrs[DRBD_NLA_RESIZE_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2394 | err = resize_parms_from_attrs(&rs, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2395 | if (err) { |
| 2396 | retcode = ERR_MANDATORY_TAG; |
| 2397 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2398 | goto fail_ldev; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2399 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | if (mdev->state.conn > C_CONNECTED) { |
| 2403 | retcode = ERR_RESIZE_RESYNC; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2404 | goto fail_ldev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | if (mdev->state.role == R_SECONDARY && |
| 2408 | mdev->state.peer == R_SECONDARY) { |
| 2409 | retcode = ERR_NO_PRIMARY; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2410 | goto fail_ldev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2413 | if (rs.no_resync && mdev->tconn->agreed_pro_version < 93) { |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2414 | retcode = ERR_NEED_APV_93; |
Andreas Gruenbacher | 7b4e4d3 | 2011-09-28 22:15:04 +0200 | [diff] [blame] | 2415 | goto fail_ldev; |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2416 | } |
| 2417 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2418 | rcu_read_lock(); |
| 2419 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; |
| 2420 | rcu_read_unlock(); |
| 2421 | if (u_size != (sector_t)rs.resize_size) { |
| 2422 | new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 2423 | if (!new_disk_conf) { |
| 2424 | retcode = ERR_NOMEM; |
Philipp Reisner | 9bcd252 | 2011-09-29 13:00:14 +0200 | [diff] [blame] | 2425 | goto fail_ldev; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2429 | if (mdev->ldev->md.al_stripes != rs.al_stripes || |
| 2430 | mdev->ldev->md.al_stripe_size_4k != rs.al_stripe_size / 4) { |
| 2431 | u32 al_size_k = rs.al_stripes * rs.al_stripe_size; |
| 2432 | |
| 2433 | if (al_size_k > (16 * 1024 * 1024)) { |
| 2434 | retcode = ERR_MD_LAYOUT_TOO_BIG; |
| 2435 | goto fail_ldev; |
| 2436 | } |
| 2437 | |
| 2438 | if (al_size_k < MD_32kB_SECT/2) { |
| 2439 | retcode = ERR_MD_LAYOUT_TOO_SMALL; |
| 2440 | goto fail_ldev; |
| 2441 | } |
| 2442 | |
| 2443 | if (mdev->state.conn != C_CONNECTED) { |
| 2444 | retcode = ERR_MD_LAYOUT_CONNECTED; |
| 2445 | goto fail_ldev; |
| 2446 | } |
| 2447 | |
| 2448 | change_al_layout = true; |
| 2449 | } |
| 2450 | |
Philipp Reisner | 087c249 | 2010-03-26 13:49:56 +0100 | [diff] [blame] | 2451 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2452 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2453 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2454 | if (new_disk_conf) { |
| 2455 | mutex_lock(&mdev->tconn->conf_update); |
| 2456 | old_disk_conf = mdev->ldev->disk_conf; |
| 2457 | *new_disk_conf = *old_disk_conf; |
| 2458 | new_disk_conf->disk_size = (sector_t)rs.resize_size; |
| 2459 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); |
| 2460 | mutex_unlock(&mdev->tconn->conf_update); |
| 2461 | synchronize_rcu(); |
| 2462 | kfree(old_disk_conf); |
| 2463 | } |
| 2464 | |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2465 | ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0); |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2466 | dd = drbd_determine_dev_size(mdev, ddsf, change_al_layout ? &rs : NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2467 | drbd_md_sync(mdev); |
| 2468 | put_ldev(mdev); |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 2469 | if (dd == DS_ERROR) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2470 | retcode = ERR_NOMEM_BITMAP; |
| 2471 | goto fail; |
Philipp Reisner | d752b26 | 2013-06-25 16:50:08 +0200 | [diff] [blame] | 2472 | } else if (dd == DS_ERROR_SPACE_MD) { |
| 2473 | retcode = ERR_MD_LAYOUT_NO_FIT; |
| 2474 | goto fail; |
| 2475 | } else if (dd == DS_ERROR_SHRINK) { |
| 2476 | retcode = ERR_IMPLICIT_SHRINK; |
| 2477 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Philipp Reisner | 087c249 | 2010-03-26 13:49:56 +0100 | [diff] [blame] | 2480 | if (mdev->state.conn == C_CONNECTED) { |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 2481 | if (dd == DS_GREW) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2482 | set_bit(RESIZE_PENDING, &mdev->flags); |
| 2483 | |
| 2484 | drbd_send_uuids(mdev); |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2485 | drbd_send_sizes(mdev, 1, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | fail: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2489 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2490 | return 0; |
Andreas Gruenbacher | 7b4e4d3 | 2011-09-28 22:15:04 +0200 | [diff] [blame] | 2491 | |
| 2492 | fail_ldev: |
| 2493 | put_ldev(mdev); |
| 2494 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2497 | int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2498 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2499 | enum drbd_ret_code retcode; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2500 | struct drbd_tconn *tconn; |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2501 | struct res_opts res_opts; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2502 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2503 | |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 2504 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2505 | if (!adm_ctx.reply_skb) |
| 2506 | return retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2507 | if (retcode != NO_ERROR) |
| 2508 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2509 | tconn = adm_ctx.tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2510 | |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2511 | res_opts = tconn->res_opts; |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 2512 | if (should_set_defaults(info)) |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2513 | set_res_opts_defaults(&res_opts); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2514 | |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2515 | err = res_opts_from_attrs(&res_opts, info); |
Andreas Gruenbacher | c75b9b1 | 2011-05-24 14:18:31 +0200 | [diff] [blame] | 2516 | if (err && err != -ENOMSG) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2517 | retcode = ERR_MANDATORY_TAG; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2518 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2519 | goto fail; |
| 2520 | } |
| 2521 | |
Andreas Gruenbacher | afbbfa8 | 2011-06-16 17:58:02 +0200 | [diff] [blame] | 2522 | err = set_resource_options(tconn, &res_opts); |
| 2523 | if (err) { |
| 2524 | retcode = ERR_INVALID_REQUEST; |
| 2525 | if (err == -ENOMEM) |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 2526 | retcode = ERR_NOMEM; |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 2527 | } |
| 2528 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2529 | fail: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2530 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2531 | return 0; |
| 2532 | } |
| 2533 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2534 | int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2535 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2536 | struct drbd_conf *mdev; |
| 2537 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
| 2538 | |
| 2539 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2540 | if (!adm_ctx.reply_skb) |
| 2541 | return retcode; |
| 2542 | if (retcode != NO_ERROR) |
| 2543 | goto out; |
| 2544 | |
| 2545 | mdev = adm_ctx.mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2546 | |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2547 | /* If there is still bitmap IO pending, probably because of a previous |
Lars Ellenberg | 7ee1fb9 | 2012-06-19 10:27:58 +0200 | [diff] [blame] | 2548 | * resync just being finished, wait for it before requesting a new resync. |
| 2549 | * Also wait for it's after_state_ch(). */ |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 2550 | drbd_suspend_io(mdev); |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2551 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
Lars Ellenberg | 7ee1fb9 | 2012-06-19 10:27:58 +0200 | [diff] [blame] | 2552 | drbd_flush_workqueue(mdev); |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2553 | |
Philipp Reisner | 0b2dafc | 2013-03-27 14:08:38 +0100 | [diff] [blame] | 2554 | /* If we happen to be C_STANDALONE R_SECONDARY, just change to |
| 2555 | * D_INCONSISTENT, and set all bits in the bitmap. Otherwise, |
| 2556 | * try to start a resync handshake as sync target for full sync. |
Philipp Reisner | 9376d9f | 2013-03-27 14:08:36 +0100 | [diff] [blame] | 2557 | */ |
Philipp Reisner | 0b2dafc | 2013-03-27 14:08:38 +0100 | [diff] [blame] | 2558 | if (mdev->state.conn == C_STANDALONE && mdev->state.role == R_SECONDARY) { |
| 2559 | retcode = drbd_request_state(mdev, NS(disk, D_INCONSISTENT)); |
| 2560 | if (retcode >= SS_SUCCESS) { |
| 2561 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, |
| 2562 | "set_n_write from invalidate", BM_LOCKED_MASK)) |
| 2563 | retcode = ERR_IO_MD_DISK; |
| 2564 | } |
| 2565 | } else |
| 2566 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T)); |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 2567 | drbd_resume_io(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2568 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2569 | out: |
| 2570 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2571 | return 0; |
| 2572 | } |
| 2573 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2574 | static int drbd_adm_simple_request_state(struct sk_buff *skb, struct genl_info *info, |
| 2575 | union drbd_state mask, union drbd_state val) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2576 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2577 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2578 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2579 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2580 | if (!adm_ctx.reply_skb) |
| 2581 | return retcode; |
| 2582 | if (retcode != NO_ERROR) |
| 2583 | goto out; |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2584 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2585 | retcode = drbd_request_state(adm_ctx.mdev, mask, val); |
| 2586 | out: |
| 2587 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | static int drbd_bmio_set_susp_al(struct drbd_conf *mdev) |
| 2592 | { |
| 2593 | int rv; |
| 2594 | |
| 2595 | rv = drbd_bmio_set_n_write(mdev); |
| 2596 | drbd_suspend_al(mdev); |
| 2597 | return rv; |
| 2598 | } |
| 2599 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2600 | int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2601 | { |
Philipp Reisner | 25b0d6c | 2012-02-14 12:12:35 +0100 | [diff] [blame] | 2602 | int retcode; /* drbd_ret_code, drbd_state_rv */ |
| 2603 | struct drbd_conf *mdev; |
| 2604 | |
| 2605 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2606 | if (!adm_ctx.reply_skb) |
| 2607 | return retcode; |
| 2608 | if (retcode != NO_ERROR) |
| 2609 | goto out; |
| 2610 | |
| 2611 | mdev = adm_ctx.mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2612 | |
| 2613 | /* If there is still bitmap IO pending, probably because of a previous |
Lars Ellenberg | 7ee1fb9 | 2012-06-19 10:27:58 +0200 | [diff] [blame] | 2614 | * resync just being finished, wait for it before requesting a new resync. |
| 2615 | * Also wait for it's after_state_ch(). */ |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 2616 | drbd_suspend_io(mdev); |
Lars Ellenberg | 5016b82 | 2012-05-07 12:00:56 +0200 | [diff] [blame] | 2617 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
Lars Ellenberg | 7ee1fb9 | 2012-06-19 10:27:58 +0200 | [diff] [blame] | 2618 | drbd_flush_workqueue(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2619 | |
Philipp Reisner | 0b2dafc | 2013-03-27 14:08:38 +0100 | [diff] [blame] | 2620 | /* If we happen to be C_STANDALONE R_PRIMARY, just set all bits |
| 2621 | * in the bitmap. Otherwise, try to start a resync handshake |
| 2622 | * as sync source for full sync. |
| 2623 | */ |
| 2624 | if (mdev->state.conn == C_STANDALONE && mdev->state.role == R_PRIMARY) { |
| 2625 | /* The peer will get a resync upon connect anyways. Just make that |
| 2626 | into a full resync. */ |
| 2627 | retcode = drbd_request_state(mdev, NS(pdsk, D_INCONSISTENT)); |
| 2628 | if (retcode >= SS_SUCCESS) { |
| 2629 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_susp_al, |
| 2630 | "set_n_write from invalidate_peer", |
| 2631 | BM_LOCKED_SET_ALLOWED)) |
| 2632 | retcode = ERR_IO_MD_DISK; |
| 2633 | } |
| 2634 | } else |
| 2635 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S)); |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 2636 | drbd_resume_io(mdev); |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 2637 | |
Philipp Reisner | 25b0d6c | 2012-02-14 12:12:35 +0100 | [diff] [blame] | 2638 | out: |
| 2639 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2640 | return 0; |
| 2641 | } |
| 2642 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2643 | int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2644 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2645 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2646 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2647 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2648 | if (!adm_ctx.reply_skb) |
| 2649 | return retcode; |
| 2650 | if (retcode != NO_ERROR) |
| 2651 | goto out; |
| 2652 | |
| 2653 | if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 1)) == SS_NOTHING_TO_DO) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2654 | retcode = ERR_PAUSE_IS_SET; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2655 | out: |
| 2656 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2657 | return 0; |
| 2658 | } |
| 2659 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2660 | int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2661 | { |
Philipp Reisner | da9fbc2 | 2011-03-29 10:52:01 +0200 | [diff] [blame] | 2662 | union drbd_dev_state s; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2663 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2664 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2665 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2666 | if (!adm_ctx.reply_skb) |
| 2667 | return retcode; |
| 2668 | if (retcode != NO_ERROR) |
| 2669 | goto out; |
| 2670 | |
| 2671 | if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 0)) == SS_NOTHING_TO_DO) { |
| 2672 | s = adm_ctx.mdev->state; |
Philipp Reisner | cd88d03 | 2011-01-20 11:46:41 +0100 | [diff] [blame] | 2673 | if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) { |
| 2674 | retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP : |
| 2675 | s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR; |
| 2676 | } else { |
| 2677 | retcode = ERR_PAUSE_IS_CLEAR; |
| 2678 | } |
| 2679 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2680 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2681 | out: |
| 2682 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2683 | return 0; |
| 2684 | } |
| 2685 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2686 | int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2687 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2688 | return drbd_adm_simple_request_state(skb, info, NS(susp, 1)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2691 | int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2692 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2693 | struct drbd_conf *mdev; |
| 2694 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
| 2695 | |
| 2696 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2697 | if (!adm_ctx.reply_skb) |
| 2698 | return retcode; |
| 2699 | if (retcode != NO_ERROR) |
| 2700 | goto out; |
| 2701 | |
| 2702 | mdev = adm_ctx.mdev; |
Philipp Reisner | 43a5182 | 2010-06-11 11:26:34 +0200 | [diff] [blame] | 2703 | if (test_bit(NEW_CUR_UUID, &mdev->flags)) { |
| 2704 | drbd_uuid_new_current(mdev); |
| 2705 | clear_bit(NEW_CUR_UUID, &mdev->flags); |
Philipp Reisner | 43a5182 | 2010-06-11 11:26:34 +0200 | [diff] [blame] | 2706 | } |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2707 | drbd_suspend_io(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2708 | retcode = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0)); |
| 2709 | if (retcode == SS_SUCCESS) { |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2710 | if (mdev->state.conn < C_CONNECTED) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 2711 | tl_clear(mdev->tconn); |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2712 | if (mdev->state.disk == D_DISKLESS || mdev->state.disk == D_FAILED) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 2713 | tl_restart(mdev->tconn, FAIL_FROZEN_DISK_IO); |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2714 | } |
| 2715 | drbd_resume_io(mdev); |
| 2716 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2717 | out: |
| 2718 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2719 | return 0; |
| 2720 | } |
| 2721 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2722 | int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2723 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2724 | return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2727 | int nla_put_drbd_cfg_context(struct sk_buff *skb, struct drbd_tconn *tconn, unsigned vnr) |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2728 | { |
| 2729 | struct nlattr *nla; |
| 2730 | nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT); |
| 2731 | if (!nla) |
| 2732 | goto nla_put_failure; |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2733 | if (vnr != VOLUME_UNSPECIFIED && |
| 2734 | nla_put_u32(skb, T_ctx_volume, 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; |
| 2741 | if (tconn->peer_addr_len && |
| 2742 | nla_put(skb, T_ctx_peer_addr, tconn->peer_addr_len, &tconn->peer_addr)) |
| 2743 | goto nla_put_failure; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2744 | nla_nest_end(skb, nla); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2745 | return 0; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2746 | |
| 2747 | nla_put_failure: |
| 2748 | if (nla) |
| 2749 | nla_nest_cancel(skb, nla); |
| 2750 | return -EMSGSIZE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2753 | int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, |
| 2754 | const struct sib_info *sib) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2755 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2756 | struct state_info *si = NULL; /* for sizeof(si->member); */ |
| 2757 | struct nlattr *nla; |
| 2758 | int got_ldev; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2759 | int err = 0; |
| 2760 | int exclude_sensitive; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2761 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2762 | /* If sib != NULL, this is drbd_bcast_event, which anyone can listen |
| 2763 | * to. So we better exclude_sensitive information. |
| 2764 | * |
| 2765 | * If sib == NULL, this is drbd_adm_get_status, executed synchronously |
| 2766 | * in the context of the requesting user process. Exclude sensitive |
| 2767 | * information, unless current has superuser. |
| 2768 | * |
| 2769 | * NOTE: for drbd_adm_get_status_all(), this is a netlink dump, and |
| 2770 | * relies on the current implementation of netlink_dump(), which |
| 2771 | * executes the dump callback successively from netlink_recvmsg(), |
| 2772 | * always in the context of the receiving process */ |
| 2773 | exclude_sensitive = sib || !capable(CAP_SYS_ADMIN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2774 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2775 | got_ldev = get_ldev(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2776 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2777 | /* We need to add connection name and volume number information still. |
| 2778 | * Minor number is in drbd_genlmsghdr. */ |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2779 | if (nla_put_drbd_cfg_context(skb, mdev->tconn, mdev->vnr)) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2780 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2781 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2782 | if (res_opts_to_skb(skb, &mdev->tconn->res_opts, exclude_sensitive)) |
| 2783 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2784 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2785 | rcu_read_lock(); |
Andreas Gruenbacher | f9eb7bf | 2013-06-25 16:50:05 +0200 | [diff] [blame] | 2786 | if (got_ldev) { |
| 2787 | struct disk_conf *disk_conf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2788 | |
Andreas Gruenbacher | f9eb7bf | 2013-06-25 16:50:05 +0200 | [diff] [blame] | 2789 | disk_conf = rcu_dereference(mdev->ldev->disk_conf); |
| 2790 | err = disk_conf_to_skb(skb, disk_conf, exclude_sensitive); |
| 2791 | } |
| 2792 | if (!err) { |
| 2793 | struct net_conf *nc; |
| 2794 | |
| 2795 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 2796 | if (nc) |
| 2797 | err = net_conf_to_skb(skb, nc, exclude_sensitive); |
| 2798 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2799 | rcu_read_unlock(); |
| 2800 | if (err) |
| 2801 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2802 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2803 | nla = nla_nest_start(skb, DRBD_NLA_STATE_INFO); |
| 2804 | if (!nla) |
| 2805 | goto nla_put_failure; |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2806 | 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) || |
| 2808 | nla_put_u64(skb, T_ed_uuid, mdev->ed_uuid) || |
Philipp Marek | 3174f8c | 2012-03-03 21:04:30 +0100 | [diff] [blame] | 2809 | nla_put_u64(skb, T_capacity, drbd_get_capacity(mdev->this_bdev)) || |
| 2810 | nla_put_u64(skb, T_send_cnt, mdev->send_cnt) || |
| 2811 | nla_put_u64(skb, T_recv_cnt, mdev->recv_cnt) || |
| 2812 | nla_put_u64(skb, T_read_cnt, mdev->read_cnt) || |
| 2813 | nla_put_u64(skb, T_writ_cnt, mdev->writ_cnt) || |
| 2814 | nla_put_u64(skb, T_al_writ_cnt, mdev->al_writ_cnt) || |
| 2815 | nla_put_u64(skb, T_bm_writ_cnt, mdev->bm_writ_cnt) || |
| 2816 | nla_put_u32(skb, T_ap_bio_cnt, atomic_read(&mdev->ap_bio_cnt)) || |
| 2817 | nla_put_u32(skb, T_ap_pending_cnt, atomic_read(&mdev->ap_pending_cnt)) || |
| 2818 | nla_put_u32(skb, T_rs_pending_cnt, atomic_read(&mdev->rs_pending_cnt))) |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2819 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2820 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2821 | if (got_ldev) { |
Philipp Reisner | 39a1aa7 | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 2822 | int err; |
| 2823 | |
| 2824 | spin_lock_irq(&mdev->ldev->md.uuid_lock); |
| 2825 | err = nla_put(skb, T_uuids, sizeof(si->uuids), mdev->ldev->md.uuid); |
| 2826 | spin_unlock_irq(&mdev->ldev->md.uuid_lock); |
| 2827 | |
| 2828 | if (err) |
| 2829 | goto nla_put_failure; |
| 2830 | |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2831 | if (nla_put_u32(skb, T_disk_flags, mdev->ldev->md.flags) || |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2832 | nla_put_u64(skb, T_bits_total, drbd_bm_bits(mdev)) || |
| 2833 | nla_put_u64(skb, T_bits_oos, drbd_bm_total_weight(mdev))) |
| 2834 | goto nla_put_failure; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2835 | if (C_SYNC_SOURCE <= mdev->state.conn && |
| 2836 | C_PAUSED_SYNC_T >= mdev->state.conn) { |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2837 | if (nla_put_u64(skb, T_bits_rs_total, mdev->rs_total) || |
| 2838 | nla_put_u64(skb, T_bits_rs_failed, mdev->rs_failed)) |
| 2839 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2840 | } |
| 2841 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2842 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2843 | if (sib) { |
| 2844 | switch(sib->sib_reason) { |
| 2845 | case SIB_SYNC_PROGRESS: |
| 2846 | case SIB_GET_STATUS_REPLY: |
| 2847 | break; |
| 2848 | case SIB_STATE_CHANGE: |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2849 | if (nla_put_u32(skb, T_prev_state, sib->os.i) || |
| 2850 | nla_put_u32(skb, T_new_state, sib->ns.i)) |
| 2851 | goto nla_put_failure; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2852 | break; |
| 2853 | case SIB_HELPER_POST: |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2854 | if (nla_put_u32(skb, T_helper_exit_code, |
| 2855 | sib->helper_exit_code)) |
| 2856 | goto nla_put_failure; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2857 | /* fall through */ |
| 2858 | case SIB_HELPER_PRE: |
Andreas Gruenbacher | 26ec928 | 2012-07-11 20:36:03 +0200 | [diff] [blame] | 2859 | if (nla_put_string(skb, T_helper, sib->helper_name)) |
| 2860 | goto nla_put_failure; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2861 | break; |
| 2862 | } |
| 2863 | } |
| 2864 | nla_nest_end(skb, nla); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2865 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2866 | if (0) |
| 2867 | nla_put_failure: |
| 2868 | err = -EMSGSIZE; |
| 2869 | if (got_ldev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2870 | put_ldev(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2871 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2874 | int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2875 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2876 | enum drbd_ret_code retcode; |
| 2877 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2878 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2879 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2880 | if (!adm_ctx.reply_skb) |
| 2881 | return retcode; |
| 2882 | if (retcode != NO_ERROR) |
| 2883 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2884 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2885 | err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.mdev, NULL); |
| 2886 | if (err) { |
| 2887 | nlmsg_free(adm_ctx.reply_skb); |
| 2888 | return err; |
| 2889 | } |
| 2890 | out: |
| 2891 | drbd_adm_finish(info, retcode); |
| 2892 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2895 | int get_one_status(struct sk_buff *skb, struct netlink_callback *cb) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2896 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2897 | struct drbd_conf *mdev; |
| 2898 | struct drbd_genlmsghdr *dh; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2899 | struct drbd_tconn *pos = (struct drbd_tconn*)cb->args[0]; |
| 2900 | struct drbd_tconn *tconn = NULL; |
| 2901 | struct drbd_tconn *tmp; |
| 2902 | unsigned volume = cb->args[1]; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2903 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2904 | /* Open coded, deferred, iteration: |
| 2905 | * list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) { |
| 2906 | * idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 2907 | * ... |
| 2908 | * } |
| 2909 | * } |
| 2910 | * where tconn is cb->args[0]; |
| 2911 | * and i is cb->args[1]; |
| 2912 | * |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2913 | * cb->args[2] indicates if we shall loop over all resources, |
| 2914 | * or just dump all volumes of a single resource. |
| 2915 | * |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2916 | * This may miss entries inserted after this dump started, |
| 2917 | * or entries deleted before they are reached. |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2918 | * |
| 2919 | * We need to make sure the mdev won't disappear while |
| 2920 | * we are looking at it, and revalidate our iterators |
| 2921 | * on each iteration. |
| 2922 | */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2923 | |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 2924 | /* synchronize with conn_create()/conn_destroy() */ |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 2925 | rcu_read_lock(); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2926 | /* revalidate iterator position */ |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 2927 | list_for_each_entry_rcu(tmp, &drbd_tconns, all_tconn) { |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2928 | if (pos == NULL) { |
| 2929 | /* first iteration */ |
| 2930 | pos = tmp; |
| 2931 | tconn = pos; |
| 2932 | break; |
| 2933 | } |
| 2934 | if (tmp == pos) { |
| 2935 | tconn = pos; |
| 2936 | break; |
| 2937 | } |
| 2938 | } |
| 2939 | if (tconn) { |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2940 | next_tconn: |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2941 | mdev = idr_get_next(&tconn->volumes, &volume); |
| 2942 | if (!mdev) { |
| 2943 | /* No more volumes to dump on this tconn. |
| 2944 | * Advance tconn iterator. */ |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 2945 | pos = list_entry_rcu(tconn->all_tconn.next, |
| 2946 | struct drbd_tconn, all_tconn); |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2947 | /* Did we dump any volume on this tconn yet? */ |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2948 | if (volume != 0) { |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2949 | /* If we reached the end of the list, |
| 2950 | * or only a single resource dump was requested, |
| 2951 | * we are done. */ |
| 2952 | if (&pos->all_tconn == &drbd_tconns || cb->args[2]) |
| 2953 | goto out; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2954 | volume = 0; |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2955 | tconn = pos; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2956 | goto next_tconn; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Philipp Reisner | 9868365 | 2012-11-09 14:18:43 +0100 | [diff] [blame] | 2960 | dh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2961 | cb->nlh->nlmsg_seq, &drbd_genl_family, |
| 2962 | NLM_F_MULTI, DRBD_ADM_GET_STATUS); |
| 2963 | if (!dh) |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2964 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2965 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2966 | if (!mdev) { |
Lars Ellenberg | 367d675d | 2011-07-11 23:49:55 +0200 | [diff] [blame] | 2967 | /* This is a tconn without a single volume. |
| 2968 | * Suprisingly enough, it may have a network |
| 2969 | * configuration. */ |
| 2970 | struct net_conf *nc; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2971 | dh->minor = -1U; |
| 2972 | dh->ret_code = NO_ERROR; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 2973 | if (nla_put_drbd_cfg_context(skb, tconn, VOLUME_UNSPECIFIED)) |
Lars Ellenberg | 367d675d | 2011-07-11 23:49:55 +0200 | [diff] [blame] | 2974 | goto cancel; |
| 2975 | nc = rcu_dereference(tconn->net_conf); |
| 2976 | if (nc && net_conf_to_skb(skb, nc, 1) != 0) |
| 2977 | goto cancel; |
| 2978 | goto done; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2979 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2980 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2981 | D_ASSERT(mdev->vnr == volume); |
| 2982 | D_ASSERT(mdev->tconn == tconn); |
| 2983 | |
| 2984 | dh->minor = mdev_to_minor(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2985 | dh->ret_code = NO_ERROR; |
| 2986 | |
| 2987 | if (nla_put_status_info(skb, mdev, NULL)) { |
Lars Ellenberg | 367d675d | 2011-07-11 23:49:55 +0200 | [diff] [blame] | 2988 | cancel: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2989 | genlmsg_cancel(skb, dh); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2990 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2991 | } |
Lars Ellenberg | 367d675d | 2011-07-11 23:49:55 +0200 | [diff] [blame] | 2992 | done: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2993 | genlmsg_end(skb, dh); |
| 2994 | } |
| 2995 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2996 | out: |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 2997 | rcu_read_unlock(); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2998 | /* where to start the next iteration */ |
| 2999 | cb->args[0] = (long)pos; |
| 3000 | cb->args[1] = (pos == tconn) ? volume + 1 : 0; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3001 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 3002 | /* No more tconns/volumes/minors found results in an empty skb. |
| 3003 | * Which will terminate the dump. */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3004 | return skb->len; |
| 3005 | } |
| 3006 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3007 | /* |
| 3008 | * Request status of all resources, or of all volumes within a single resource. |
| 3009 | * |
| 3010 | * This is a dump, as the answer may not fit in a single reply skb otherwise. |
| 3011 | * Which means we cannot use the family->attrbuf or other such members, because |
| 3012 | * dump is NOT protected by the genl_lock(). During dump, we only have access |
| 3013 | * to the incoming skb, and need to opencode "parsing" of the nlattr payload. |
| 3014 | * |
| 3015 | * Once things are setup properly, we call into get_one_status(). |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3016 | */ |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3017 | int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3018 | { |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3019 | const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ; |
| 3020 | struct nlattr *nla; |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3021 | const char *resource_name; |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3022 | struct drbd_tconn *tconn; |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3023 | int maxtype; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3024 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3025 | /* Is this a followup call? */ |
| 3026 | if (cb->args[0]) { |
| 3027 | /* ... of a single resource dump, |
| 3028 | * and the resource iterator has been advanced already? */ |
| 3029 | if (cb->args[2] && cb->args[2] != cb->args[0]) |
| 3030 | return 0; /* DONE. */ |
| 3031 | goto dump; |
| 3032 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3033 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3034 | /* First call (from netlink_dump_start). We need to figure out |
| 3035 | * which resource(s) the user wants us to dump. */ |
| 3036 | nla = nla_find(nlmsg_attrdata(cb->nlh, hdrlen), |
| 3037 | nlmsg_attrlen(cb->nlh, hdrlen), |
| 3038 | DRBD_NLA_CFG_CONTEXT); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3039 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3040 | /* No explicit context given. Dump all. */ |
| 3041 | if (!nla) |
| 3042 | goto dump; |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3043 | maxtype = ARRAY_SIZE(drbd_cfg_context_nl_policy) - 1; |
| 3044 | nla = drbd_nla_find_nested(maxtype, nla, __nla_type(T_ctx_resource_name)); |
| 3045 | if (IS_ERR(nla)) |
| 3046 | return PTR_ERR(nla); |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3047 | /* context given, but no name present? */ |
| 3048 | if (!nla) |
| 3049 | return -EINVAL; |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3050 | resource_name = nla_data(nla); |
| 3051 | tconn = conn_get_by_name(resource_name); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3052 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3053 | if (!tconn) |
| 3054 | return -ENODEV; |
| 3055 | |
Philipp Reisner | 0ace9df | 2011-04-24 10:53:19 +0200 | [diff] [blame] | 3056 | kref_put(&tconn->kref, &conn_destroy); /* get_one_status() (re)validates tconn by itself */ |
| 3057 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 3058 | /* prime iterators, and set "filter" mode mark: |
| 3059 | * only dump this tconn. */ |
| 3060 | cb->args[0] = (long)tconn; |
| 3061 | /* cb->args[1] = 0; passed in this way. */ |
| 3062 | cb->args[2] = (long)tconn; |
| 3063 | |
| 3064 | dump: |
| 3065 | return get_one_status(skb, cb); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3068 | int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3069 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3070 | enum drbd_ret_code retcode; |
| 3071 | struct timeout_parms tp; |
| 3072 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3073 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3074 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 3075 | if (!adm_ctx.reply_skb) |
| 3076 | return retcode; |
| 3077 | if (retcode != NO_ERROR) |
| 3078 | goto out; |
| 3079 | |
| 3080 | tp.timeout_type = |
| 3081 | adm_ctx.mdev->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED : |
| 3082 | test_bit(USE_DEGR_WFC_T, &adm_ctx.mdev->flags) ? UT_DEGRADED : |
| 3083 | UT_DEFAULT; |
| 3084 | |
| 3085 | err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp); |
| 3086 | if (err) { |
| 3087 | nlmsg_free(adm_ctx.reply_skb); |
| 3088 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3089 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3090 | out: |
| 3091 | drbd_adm_finish(info, retcode); |
| 3092 | return 0; |
| 3093 | } |
Lars Ellenberg | 873b0d5 | 2011-01-21 22:53:48 +0100 | [diff] [blame] | 3094 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3095 | int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) |
| 3096 | { |
| 3097 | struct drbd_conf *mdev; |
| 3098 | enum drbd_ret_code retcode; |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 3099 | struct start_ov_parms parms; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3100 | |
| 3101 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 3102 | if (!adm_ctx.reply_skb) |
| 3103 | return retcode; |
| 3104 | if (retcode != NO_ERROR) |
| 3105 | goto out; |
| 3106 | |
| 3107 | mdev = adm_ctx.mdev; |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 3108 | |
| 3109 | /* resume from last known position, if possible */ |
| 3110 | parms.ov_start_sector = mdev->ov_start_sector; |
| 3111 | parms.ov_stop_sector = ULLONG_MAX; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3112 | if (info->attrs[DRBD_NLA_START_OV_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 3113 | int err = start_ov_parms_from_attrs(&parms, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3114 | if (err) { |
| 3115 | retcode = ERR_MANDATORY_TAG; |
| 3116 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 3117 | goto out; |
| 3118 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3119 | } |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 3120 | /* w_make_ov_request expects position to be aligned */ |
| 3121 | mdev->ov_start_sector = parms.ov_start_sector & ~(BM_SECT_PER_BIT-1); |
| 3122 | mdev->ov_stop_sector = parms.ov_stop_sector; |
Lars Ellenberg | 873b0d5 | 2011-01-21 22:53:48 +0100 | [diff] [blame] | 3123 | |
| 3124 | /* 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. */ |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 3126 | drbd_suspend_io(mdev); |
Lars Ellenberg | 873b0d5 | 2011-01-21 22:53:48 +0100 | [diff] [blame] | 3127 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3128 | retcode = drbd_request_state(mdev,NS(conn,C_VERIFY_S)); |
Lars Ellenberg | a574daf | 2012-04-25 16:27:35 +0200 | [diff] [blame] | 3129 | drbd_resume_io(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3130 | out: |
| 3131 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3132 | return 0; |
| 3133 | } |
| 3134 | |
| 3135 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3136 | int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3137 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3138 | struct drbd_conf *mdev; |
| 3139 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3140 | int skip_initial_sync = 0; |
| 3141 | int err; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3142 | struct new_c_uuid_parms args; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3143 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3144 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 3145 | if (!adm_ctx.reply_skb) |
| 3146 | return retcode; |
| 3147 | if (retcode != NO_ERROR) |
| 3148 | goto out_nolock; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3149 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3150 | mdev = adm_ctx.mdev; |
| 3151 | memset(&args, 0, sizeof(args)); |
| 3152 | if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 3153 | err = new_c_uuid_parms_from_attrs(&args, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3154 | if (err) { |
| 3155 | retcode = ERR_MANDATORY_TAG; |
| 3156 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 3157 | goto out_nolock; |
| 3158 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Philipp Reisner | 8410da8f0 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3161 | mutex_lock(mdev->state_mutex); /* Protects us against serialized state changes. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3162 | |
| 3163 | if (!get_ldev(mdev)) { |
| 3164 | retcode = ERR_NO_DISK; |
| 3165 | goto out; |
| 3166 | } |
| 3167 | |
| 3168 | /* this is "skip initial sync", assume to be clean */ |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 3169 | if (mdev->state.conn == C_CONNECTED && mdev->tconn->agreed_pro_version >= 90 && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3170 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) { |
| 3171 | dev_info(DEV, "Preparing to skip initial sync\n"); |
| 3172 | skip_initial_sync = 1; |
| 3173 | } else if (mdev->state.conn != C_STANDALONE) { |
| 3174 | retcode = ERR_CONNECTED; |
| 3175 | goto out_dec; |
| 3176 | } |
| 3177 | |
| 3178 | drbd_uuid_set(mdev, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */ |
| 3179 | drbd_uuid_new_current(mdev); /* New current, previous to UI_BITMAP */ |
| 3180 | |
| 3181 | if (args.clear_bm) { |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3182 | err = drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, |
| 3183 | "clear_n_write from new_c_uuid", BM_LOCKED_MASK); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3184 | if (err) { |
| 3185 | dev_err(DEV, "Writing bitmap failed with %d\n",err); |
| 3186 | retcode = ERR_IO_MD_DISK; |
| 3187 | } |
| 3188 | if (skip_initial_sync) { |
| 3189 | drbd_send_uuids_skip_initial_sync(mdev); |
| 3190 | _drbd_uuid_set(mdev, UI_BITMAP, 0); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3191 | drbd_print_uuids(mdev, "cleared bitmap UUID"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3192 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3193 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
| 3194 | CS_VERBOSE, NULL); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3195 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | drbd_md_sync(mdev); |
| 3200 | out_dec: |
| 3201 | put_ldev(mdev); |
| 3202 | out: |
Philipp Reisner | 8410da8f0 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3203 | mutex_unlock(mdev->state_mutex); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3204 | out_nolock: |
| 3205 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3206 | return 0; |
| 3207 | } |
| 3208 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3209 | static enum drbd_ret_code |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3210 | drbd_check_resource_name(const char *name) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3211 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3212 | if (!name || !name[0]) { |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3213 | drbd_msg_put_info("resource name missing"); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3214 | return ERR_MANDATORY_TAG; |
| 3215 | } |
| 3216 | /* if we want to use these in sysfs/configfs/debugfs some day, |
| 3217 | * we must not allow slashes */ |
| 3218 | if (strchr(name, '/')) { |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3219 | drbd_msg_put_info("invalid resource name"); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3220 | return ERR_INVALID_REQUEST; |
| 3221 | } |
| 3222 | return NO_ERROR; |
| 3223 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3224 | |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3225 | int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3226 | { |
| 3227 | enum drbd_ret_code retcode; |
Andreas Gruenbacher | afbbfa8 | 2011-06-16 17:58:02 +0200 | [diff] [blame] | 3228 | struct res_opts res_opts; |
| 3229 | int err; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3230 | |
| 3231 | retcode = drbd_adm_prepare(skb, info, 0); |
| 3232 | if (!adm_ctx.reply_skb) |
| 3233 | return retcode; |
| 3234 | if (retcode != NO_ERROR) |
| 3235 | goto out; |
| 3236 | |
Andreas Gruenbacher | afbbfa8 | 2011-06-16 17:58:02 +0200 | [diff] [blame] | 3237 | set_res_opts_defaults(&res_opts); |
| 3238 | err = res_opts_from_attrs(&res_opts, info); |
| 3239 | if (err && err != -ENOMSG) { |
| 3240 | retcode = ERR_MANDATORY_TAG; |
| 3241 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 3242 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Andreas Gruenbacher | 7c3063c | 2011-06-09 17:52:12 +0200 | [diff] [blame] | 3245 | retcode = drbd_check_resource_name(adm_ctx.resource_name); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3246 | if (retcode != NO_ERROR) |
| 3247 | goto out; |
| 3248 | |
| 3249 | if (adm_ctx.tconn) { |
Lars Ellenberg | 38f1961 | 2011-03-14 13:22:35 +0100 | [diff] [blame] | 3250 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) { |
| 3251 | retcode = ERR_INVALID_REQUEST; |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3252 | drbd_msg_put_info("resource exists"); |
Lars Ellenberg | 38f1961 | 2011-03-14 13:22:35 +0100 | [diff] [blame] | 3253 | } |
| 3254 | /* else: still NO_ERROR */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3255 | goto out; |
Philipp Reisner | 9f5180e | 2009-10-06 09:30:14 +0200 | [diff] [blame] | 3256 | } |
| 3257 | |
Andreas Gruenbacher | afbbfa8 | 2011-06-16 17:58:02 +0200 | [diff] [blame] | 3258 | if (!conn_create(adm_ctx.resource_name, &res_opts)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3259 | retcode = ERR_NOMEM; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3260 | out: |
| 3261 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3262 | return 0; |
| 3263 | } |
| 3264 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3265 | int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3266 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3267 | struct drbd_genlmsghdr *dh = info->userhdr; |
| 3268 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3269 | |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 3270 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3271 | if (!adm_ctx.reply_skb) |
| 3272 | return retcode; |
| 3273 | if (retcode != NO_ERROR) |
| 3274 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3275 | |
Andreas Gruenbacher | f2257a5 | 2011-07-14 16:00:40 +0200 | [diff] [blame] | 3276 | if (dh->minor > MINORMASK) { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3277 | drbd_msg_put_info("requested minor out of range"); |
| 3278 | retcode = ERR_INVALID_REQUEST; |
| 3279 | goto out; |
| 3280 | } |
Andreas Gruenbacher | 0c8e36d | 2011-03-30 16:00:17 +0200 | [diff] [blame] | 3281 | if (adm_ctx.volume > DRBD_VOLUME_MAX) { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3282 | drbd_msg_put_info("requested volume id out of range"); |
| 3283 | retcode = ERR_INVALID_REQUEST; |
| 3284 | goto out; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3285 | } |
| 3286 | |
Lars Ellenberg | 38f1961 | 2011-03-14 13:22:35 +0100 | [diff] [blame] | 3287 | /* drbd_adm_prepare made sure already |
| 3288 | * that mdev->tconn and mdev->vnr match the request. */ |
| 3289 | if (adm_ctx.mdev) { |
| 3290 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) |
| 3291 | retcode = ERR_MINOR_EXISTS; |
| 3292 | /* else: still NO_ERROR */ |
| 3293 | goto out; |
| 3294 | } |
| 3295 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3296 | retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume); |
| 3297 | out: |
| 3298 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3299 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3302 | static enum drbd_ret_code adm_delete_minor(struct drbd_conf *mdev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3303 | { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3304 | if (mdev->state.disk == D_DISKLESS && |
| 3305 | /* no need to be mdev->state.conn == C_STANDALONE && |
| 3306 | * we may want to delete a minor from a live replication group. |
| 3307 | */ |
| 3308 | mdev->state.role == R_SECONDARY) { |
Philipp Reisner | 369bea6 | 2011-07-06 23:04:44 +0200 | [diff] [blame] | 3309 | _drbd_request_state(mdev, NS(conn, C_WF_REPORT_PARAMS), |
| 3310 | CS_VERBOSE + CS_WAIT_COMPLETE); |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 3311 | idr_remove(&mdev->tconn->volumes, mdev->vnr); |
| 3312 | idr_remove(&minors, mdev_to_minor(mdev)); |
Lars Ellenberg | 113fef9 | 2013-03-22 18:14:40 -0600 | [diff] [blame] | 3313 | destroy_workqueue(mdev->submit.wq); |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 3314 | del_gendisk(mdev->vdisk); |
| 3315 | synchronize_rcu(); |
| 3316 | kref_put(&mdev->kref, &drbd_minor_destroy); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3317 | return NO_ERROR; |
| 3318 | } else |
| 3319 | return ERR_MINOR_CONFIGURED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3322 | int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3323 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3324 | enum drbd_ret_code retcode; |
| 3325 | |
| 3326 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 3327 | if (!adm_ctx.reply_skb) |
| 3328 | return retcode; |
| 3329 | if (retcode != NO_ERROR) |
| 3330 | goto out; |
| 3331 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3332 | retcode = adm_delete_minor(adm_ctx.mdev); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3333 | out: |
| 3334 | drbd_adm_finish(info, retcode); |
| 3335 | return 0; |
| 3336 | } |
| 3337 | |
| 3338 | int drbd_adm_down(struct sk_buff *skb, struct genl_info *info) |
| 3339 | { |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3340 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3341 | struct drbd_conf *mdev; |
| 3342 | unsigned i; |
| 3343 | |
| 3344 | retcode = drbd_adm_prepare(skb, info, 0); |
| 3345 | if (!adm_ctx.reply_skb) |
| 3346 | return retcode; |
| 3347 | if (retcode != NO_ERROR) |
| 3348 | goto out; |
| 3349 | |
| 3350 | if (!adm_ctx.tconn) { |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3351 | retcode = ERR_RES_NOT_KNOWN; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3352 | goto out; |
| 3353 | } |
| 3354 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3355 | /* demote */ |
| 3356 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
| 3357 | retcode = drbd_set_role(mdev, R_SECONDARY, 0); |
| 3358 | if (retcode < SS_SUCCESS) { |
| 3359 | drbd_msg_put_info("failed to demote"); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3360 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3364 | retcode = conn_try_disconnect(adm_ctx.tconn, 0); |
| 3365 | if (retcode < SS_SUCCESS) { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3366 | drbd_msg_put_info("failed to disconnect"); |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3367 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | /* detach */ |
| 3371 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 3372 | retcode = adm_detach(mdev, 0); |
Lars Ellenberg | 2701238 | 2012-07-24 10:13:55 +0200 | [diff] [blame] | 3373 | if (retcode < SS_SUCCESS || retcode > NO_ERROR) { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3374 | drbd_msg_put_info("failed to detach"); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3375 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3379 | /* If we reach this, all volumes (of this tconn) are Secondary, |
| 3380 | * Disconnected, Diskless, aka Unconfigured. Make sure all threads have |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3381 | * actually stopped, state handling only does drbd_thread_stop_nowait(). */ |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3382 | drbd_thread_stop(&adm_ctx.tconn->worker); |
| 3383 | |
| 3384 | /* Now, nothing can fail anymore */ |
| 3385 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3386 | /* delete volumes */ |
| 3387 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
| 3388 | retcode = adm_delete_minor(mdev); |
| 3389 | if (retcode != NO_ERROR) { |
| 3390 | /* "can not happen" */ |
| 3391 | drbd_msg_put_info("failed to delete volume"); |
Philipp Reisner | ef35626 | 2011-04-13 14:21:29 -0700 | [diff] [blame] | 3392 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3396 | /* delete connection */ |
| 3397 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 3398 | list_del_rcu(&adm_ctx.tconn->all_tconn); |
| 3399 | synchronize_rcu(); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 3400 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); |
| 3401 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3402 | retcode = NO_ERROR; |
| 3403 | } else { |
| 3404 | /* "can not happen" */ |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3405 | retcode = ERR_RES_IN_USE; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3406 | drbd_msg_put_info("failed to delete connection"); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3407 | } |
Philipp Reisner | ef35626 | 2011-04-13 14:21:29 -0700 | [diff] [blame] | 3408 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3409 | out: |
| 3410 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3414 | int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3415 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3416 | enum drbd_ret_code retcode; |
| 3417 | |
Andreas Gruenbacher | 44e52cf | 2011-06-14 16:07:32 +0200 | [diff] [blame] | 3418 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3419 | if (!adm_ctx.reply_skb) |
| 3420 | return retcode; |
| 3421 | if (retcode != NO_ERROR) |
| 3422 | goto out; |
| 3423 | |
| 3424 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 3425 | list_del_rcu(&adm_ctx.tconn->all_tconn); |
| 3426 | synchronize_rcu(); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 3427 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); |
| 3428 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3429 | retcode = NO_ERROR; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3430 | } else { |
Andreas Gruenbacher | 789c1b6 | 2011-06-06 16:16:44 +0200 | [diff] [blame] | 3431 | retcode = ERR_RES_IN_USE; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3432 | } |
| 3433 | |
Lars Ellenberg | 992d6e9 | 2011-05-02 11:47:18 +0200 | [diff] [blame] | 3434 | if (retcode == NO_ERROR) |
| 3435 | drbd_thread_stop(&adm_ctx.tconn->worker); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3436 | out: |
| 3437 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3438 | return 0; |
| 3439 | } |
| 3440 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3441 | void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3442 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3443 | static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */ |
| 3444 | struct sk_buff *msg; |
| 3445 | struct drbd_genlmsghdr *d_out; |
| 3446 | unsigned seq; |
| 3447 | int err = -ENOMEM; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3448 | |
Philipp Reisner | ef86b77 | 2012-12-06 10:34:34 +0100 | [diff] [blame] | 3449 | if (sib->sib_reason == SIB_SYNC_PROGRESS) { |
| 3450 | if (time_after(jiffies, mdev->rs_last_bcast + HZ)) |
| 3451 | mdev->rs_last_bcast = jiffies; |
| 3452 | else |
| 3453 | return; |
| 3454 | } |
Philipp Reisner | 328e0f1 | 2012-10-19 14:37:47 +0200 | [diff] [blame] | 3455 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3456 | seq = atomic_inc_return(&drbd_genl_seq); |
| 3457 | msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO); |
| 3458 | if (!msg) |
| 3459 | goto failed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3460 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3461 | err = -EMSGSIZE; |
| 3462 | d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT); |
| 3463 | if (!d_out) /* cannot happen, but anyways. */ |
| 3464 | goto nla_put_failure; |
| 3465 | d_out->minor = mdev_to_minor(mdev); |
Andreas Gruenbacher | 6f9b5f8 | 2011-05-06 01:03:32 +0200 | [diff] [blame] | 3466 | d_out->ret_code = NO_ERROR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3467 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3468 | if (nla_put_status_info(msg, mdev, sib)) |
| 3469 | goto nla_put_failure; |
| 3470 | genlmsg_end(msg, d_out); |
| 3471 | err = drbd_genl_multicast_events(msg, 0); |
| 3472 | /* msg has been consumed or freed in netlink_broadcast() */ |
| 3473 | if (err && err != -ESRCH) |
| 3474 | goto failed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3475 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3476 | return; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3477 | |
| 3478 | nla_put_failure: |
| 3479 | nlmsg_free(msg); |
| 3480 | failed: |
| 3481 | dev_err(DEV, "Error %d while broadcasting event. " |
| 3482 | "Event seq:%u sib_reason:%u\n", |
| 3483 | err, seq, sib->sib_reason); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3484 | } |