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