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