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