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