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