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