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