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