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