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