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); |
Andreas Gruenbacher | 95f8efd | 2011-05-12 11:15:34 +0200 | [diff] [blame] | 1186 | retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after); |
Philipp Reisner | dc97b70 | 2011-05-03 14:27:15 +0200 | [diff] [blame] | 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); |
Andreas Gruenbacher | 95f8efd | 2011-05-12 11:15:34 +0200 | [diff] [blame] | 1189 | drbd_resync_after_changed(mdev); |
Philipp Reisner | dc97b70 | 2011-05-03 14:27:15 +0200 | [diff] [blame] | 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 | dcb20d1 | 2011-05-16 14:30:24 +0200 | [diff] [blame] | 1725 | if (old_conf && tconn->cstate == C_WF_REPORT_PARAMS && tconn->agreed_pro_version < 100) { |
| 1726 | if (new_conf->wire_protocol != old_conf->wire_protocol) |
| 1727 | return ERR_NEED_APV_100; |
| 1728 | |
| 1729 | if (new_conf->two_primaries != old_conf->two_primaries) |
| 1730 | return ERR_NEED_APV_100; |
| 1731 | |
| 1732 | if (!new_conf->integrity_alg != !old_conf->integrity_alg) |
| 1733 | return ERR_NEED_APV_100; |
| 1734 | |
| 1735 | if (strcmp(new_conf->integrity_alg, old_conf->integrity_alg)) |
| 1736 | return ERR_NEED_APV_100; |
| 1737 | } |
| 1738 | |
| 1739 | if (!new_conf->two_primaries && |
| 1740 | conn_highest_role(tconn) == R_PRIMARY && |
| 1741 | conn_highest_peer(tconn) == R_PRIMARY) |
| 1742 | return ERR_NEED_ALLOW_TWO_PRI; |
Philipp Reisner | b032b6f | 2011-04-13 18:16:10 -0700 | [diff] [blame] | 1743 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1744 | if (new_conf->two_primaries && |
| 1745 | (new_conf->wire_protocol != DRBD_PROT_C)) |
| 1746 | return ERR_NOT_PROTO_C; |
| 1747 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1748 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 1749 | if (get_ldev(mdev)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1750 | enum drbd_fencing_p fp = rcu_dereference(mdev->ldev->disk_conf)->fencing; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1751 | put_ldev(mdev); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1752 | if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH) |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1753 | return ERR_STONITH_AND_PROT_A; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1754 | } |
Andreas Gruenbacher | 6139f60 | 2011-05-06 20:00:02 +0200 | [diff] [blame] | 1755 | if (mdev->state.role == R_PRIMARY && new_conf->discard_my_data) |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1756 | return ERR_DISCARD; |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1757 | } |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1758 | |
| 1759 | if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A) |
| 1760 | return ERR_CONG_NOT_PROTO_A; |
| 1761 | |
| 1762 | return NO_ERROR; |
| 1763 | } |
| 1764 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1765 | static enum drbd_ret_code |
| 1766 | check_net_options(struct drbd_tconn *tconn, struct net_conf *new_conf) |
| 1767 | { |
| 1768 | static enum drbd_ret_code rv; |
| 1769 | struct drbd_conf *mdev; |
| 1770 | int i; |
| 1771 | |
| 1772 | rcu_read_lock(); |
| 1773 | rv = _check_net_options(tconn, rcu_dereference(tconn->net_conf), new_conf); |
| 1774 | rcu_read_unlock(); |
| 1775 | |
| 1776 | /* tconn->volumes protected by genl_lock() here */ |
| 1777 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 1778 | if (!mdev->bitmap) { |
| 1779 | if(drbd_bm_init(mdev)) |
| 1780 | return ERR_NOMEM; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | return rv; |
| 1785 | } |
| 1786 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1787 | struct crypto { |
| 1788 | struct crypto_hash *verify_tfm; |
| 1789 | struct crypto_hash *csums_tfm; |
| 1790 | struct crypto_hash *cram_hmac_tfm; |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 1791 | struct crypto_hash *integrity_tfm; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1792 | void *int_dig_in; |
| 1793 | void *int_dig_vv; |
| 1794 | }; |
| 1795 | |
| 1796 | static int |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1797 | alloc_hash(struct crypto_hash **tfm, char *tfm_name, int err_alg) |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1798 | { |
| 1799 | if (!tfm_name[0]) |
| 1800 | return NO_ERROR; |
| 1801 | |
| 1802 | *tfm = crypto_alloc_hash(tfm_name, 0, CRYPTO_ALG_ASYNC); |
| 1803 | if (IS_ERR(*tfm)) { |
| 1804 | *tfm = NULL; |
| 1805 | return err_alg; |
| 1806 | } |
| 1807 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1808 | return NO_ERROR; |
| 1809 | } |
| 1810 | |
| 1811 | static enum drbd_ret_code |
| 1812 | alloc_crypto(struct crypto *crypto, struct net_conf *new_conf) |
| 1813 | { |
| 1814 | char hmac_name[CRYPTO_MAX_ALG_NAME]; |
| 1815 | enum drbd_ret_code rv; |
| 1816 | int hash_size; |
| 1817 | |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1818 | rv = alloc_hash(&crypto->csums_tfm, new_conf->csums_alg, |
| 1819 | ERR_CSUMS_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1820 | if (rv != NO_ERROR) |
| 1821 | return rv; |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1822 | rv = alloc_hash(&crypto->verify_tfm, new_conf->verify_alg, |
| 1823 | ERR_VERIFY_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1824 | if (rv != NO_ERROR) |
| 1825 | return rv; |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1826 | rv = alloc_hash(&crypto->integrity_tfm, new_conf->integrity_alg, |
| 1827 | ERR_INTEGRITY_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1828 | if (rv != NO_ERROR) |
| 1829 | return rv; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1830 | if (new_conf->cram_hmac_alg[0] != 0) { |
| 1831 | snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", |
| 1832 | new_conf->cram_hmac_alg); |
| 1833 | |
Andreas Gruenbacher | 4b6ad6d | 2011-04-29 10:20:08 +0200 | [diff] [blame] | 1834 | rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name, |
| 1835 | ERR_AUTH_ALG); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1836 | } |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 1837 | if (crypto->integrity_tfm) { |
| 1838 | hash_size = crypto_hash_digestsize(crypto->integrity_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1839 | crypto->int_dig_in = kmalloc(hash_size, GFP_KERNEL); |
| 1840 | if (!crypto->int_dig_in) |
| 1841 | return ERR_NOMEM; |
| 1842 | crypto->int_dig_vv = kmalloc(hash_size, GFP_KERNEL); |
| 1843 | if (!crypto->int_dig_vv) |
| 1844 | return ERR_NOMEM; |
| 1845 | } |
| 1846 | |
| 1847 | return rv; |
| 1848 | } |
| 1849 | |
| 1850 | static void free_crypto(struct crypto *crypto) |
| 1851 | { |
| 1852 | kfree(crypto->int_dig_in); |
| 1853 | kfree(crypto->int_dig_vv); |
| 1854 | crypto_free_hash(crypto->cram_hmac_tfm); |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 1855 | crypto_free_hash(crypto->integrity_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1856 | crypto_free_hash(crypto->csums_tfm); |
| 1857 | crypto_free_hash(crypto->verify_tfm); |
| 1858 | } |
| 1859 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1860 | int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info) |
| 1861 | { |
| 1862 | enum drbd_ret_code retcode; |
| 1863 | struct drbd_tconn *tconn; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1864 | struct net_conf *old_conf, *new_conf = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1865 | int err; |
| 1866 | int ovr; /* online verify running */ |
| 1867 | int rsr; /* re-sync running */ |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1868 | struct crypto crypto = { }; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1869 | |
| 1870 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
| 1871 | if (!adm_ctx.reply_skb) |
| 1872 | return retcode; |
| 1873 | if (retcode != NO_ERROR) |
| 1874 | goto out; |
| 1875 | |
| 1876 | tconn = adm_ctx.tconn; |
| 1877 | |
| 1878 | new_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 1879 | if (!new_conf) { |
| 1880 | retcode = ERR_NOMEM; |
| 1881 | goto out; |
| 1882 | } |
| 1883 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1884 | conn_reconfig_start(tconn); |
| 1885 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1886 | mutex_lock(&tconn->data.mutex); |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 1887 | mutex_lock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1888 | old_conf = tconn->net_conf; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1889 | |
| 1890 | if (!old_conf) { |
| 1891 | drbd_msg_put_info("net conf missing, try connect"); |
| 1892 | retcode = ERR_INVALID_REQUEST; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1893 | goto fail; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | *new_conf = *old_conf; |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 1897 | if (should_set_defaults(info)) |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 1898 | set_net_conf_defaults(new_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1899 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1900 | err = net_conf_from_attrs_for_change(new_conf, info); |
| 1901 | if (err) { |
| 1902 | retcode = ERR_MANDATORY_TAG; |
| 1903 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 1904 | goto fail; |
| 1905 | } |
| 1906 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 1907 | retcode = check_net_options(tconn, new_conf); |
| 1908 | if (retcode != NO_ERROR) |
| 1909 | goto fail; |
| 1910 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1911 | /* re-sync running */ |
| 1912 | rsr = conn_resync_running(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1913 | if (rsr && strcmp(new_conf->csums_alg, old_conf->csums_alg)) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1914 | retcode = ERR_CSUMS_RESYNC_RUNNING; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1915 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1916 | } |
| 1917 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1918 | /* online verify running */ |
| 1919 | ovr = conn_ov_running(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1920 | if (ovr && strcmp(new_conf->verify_alg, old_conf->verify_alg)) { |
| 1921 | retcode = ERR_VERIFY_RUNNING; |
| 1922 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1923 | } |
| 1924 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1925 | retcode = alloc_crypto(&crypto, new_conf); |
| 1926 | if (retcode != NO_ERROR) |
| 1927 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1928 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1929 | rcu_assign_pointer(tconn->net_conf, new_conf); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1930 | |
| 1931 | if (!rsr) { |
| 1932 | crypto_free_hash(tconn->csums_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1933 | tconn->csums_tfm = crypto.csums_tfm; |
| 1934 | crypto.csums_tfm = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1935 | } |
| 1936 | if (!ovr) { |
| 1937 | crypto_free_hash(tconn->verify_tfm); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1938 | tconn->verify_tfm = crypto.verify_tfm; |
| 1939 | crypto.verify_tfm = NULL; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1940 | } |
| 1941 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1942 | kfree(tconn->int_dig_in); |
| 1943 | tconn->int_dig_in = crypto.int_dig_in; |
| 1944 | kfree(tconn->int_dig_vv); |
| 1945 | tconn->int_dig_vv = crypto.int_dig_vv; |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 1946 | crypto_free_hash(tconn->integrity_tfm); |
| 1947 | tconn->integrity_tfm = crypto.integrity_tfm; |
Philipp Reisner | d659f2a | 2011-05-16 17:38:45 +0200 | [diff] [blame^] | 1948 | if (tconn->cstate >= C_WF_REPORT_PARAMS && tconn->agreed_pro_version >= 100) |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1949 | /* Do this without trying to take tconn->data.mutex again. */ |
Philipp Reisner | d659f2a | 2011-05-16 17:38:45 +0200 | [diff] [blame^] | 1950 | __drbd_send_protocol(tconn, P_PROTOCOL_UPDATE); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1951 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1952 | crypto_free_hash(tconn->cram_hmac_tfm); |
| 1953 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; |
| 1954 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 1955 | mutex_unlock(&tconn->conf_update); |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1956 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1957 | synchronize_rcu(); |
| 1958 | kfree(old_conf); |
| 1959 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1960 | if (tconn->cstate >= C_WF_REPORT_PARAMS) |
| 1961 | drbd_send_sync_param(minor_to_mdev(conn_lowest_minor(tconn))); |
| 1962 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1963 | goto done; |
| 1964 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1965 | fail: |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 1966 | mutex_unlock(&tconn->conf_update); |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1967 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1968 | free_crypto(&crypto); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1969 | kfree(new_conf); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 1970 | done: |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 1971 | conn_reconfig_done(tconn); |
| 1972 | out: |
| 1973 | drbd_adm_finish(info, retcode); |
| 1974 | return 0; |
| 1975 | } |
| 1976 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1977 | int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1978 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1979 | struct drbd_conf *mdev; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1980 | struct net_conf *old_conf, *new_conf = NULL; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 1981 | struct crypto crypto = { }; |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 1982 | struct drbd_tconn *oconn; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1983 | struct drbd_tconn *tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1984 | struct sockaddr *new_my_addr, *new_peer_addr, *taken_addr; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1985 | enum drbd_ret_code retcode; |
| 1986 | int i; |
| 1987 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1988 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1989 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
| 1990 | if (!adm_ctx.reply_skb) |
| 1991 | return retcode; |
| 1992 | if (retcode != NO_ERROR) |
| 1993 | goto out; |
| 1994 | |
| 1995 | tconn = adm_ctx.tconn; |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 1996 | conn_reconfig_start(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1997 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 1998 | if (tconn->cstate > C_STANDALONE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1999 | retcode = ERR_NET_CONFIGURED; |
| 2000 | goto fail; |
| 2001 | } |
| 2002 | |
| 2003 | /* allocation not in the IO path, cqueue thread context */ |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 2004 | new_conf = kzalloc(sizeof(*new_conf), GFP_KERNEL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2005 | if (!new_conf) { |
| 2006 | retcode = ERR_NOMEM; |
| 2007 | goto fail; |
| 2008 | } |
| 2009 | |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2010 | set_net_conf_defaults(new_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2011 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2012 | err = net_conf_from_attrs(new_conf, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2013 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2014 | retcode = ERR_MANDATORY_TAG; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2015 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2016 | goto fail; |
| 2017 | } |
| 2018 | |
Philipp Reisner | cd64397 | 2011-04-13 18:00:59 -0700 | [diff] [blame] | 2019 | retcode = check_net_options(tconn, new_conf); |
| 2020 | if (retcode != NO_ERROR) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2021 | goto fail; |
Philipp Reisner | 422028b | 2010-10-27 11:12:07 +0200 | [diff] [blame] | 2022 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2023 | retcode = NO_ERROR; |
| 2024 | |
| 2025 | new_my_addr = (struct sockaddr *)&new_conf->my_addr; |
| 2026 | new_peer_addr = (struct sockaddr *)&new_conf->peer_addr; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2027 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 2028 | /* No need for _rcu here. All reconfiguration is |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2029 | * strictly serialized on genl_lock(). We are protected against |
| 2030 | * concurrent reconfiguration/addition/deletion */ |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2031 | list_for_each_entry(oconn, &drbd_tconns, all_tconn) { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2032 | struct net_conf *nc; |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2033 | if (oconn == tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2034 | continue; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2035 | |
| 2036 | rcu_read_lock(); |
| 2037 | nc = rcu_dereference(oconn->net_conf); |
| 2038 | if (nc) { |
| 2039 | taken_addr = (struct sockaddr *)&nc->my_addr; |
| 2040 | if (new_conf->my_addr_len == nc->my_addr_len && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2041 | !memcmp(new_my_addr, taken_addr, new_conf->my_addr_len)) |
| 2042 | retcode = ERR_LOCAL_ADDR; |
| 2043 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2044 | taken_addr = (struct sockaddr *)&nc->peer_addr; |
| 2045 | if (new_conf->peer_addr_len == nc->peer_addr_len && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2046 | !memcmp(new_peer_addr, taken_addr, new_conf->peer_addr_len)) |
| 2047 | retcode = ERR_PEER_ADDR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2048 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2049 | rcu_read_unlock(); |
| 2050 | if (retcode != NO_ERROR) |
| 2051 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2054 | retcode = alloc_crypto(&crypto, new_conf); |
| 2055 | if (retcode != NO_ERROR) |
| 2056 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2057 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2058 | ((char *)new_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0; |
| 2059 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2060 | conn_flush_workqueue(tconn); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2061 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2062 | mutex_lock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2063 | old_conf = tconn->net_conf; |
| 2064 | if (old_conf) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2065 | retcode = ERR_NET_CONFIGURED; |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2066 | mutex_unlock(&tconn->conf_update); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2067 | goto fail; |
| 2068 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2069 | rcu_assign_pointer(tconn->net_conf, new_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2070 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2071 | conn_free_crypto(tconn); |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2072 | tconn->int_dig_in = crypto.int_dig_in; |
| 2073 | tconn->int_dig_vv = crypto.int_dig_vv; |
| 2074 | tconn->cram_hmac_tfm = crypto.cram_hmac_tfm; |
Andreas Gruenbacher | 8d412fc | 2011-04-27 20:59:18 +0200 | [diff] [blame] | 2075 | tconn->integrity_tfm = crypto.integrity_tfm; |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2076 | tconn->csums_tfm = crypto.csums_tfm; |
| 2077 | tconn->verify_tfm = crypto.verify_tfm; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2078 | |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 2079 | mutex_unlock(&tconn->conf_update); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 2080 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 2081 | rcu_read_lock(); |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2082 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 2083 | mdev->send_cnt = 0; |
| 2084 | mdev->recv_cnt = 0; |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2085 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 2086 | rcu_read_unlock(); |
Lars Ellenberg | 5ee743e | 2011-04-26 16:22:25 +0200 | [diff] [blame] | 2087 | |
| 2088 | retcode = conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
| 2089 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2090 | conn_reconfig_done(tconn); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2091 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2092 | return 0; |
| 2093 | |
| 2094 | fail: |
Philipp Reisner | 0fd0ea0 | 2011-04-27 11:27:47 +0200 | [diff] [blame] | 2095 | free_crypto(&crypto); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2096 | kfree(new_conf); |
| 2097 | |
Philipp Reisner | 8088319 | 2011-02-18 14:56:45 +0100 | [diff] [blame] | 2098 | conn_reconfig_done(tconn); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2099 | out: |
| 2100 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2101 | return 0; |
| 2102 | } |
| 2103 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2104 | static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool force) |
| 2105 | { |
| 2106 | enum drbd_state_rv rv; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2107 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2108 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), |
| 2109 | force ? CS_HARD : 0); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2110 | |
| 2111 | switch (rv) { |
| 2112 | case SS_NOTHING_TO_DO: |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2113 | break; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2114 | case SS_ALREADY_STANDALONE: |
| 2115 | return SS_SUCCESS; |
| 2116 | case SS_PRIMARY_NOP: |
| 2117 | /* Our state checking code wants to see the peer outdated. */ |
| 2118 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2119 | pdsk, D_OUTDATED), CS_VERBOSE); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2120 | break; |
| 2121 | case SS_CW_FAILED_BY_PEER: |
| 2122 | /* The peer probably wants to see us outdated. */ |
| 2123 | rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING, |
| 2124 | disk, D_OUTDATED), 0); |
| 2125 | if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) { |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2126 | rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING), |
| 2127 | CS_HARD); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2128 | } |
| 2129 | break; |
| 2130 | default:; |
| 2131 | /* no special handling necessary */ |
| 2132 | } |
| 2133 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2134 | if (rv >= SS_SUCCESS) { |
| 2135 | enum drbd_state_rv rv2; |
| 2136 | /* No one else can reconfigure the network while I am here. |
| 2137 | * The state handling only uses drbd_thread_stop_nowait(), |
| 2138 | * we want to really wait here until the receiver is no more. |
| 2139 | */ |
| 2140 | drbd_thread_stop(&adm_ctx.tconn->receiver); |
| 2141 | |
| 2142 | /* Race breaker. This additional state change request may be |
| 2143 | * necessary, if this was a forced disconnect during a receiver |
| 2144 | * restart. We may have "killed" the receiver thread just |
| 2145 | * after drbdd_init() returned. Typically, we should be |
| 2146 | * C_STANDALONE already, now, and this becomes a no-op. |
| 2147 | */ |
| 2148 | rv2 = conn_request_state(tconn, NS(conn, C_STANDALONE), |
| 2149 | CS_VERBOSE | CS_HARD); |
| 2150 | if (rv2 < SS_SUCCESS) |
| 2151 | conn_err(tconn, |
| 2152 | "unexpected rv2=%d in conn_try_disconnect()\n", |
| 2153 | rv2); |
| 2154 | } |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2155 | return rv; |
| 2156 | } |
| 2157 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2158 | int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2159 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2160 | struct disconnect_parms parms; |
| 2161 | struct drbd_tconn *tconn; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2162 | enum drbd_state_rv rv; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2163 | enum drbd_ret_code retcode; |
| 2164 | int err; |
Philipp Reisner | 2561b9c | 2010-12-03 15:22:48 +0100 | [diff] [blame] | 2165 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2166 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
| 2167 | if (!adm_ctx.reply_skb) |
| 2168 | return retcode; |
| 2169 | if (retcode != NO_ERROR) |
Philipp Reisner | 2561b9c | 2010-12-03 15:22:48 +0100 | [diff] [blame] | 2170 | goto fail; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2171 | |
| 2172 | tconn = adm_ctx.tconn; |
| 2173 | memset(&parms, 0, sizeof(parms)); |
| 2174 | if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2175 | err = disconnect_parms_from_attrs(&parms, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2176 | if (err) { |
| 2177 | retcode = ERR_MANDATORY_TAG; |
| 2178 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2179 | goto fail; |
| 2180 | } |
Philipp Reisner | 2561b9c | 2010-12-03 15:22:48 +0100 | [diff] [blame] | 2181 | } |
| 2182 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 2183 | rv = conn_try_disconnect(tconn, parms.force_disconnect); |
| 2184 | if (rv < SS_SUCCESS) |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 2185 | retcode = rv; /* FIXME: Type mismatch. */ |
| 2186 | else |
| 2187 | retcode = NO_ERROR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2188 | fail: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2189 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2190 | return 0; |
| 2191 | } |
| 2192 | |
| 2193 | void resync_after_online_grow(struct drbd_conf *mdev) |
| 2194 | { |
| 2195 | int iass; /* I am sync source */ |
| 2196 | |
| 2197 | dev_info(DEV, "Resync of new storage after online grow\n"); |
| 2198 | if (mdev->state.role != mdev->state.peer) |
| 2199 | iass = (mdev->state.role == R_PRIMARY); |
| 2200 | else |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2201 | iass = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2202 | |
| 2203 | if (iass) |
| 2204 | drbd_start_resync(mdev, C_SYNC_SOURCE); |
| 2205 | else |
| 2206 | _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE); |
| 2207 | } |
| 2208 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2209 | int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2210 | { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2211 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2212 | struct resize_parms rs; |
| 2213 | struct drbd_conf *mdev; |
| 2214 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2215 | enum determine_dev_size dd; |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2216 | enum dds_flags ddsf; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2217 | sector_t u_size; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2218 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2219 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2220 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2221 | if (!adm_ctx.reply_skb) |
| 2222 | return retcode; |
| 2223 | if (retcode != NO_ERROR) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2224 | goto fail; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2225 | |
| 2226 | memset(&rs, 0, sizeof(struct resize_parms)); |
| 2227 | if (info->attrs[DRBD_NLA_RESIZE_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2228 | err = resize_parms_from_attrs(&rs, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2229 | if (err) { |
| 2230 | retcode = ERR_MANDATORY_TAG; |
| 2231 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2232 | goto fail; |
| 2233 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2236 | mdev = adm_ctx.mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2237 | if (mdev->state.conn > C_CONNECTED) { |
| 2238 | retcode = ERR_RESIZE_RESYNC; |
| 2239 | goto fail; |
| 2240 | } |
| 2241 | |
| 2242 | if (mdev->state.role == R_SECONDARY && |
| 2243 | mdev->state.peer == R_SECONDARY) { |
| 2244 | retcode = ERR_NO_PRIMARY; |
| 2245 | goto fail; |
| 2246 | } |
| 2247 | |
| 2248 | if (!get_ldev(mdev)) { |
| 2249 | retcode = ERR_NO_DISK; |
| 2250 | goto fail; |
| 2251 | } |
| 2252 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2253 | if (rs.no_resync && mdev->tconn->agreed_pro_version < 93) { |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2254 | retcode = ERR_NEED_APV_93; |
| 2255 | goto fail; |
| 2256 | } |
| 2257 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2258 | rcu_read_lock(); |
| 2259 | u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size; |
| 2260 | rcu_read_unlock(); |
| 2261 | if (u_size != (sector_t)rs.resize_size) { |
| 2262 | new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 2263 | if (!new_disk_conf) { |
| 2264 | retcode = ERR_NOMEM; |
| 2265 | goto fail; |
| 2266 | } |
| 2267 | } |
| 2268 | |
Philipp Reisner | 087c249 | 2010-03-26 13:49:56 +0100 | [diff] [blame] | 2269 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2270 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2271 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2272 | if (new_disk_conf) { |
| 2273 | mutex_lock(&mdev->tconn->conf_update); |
| 2274 | old_disk_conf = mdev->ldev->disk_conf; |
| 2275 | *new_disk_conf = *old_disk_conf; |
| 2276 | new_disk_conf->disk_size = (sector_t)rs.resize_size; |
| 2277 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); |
| 2278 | mutex_unlock(&mdev->tconn->conf_update); |
| 2279 | synchronize_rcu(); |
| 2280 | kfree(old_disk_conf); |
| 2281 | } |
| 2282 | |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2283 | 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] | 2284 | dd = drbd_determine_dev_size(mdev, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2285 | drbd_md_sync(mdev); |
| 2286 | put_ldev(mdev); |
| 2287 | if (dd == dev_size_error) { |
| 2288 | retcode = ERR_NOMEM_BITMAP; |
| 2289 | goto fail; |
| 2290 | } |
| 2291 | |
Philipp Reisner | 087c249 | 2010-03-26 13:49:56 +0100 | [diff] [blame] | 2292 | if (mdev->state.conn == C_CONNECTED) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2293 | if (dd == grew) |
| 2294 | set_bit(RESIZE_PENDING, &mdev->flags); |
| 2295 | |
| 2296 | drbd_send_uuids(mdev); |
Philipp Reisner | 6495d2c | 2010-03-24 16:07:04 +0100 | [diff] [blame] | 2297 | drbd_send_sizes(mdev, 1, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | fail: |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2301 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2302 | return 0; |
| 2303 | } |
| 2304 | |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2305 | void drbd_set_res_opts_defaults(struct res_opts *r) |
| 2306 | { |
| 2307 | return set_res_opts_defaults(r); |
| 2308 | } |
| 2309 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2310 | 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] | 2311 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2312 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2313 | cpumask_var_t new_cpu_mask; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2314 | struct drbd_tconn *tconn; |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2315 | struct res_opts res_opts; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2316 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2317 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2318 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2319 | if (!adm_ctx.reply_skb) |
| 2320 | return retcode; |
| 2321 | if (retcode != NO_ERROR) |
| 2322 | goto fail; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2323 | tconn = adm_ctx.tconn; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2324 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2325 | if (!zalloc_cpumask_var(&new_cpu_mask, GFP_KERNEL)) { |
| 2326 | retcode = ERR_NOMEM; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2327 | drbd_msg_put_info("unable to allocate cpumask"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2328 | goto fail; |
| 2329 | } |
| 2330 | |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2331 | res_opts = tconn->res_opts; |
Lars Ellenberg | 5979e36 | 2011-04-27 21:09:55 +0200 | [diff] [blame] | 2332 | if (should_set_defaults(info)) |
Andreas Gruenbacher | b966b5d | 2011-05-03 14:56:09 +0200 | [diff] [blame] | 2333 | set_res_opts_defaults(&res_opts); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2334 | |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2335 | err = res_opts_from_attrs(&res_opts, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2336 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2337 | retcode = ERR_MANDATORY_TAG; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2338 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2339 | goto fail; |
| 2340 | } |
| 2341 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2342 | /* silently ignore cpu mask on UP kernel */ |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2343 | if (nr_cpu_ids > 1 && res_opts.cpu_mask[0] != 0) { |
| 2344 | err = __bitmap_parse(res_opts.cpu_mask, 32, 0, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2345 | cpumask_bits(new_cpu_mask), nr_cpu_ids); |
| 2346 | if (err) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2347 | conn_warn(tconn, "__bitmap_parse() failed with %d\n", err); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2348 | retcode = ERR_CPU_MASK_PARSE; |
| 2349 | goto fail; |
| 2350 | } |
| 2351 | } |
| 2352 | |
Lars Ellenberg | 7ad651b | 2011-02-21 13:21:03 +0100 | [diff] [blame] | 2353 | |
Lars Ellenberg | b57a1e2 | 2011-04-27 21:17:33 +0200 | [diff] [blame] | 2354 | tconn->res_opts = res_opts; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2355 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2356 | if (!cpumask_equal(tconn->cpu_mask, new_cpu_mask)) { |
| 2357 | cpumask_copy(tconn->cpu_mask, new_cpu_mask); |
| 2358 | drbd_calc_cpu_mask(tconn); |
| 2359 | tconn->receiver.reset_cpu_mask = 1; |
| 2360 | tconn->asender.reset_cpu_mask = 1; |
| 2361 | tconn->worker.reset_cpu_mask = 1; |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 2362 | } |
| 2363 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2364 | fail: |
| 2365 | free_cpumask_var(new_cpu_mask); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2366 | |
| 2367 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2368 | return 0; |
| 2369 | } |
| 2370 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2371 | int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2372 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2373 | struct drbd_conf *mdev; |
| 2374 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
| 2375 | |
| 2376 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2377 | if (!adm_ctx.reply_skb) |
| 2378 | return retcode; |
| 2379 | if (retcode != NO_ERROR) |
| 2380 | goto out; |
| 2381 | |
| 2382 | mdev = adm_ctx.mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2383 | |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2384 | /* If there is still bitmap IO pending, probably because of a previous |
| 2385 | * resync just being finished, wait for it before requesting a new resync. */ |
| 2386 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
| 2387 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2388 | retcode = _drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T), CS_ORDERED); |
| 2389 | |
| 2390 | if (retcode < SS_SUCCESS && retcode != SS_NEED_CONNECTION) |
| 2391 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T)); |
| 2392 | |
| 2393 | while (retcode == SS_NEED_CONNECTION) { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2394 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2395 | if (mdev->state.conn < C_CONNECTED) |
| 2396 | retcode = _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_VERBOSE, NULL); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2397 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2398 | |
| 2399 | if (retcode != SS_NEED_CONNECTION) |
| 2400 | break; |
| 2401 | |
| 2402 | retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T)); |
| 2403 | } |
| 2404 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2405 | out: |
| 2406 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2407 | return 0; |
| 2408 | } |
| 2409 | |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 2410 | static int drbd_bmio_set_susp_al(struct drbd_conf *mdev) |
| 2411 | { |
| 2412 | int rv; |
| 2413 | |
| 2414 | rv = drbd_bmio_set_n_write(mdev); |
| 2415 | drbd_suspend_al(mdev); |
| 2416 | return rv; |
| 2417 | } |
| 2418 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2419 | static int drbd_adm_simple_request_state(struct sk_buff *skb, struct genl_info *info, |
| 2420 | union drbd_state mask, union drbd_state val) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2421 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2422 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2423 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2424 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2425 | if (!adm_ctx.reply_skb) |
| 2426 | return retcode; |
| 2427 | if (retcode != NO_ERROR) |
| 2428 | goto out; |
Lars Ellenberg | 194bfb3 | 2011-01-18 10:38:01 +0100 | [diff] [blame] | 2429 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2430 | retcode = drbd_request_state(adm_ctx.mdev, mask, val); |
| 2431 | out: |
| 2432 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2433 | return 0; |
| 2434 | } |
| 2435 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2436 | 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] | 2437 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2438 | return drbd_adm_simple_request_state(skb, info, NS(conn, C_STARTING_SYNC_S)); |
| 2439 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2440 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2441 | int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info) |
| 2442 | { |
| 2443 | enum drbd_ret_code retcode; |
| 2444 | |
| 2445 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2446 | if (!adm_ctx.reply_skb) |
| 2447 | return retcode; |
| 2448 | if (retcode != NO_ERROR) |
| 2449 | goto out; |
| 2450 | |
| 2451 | 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] | 2452 | retcode = ERR_PAUSE_IS_SET; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2453 | out: |
| 2454 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2455 | return 0; |
| 2456 | } |
| 2457 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2458 | 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] | 2459 | { |
Philipp Reisner | da9fbc2 | 2011-03-29 10:52:01 +0200 | [diff] [blame] | 2460 | union drbd_dev_state s; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2461 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2462 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2463 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2464 | if (!adm_ctx.reply_skb) |
| 2465 | return retcode; |
| 2466 | if (retcode != NO_ERROR) |
| 2467 | goto out; |
| 2468 | |
| 2469 | if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 0)) == SS_NOTHING_TO_DO) { |
| 2470 | s = adm_ctx.mdev->state; |
Philipp Reisner | cd88d03 | 2011-01-20 11:46:41 +0100 | [diff] [blame] | 2471 | if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) { |
| 2472 | retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP : |
| 2473 | s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR; |
| 2474 | } else { |
| 2475 | retcode = ERR_PAUSE_IS_CLEAR; |
| 2476 | } |
| 2477 | } |
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 | out: |
| 2480 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2481 | return 0; |
| 2482 | } |
| 2483 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2484 | 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] | 2485 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2486 | return drbd_adm_simple_request_state(skb, info, NS(susp, 1)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2489 | 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] | 2490 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2491 | struct drbd_conf *mdev; |
| 2492 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
| 2493 | |
| 2494 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2495 | if (!adm_ctx.reply_skb) |
| 2496 | return retcode; |
| 2497 | if (retcode != NO_ERROR) |
| 2498 | goto out; |
| 2499 | |
| 2500 | mdev = adm_ctx.mdev; |
Philipp Reisner | 43a5182 | 2010-06-11 11:26:34 +0200 | [diff] [blame] | 2501 | if (test_bit(NEW_CUR_UUID, &mdev->flags)) { |
| 2502 | drbd_uuid_new_current(mdev); |
| 2503 | clear_bit(NEW_CUR_UUID, &mdev->flags); |
Philipp Reisner | 43a5182 | 2010-06-11 11:26:34 +0200 | [diff] [blame] | 2504 | } |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2505 | drbd_suspend_io(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2506 | retcode = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0)); |
| 2507 | if (retcode == SS_SUCCESS) { |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2508 | if (mdev->state.conn < C_CONNECTED) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 2509 | tl_clear(mdev->tconn); |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2510 | if (mdev->state.disk == D_DISKLESS || mdev->state.disk == D_FAILED) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 2511 | tl_restart(mdev->tconn, FAIL_FROZEN_DISK_IO); |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 2512 | } |
| 2513 | drbd_resume_io(mdev); |
| 2514 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2515 | out: |
| 2516 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2517 | return 0; |
| 2518 | } |
| 2519 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2520 | int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2521 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2522 | return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2525 | int nla_put_drbd_cfg_context(struct sk_buff *skb, const char *conn_name, unsigned vnr) |
| 2526 | { |
| 2527 | struct nlattr *nla; |
| 2528 | nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT); |
| 2529 | if (!nla) |
| 2530 | goto nla_put_failure; |
| 2531 | if (vnr != VOLUME_UNSPECIFIED) |
| 2532 | NLA_PUT_U32(skb, T_ctx_volume, vnr); |
| 2533 | NLA_PUT_STRING(skb, T_ctx_conn_name, conn_name); |
| 2534 | nla_nest_end(skb, nla); |
| 2535 | return 0; |
| 2536 | |
| 2537 | nla_put_failure: |
| 2538 | if (nla) |
| 2539 | nla_nest_cancel(skb, nla); |
| 2540 | return -EMSGSIZE; |
| 2541 | } |
| 2542 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2543 | int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev, |
| 2544 | const struct sib_info *sib) |
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 | struct state_info *si = NULL; /* for sizeof(si->member); */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2547 | struct net_conf *nc; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2548 | struct nlattr *nla; |
| 2549 | int got_ldev; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2550 | int err = 0; |
| 2551 | int exclude_sensitive; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2552 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2553 | /* If sib != NULL, this is drbd_bcast_event, which anyone can listen |
| 2554 | * to. So we better exclude_sensitive information. |
| 2555 | * |
| 2556 | * If sib == NULL, this is drbd_adm_get_status, executed synchronously |
| 2557 | * in the context of the requesting user process. Exclude sensitive |
| 2558 | * information, unless current has superuser. |
| 2559 | * |
| 2560 | * NOTE: for drbd_adm_get_status_all(), this is a netlink dump, and |
| 2561 | * relies on the current implementation of netlink_dump(), which |
| 2562 | * executes the dump callback successively from netlink_recvmsg(), |
| 2563 | * always in the context of the receiving process */ |
| 2564 | exclude_sensitive = sib || !capable(CAP_SYS_ADMIN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2565 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2566 | got_ldev = get_ldev(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2567 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2568 | /* We need to add connection name and volume number information still. |
| 2569 | * Minor number is in drbd_genlmsghdr. */ |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2570 | if (nla_put_drbd_cfg_context(skb, mdev->tconn->name, mdev->vnr)) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2571 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2572 | |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2573 | if (res_opts_to_skb(skb, &mdev->tconn->res_opts, exclude_sensitive)) |
| 2574 | goto nla_put_failure; |
| 2575 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2576 | rcu_read_lock(); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2577 | if (got_ldev) |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2578 | 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] | 2579 | goto nla_put_failure; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2580 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2581 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 2582 | if (nc) |
| 2583 | err = net_conf_to_skb(skb, nc, exclude_sensitive); |
| 2584 | rcu_read_unlock(); |
| 2585 | if (err) |
| 2586 | goto nla_put_failure; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2587 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2588 | nla = nla_nest_start(skb, DRBD_NLA_STATE_INFO); |
| 2589 | if (!nla) |
| 2590 | goto nla_put_failure; |
| 2591 | NLA_PUT_U32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY); |
| 2592 | NLA_PUT_U32(skb, T_current_state, mdev->state.i); |
| 2593 | NLA_PUT_U64(skb, T_ed_uuid, mdev->ed_uuid); |
| 2594 | NLA_PUT_U64(skb, T_capacity, drbd_get_capacity(mdev->this_bdev)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2595 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2596 | if (got_ldev) { |
| 2597 | NLA_PUT_U32(skb, T_disk_flags, mdev->ldev->md.flags); |
| 2598 | NLA_PUT(skb, T_uuids, sizeof(si->uuids), mdev->ldev->md.uuid); |
| 2599 | NLA_PUT_U64(skb, T_bits_total, drbd_bm_bits(mdev)); |
| 2600 | NLA_PUT_U64(skb, T_bits_oos, drbd_bm_total_weight(mdev)); |
| 2601 | if (C_SYNC_SOURCE <= mdev->state.conn && |
| 2602 | C_PAUSED_SYNC_T >= mdev->state.conn) { |
| 2603 | NLA_PUT_U64(skb, T_bits_rs_total, mdev->rs_total); |
| 2604 | NLA_PUT_U64(skb, T_bits_rs_failed, mdev->rs_failed); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2605 | } |
| 2606 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2607 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2608 | if (sib) { |
| 2609 | switch(sib->sib_reason) { |
| 2610 | case SIB_SYNC_PROGRESS: |
| 2611 | case SIB_GET_STATUS_REPLY: |
| 2612 | break; |
| 2613 | case SIB_STATE_CHANGE: |
| 2614 | NLA_PUT_U32(skb, T_prev_state, sib->os.i); |
| 2615 | NLA_PUT_U32(skb, T_new_state, sib->ns.i); |
| 2616 | break; |
| 2617 | case SIB_HELPER_POST: |
| 2618 | NLA_PUT_U32(skb, |
| 2619 | T_helper_exit_code, sib->helper_exit_code); |
| 2620 | /* fall through */ |
| 2621 | case SIB_HELPER_PRE: |
| 2622 | NLA_PUT_STRING(skb, T_helper, sib->helper_name); |
| 2623 | break; |
| 2624 | } |
| 2625 | } |
| 2626 | nla_nest_end(skb, nla); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2627 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2628 | if (0) |
| 2629 | nla_put_failure: |
| 2630 | err = -EMSGSIZE; |
| 2631 | if (got_ldev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2632 | put_ldev(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2633 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2636 | 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] | 2637 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2638 | enum drbd_ret_code retcode; |
| 2639 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2640 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2641 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2642 | if (!adm_ctx.reply_skb) |
| 2643 | return retcode; |
| 2644 | if (retcode != NO_ERROR) |
| 2645 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2646 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2647 | err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.mdev, NULL); |
| 2648 | if (err) { |
| 2649 | nlmsg_free(adm_ctx.reply_skb); |
| 2650 | return err; |
| 2651 | } |
| 2652 | out: |
| 2653 | drbd_adm_finish(info, retcode); |
| 2654 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2657 | int get_one_status(struct sk_buff *skb, struct netlink_callback *cb) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2658 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2659 | struct drbd_conf *mdev; |
| 2660 | struct drbd_genlmsghdr *dh; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2661 | struct drbd_tconn *pos = (struct drbd_tconn*)cb->args[0]; |
| 2662 | struct drbd_tconn *tconn = NULL; |
| 2663 | struct drbd_tconn *tmp; |
| 2664 | unsigned volume = cb->args[1]; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2665 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2666 | /* Open coded, deferred, iteration: |
| 2667 | * list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) { |
| 2668 | * idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 2669 | * ... |
| 2670 | * } |
| 2671 | * } |
| 2672 | * where tconn is cb->args[0]; |
| 2673 | * and i is cb->args[1]; |
| 2674 | * |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2675 | * cb->args[2] indicates if we shall loop over all resources, |
| 2676 | * or just dump all volumes of a single resource. |
| 2677 | * |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2678 | * This may miss entries inserted after this dump started, |
| 2679 | * or entries deleted before they are reached. |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2680 | * |
| 2681 | * We need to make sure the mdev won't disappear while |
| 2682 | * we are looking at it, and revalidate our iterators |
| 2683 | * on each iteration. |
| 2684 | */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2685 | |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 2686 | /* synchronize with conn_create()/conn_destroy() */ |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 2687 | rcu_read_lock(); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2688 | /* revalidate iterator position */ |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 2689 | list_for_each_entry_rcu(tmp, &drbd_tconns, all_tconn) { |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2690 | if (pos == NULL) { |
| 2691 | /* first iteration */ |
| 2692 | pos = tmp; |
| 2693 | tconn = pos; |
| 2694 | break; |
| 2695 | } |
| 2696 | if (tmp == pos) { |
| 2697 | tconn = pos; |
| 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | if (tconn) { |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2702 | next_tconn: |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2703 | mdev = idr_get_next(&tconn->volumes, &volume); |
| 2704 | if (!mdev) { |
| 2705 | /* No more volumes to dump on this tconn. |
| 2706 | * Advance tconn iterator. */ |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 2707 | pos = list_entry_rcu(tconn->all_tconn.next, |
| 2708 | struct drbd_tconn, all_tconn); |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2709 | /* Did we dump any volume on this tconn yet? */ |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2710 | if (volume != 0) { |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2711 | /* If we reached the end of the list, |
| 2712 | * or only a single resource dump was requested, |
| 2713 | * we are done. */ |
| 2714 | if (&pos->all_tconn == &drbd_tconns || cb->args[2]) |
| 2715 | goto out; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2716 | volume = 0; |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2717 | tconn = pos; |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2718 | goto next_tconn; |
| 2719 | } |
| 2720 | } |
| 2721 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2722 | dh = genlmsg_put(skb, NETLINK_CB(cb->skb).pid, |
| 2723 | cb->nlh->nlmsg_seq, &drbd_genl_family, |
| 2724 | NLM_F_MULTI, DRBD_ADM_GET_STATUS); |
| 2725 | if (!dh) |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2726 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2727 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2728 | if (!mdev) { |
| 2729 | /* this is a tconn without a single volume */ |
| 2730 | dh->minor = -1U; |
| 2731 | dh->ret_code = NO_ERROR; |
| 2732 | if (nla_put_drbd_cfg_context(skb, tconn->name, VOLUME_UNSPECIFIED)) |
| 2733 | genlmsg_cancel(skb, dh); |
| 2734 | else |
| 2735 | genlmsg_end(skb, dh); |
| 2736 | goto out; |
| 2737 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2738 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2739 | D_ASSERT(mdev->vnr == volume); |
| 2740 | D_ASSERT(mdev->tconn == tconn); |
| 2741 | |
| 2742 | dh->minor = mdev_to_minor(mdev); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2743 | dh->ret_code = NO_ERROR; |
| 2744 | |
| 2745 | if (nla_put_status_info(skb, mdev, NULL)) { |
| 2746 | genlmsg_cancel(skb, dh); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2747 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2748 | } |
| 2749 | genlmsg_end(skb, dh); |
| 2750 | } |
| 2751 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2752 | out: |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 2753 | rcu_read_unlock(); |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2754 | /* where to start the next iteration */ |
| 2755 | cb->args[0] = (long)pos; |
| 2756 | cb->args[1] = (pos == tconn) ? volume + 1 : 0; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2757 | |
Lars Ellenberg | 543cc10 | 2011-03-10 22:18:18 +0100 | [diff] [blame] | 2758 | /* No more tconns/volumes/minors found results in an empty skb. |
| 2759 | * Which will terminate the dump. */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2760 | return skb->len; |
| 2761 | } |
| 2762 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2763 | /* |
| 2764 | * Request status of all resources, or of all volumes within a single resource. |
| 2765 | * |
| 2766 | * This is a dump, as the answer may not fit in a single reply skb otherwise. |
| 2767 | * Which means we cannot use the family->attrbuf or other such members, because |
| 2768 | * dump is NOT protected by the genl_lock(). During dump, we only have access |
| 2769 | * to the incoming skb, and need to opencode "parsing" of the nlattr payload. |
| 2770 | * |
| 2771 | * Once things are setup properly, we call into get_one_status(). |
| 2772 | */ |
| 2773 | int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb) |
| 2774 | { |
| 2775 | const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ; |
| 2776 | struct nlattr *nla; |
| 2777 | const char *conn_name; |
| 2778 | struct drbd_tconn *tconn; |
| 2779 | |
| 2780 | /* Is this a followup call? */ |
| 2781 | if (cb->args[0]) { |
| 2782 | /* ... of a single resource dump, |
| 2783 | * and the resource iterator has been advanced already? */ |
| 2784 | if (cb->args[2] && cb->args[2] != cb->args[0]) |
| 2785 | return 0; /* DONE. */ |
| 2786 | goto dump; |
| 2787 | } |
| 2788 | |
| 2789 | /* First call (from netlink_dump_start). We need to figure out |
| 2790 | * which resource(s) the user wants us to dump. */ |
| 2791 | nla = nla_find(nlmsg_attrdata(cb->nlh, hdrlen), |
| 2792 | nlmsg_attrlen(cb->nlh, hdrlen), |
| 2793 | DRBD_NLA_CFG_CONTEXT); |
| 2794 | |
| 2795 | /* No explicit context given. Dump all. */ |
| 2796 | if (!nla) |
| 2797 | goto dump; |
| 2798 | nla = nla_find_nested(nla, __nla_type(T_ctx_conn_name)); |
| 2799 | /* context given, but no name present? */ |
| 2800 | if (!nla) |
| 2801 | return -EINVAL; |
| 2802 | conn_name = nla_data(nla); |
Philipp Reisner | 0ace9df | 2011-04-24 10:53:19 +0200 | [diff] [blame] | 2803 | tconn = conn_get_by_name(conn_name); |
| 2804 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2805 | if (!tconn) |
| 2806 | return -ENODEV; |
| 2807 | |
Philipp Reisner | 0ace9df | 2011-04-24 10:53:19 +0200 | [diff] [blame] | 2808 | kref_put(&tconn->kref, &conn_destroy); /* get_one_status() (re)validates tconn by itself */ |
| 2809 | |
Lars Ellenberg | 71932ef | 2011-04-18 09:43:25 +0200 | [diff] [blame] | 2810 | /* prime iterators, and set "filter" mode mark: |
| 2811 | * only dump this tconn. */ |
| 2812 | cb->args[0] = (long)tconn; |
| 2813 | /* cb->args[1] = 0; passed in this way. */ |
| 2814 | cb->args[2] = (long)tconn; |
| 2815 | |
| 2816 | dump: |
| 2817 | return get_one_status(skb, cb); |
| 2818 | } |
| 2819 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2820 | int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info) |
| 2821 | { |
| 2822 | enum drbd_ret_code retcode; |
| 2823 | struct timeout_parms tp; |
| 2824 | int err; |
| 2825 | |
| 2826 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2827 | if (!adm_ctx.reply_skb) |
| 2828 | return retcode; |
| 2829 | if (retcode != NO_ERROR) |
| 2830 | goto out; |
| 2831 | |
| 2832 | tp.timeout_type = |
| 2833 | adm_ctx.mdev->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED : |
| 2834 | test_bit(USE_DEGR_WFC_T, &adm_ctx.mdev->flags) ? UT_DEGRADED : |
| 2835 | UT_DEFAULT; |
| 2836 | |
| 2837 | err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp); |
| 2838 | if (err) { |
| 2839 | nlmsg_free(adm_ctx.reply_skb); |
| 2840 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2841 | } |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2842 | out: |
| 2843 | drbd_adm_finish(info, retcode); |
| 2844 | return 0; |
| 2845 | } |
Lars Ellenberg | 873b0d5 | 2011-01-21 22:53:48 +0100 | [diff] [blame] | 2846 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2847 | int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info) |
| 2848 | { |
| 2849 | struct drbd_conf *mdev; |
| 2850 | enum drbd_ret_code retcode; |
| 2851 | |
| 2852 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2853 | if (!adm_ctx.reply_skb) |
| 2854 | return retcode; |
| 2855 | if (retcode != NO_ERROR) |
| 2856 | goto out; |
| 2857 | |
| 2858 | mdev = adm_ctx.mdev; |
| 2859 | if (info->attrs[DRBD_NLA_START_OV_PARMS]) { |
| 2860 | /* resume from last known position, if possible */ |
| 2861 | struct start_ov_parms parms = |
| 2862 | { .ov_start_sector = mdev->ov_start_sector }; |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2863 | int err = start_ov_parms_from_attrs(&parms, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2864 | if (err) { |
| 2865 | retcode = ERR_MANDATORY_TAG; |
| 2866 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2867 | goto out; |
| 2868 | } |
| 2869 | /* w_make_ov_request expects position to be aligned */ |
| 2870 | mdev->ov_start_sector = parms.ov_start_sector & ~BM_SECT_PER_BIT; |
| 2871 | } |
Lars Ellenberg | 873b0d5 | 2011-01-21 22:53:48 +0100 | [diff] [blame] | 2872 | /* If there is still bitmap IO pending, e.g. previous resync or verify |
| 2873 | * just being finished, wait for it before requesting a new resync. */ |
| 2874 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2875 | retcode = drbd_request_state(mdev,NS(conn,C_VERIFY_S)); |
| 2876 | out: |
| 2877 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2878 | return 0; |
| 2879 | } |
| 2880 | |
| 2881 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2882 | 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] | 2883 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2884 | struct drbd_conf *mdev; |
| 2885 | enum drbd_ret_code retcode; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2886 | int skip_initial_sync = 0; |
| 2887 | int err; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2888 | struct new_c_uuid_parms args; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2889 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2890 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 2891 | if (!adm_ctx.reply_skb) |
| 2892 | return retcode; |
| 2893 | if (retcode != NO_ERROR) |
| 2894 | goto out_nolock; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2895 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2896 | mdev = adm_ctx.mdev; |
| 2897 | memset(&args, 0, sizeof(args)); |
| 2898 | if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) { |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 2899 | err = new_c_uuid_parms_from_attrs(&args, info); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2900 | if (err) { |
| 2901 | retcode = ERR_MANDATORY_TAG; |
| 2902 | drbd_msg_put_info(from_attrs_err_to_txt(err)); |
| 2903 | goto out_nolock; |
| 2904 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 2907 | mutex_lock(mdev->state_mutex); /* Protects us against serialized state changes. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2908 | |
| 2909 | if (!get_ldev(mdev)) { |
| 2910 | retcode = ERR_NO_DISK; |
| 2911 | goto out; |
| 2912 | } |
| 2913 | |
| 2914 | /* this is "skip initial sync", assume to be clean */ |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2915 | if (mdev->state.conn == C_CONNECTED && mdev->tconn->agreed_pro_version >= 90 && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2916 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) { |
| 2917 | dev_info(DEV, "Preparing to skip initial sync\n"); |
| 2918 | skip_initial_sync = 1; |
| 2919 | } else if (mdev->state.conn != C_STANDALONE) { |
| 2920 | retcode = ERR_CONNECTED; |
| 2921 | goto out_dec; |
| 2922 | } |
| 2923 | |
| 2924 | drbd_uuid_set(mdev, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */ |
| 2925 | drbd_uuid_new_current(mdev); /* New current, previous to UI_BITMAP */ |
| 2926 | |
| 2927 | if (args.clear_bm) { |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 2928 | err = drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, |
| 2929 | "clear_n_write from new_c_uuid", BM_LOCKED_MASK); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2930 | if (err) { |
| 2931 | dev_err(DEV, "Writing bitmap failed with %d\n",err); |
| 2932 | retcode = ERR_IO_MD_DISK; |
| 2933 | } |
| 2934 | if (skip_initial_sync) { |
| 2935 | drbd_send_uuids_skip_initial_sync(mdev); |
| 2936 | _drbd_uuid_set(mdev, UI_BITMAP, 0); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 2937 | drbd_print_uuids(mdev, "cleared bitmap UUID"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2938 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2939 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
| 2940 | CS_VERBOSE, NULL); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2941 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | drbd_md_sync(mdev); |
| 2946 | out_dec: |
| 2947 | put_ldev(mdev); |
| 2948 | out: |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 2949 | mutex_unlock(mdev->state_mutex); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2950 | out_nolock: |
| 2951 | drbd_adm_finish(info, retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2952 | return 0; |
| 2953 | } |
| 2954 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2955 | static enum drbd_ret_code |
| 2956 | drbd_check_conn_name(const char *name) |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 2957 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2958 | if (!name || !name[0]) { |
| 2959 | drbd_msg_put_info("connection name missing"); |
| 2960 | return ERR_MANDATORY_TAG; |
| 2961 | } |
| 2962 | /* if we want to use these in sysfs/configfs/debugfs some day, |
| 2963 | * we must not allow slashes */ |
| 2964 | if (strchr(name, '/')) { |
| 2965 | drbd_msg_put_info("invalid connection name"); |
| 2966 | return ERR_INVALID_REQUEST; |
| 2967 | } |
| 2968 | return NO_ERROR; |
| 2969 | } |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 2970 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2971 | int drbd_adm_create_connection(struct sk_buff *skb, struct genl_info *info) |
| 2972 | { |
| 2973 | enum drbd_ret_code retcode; |
| 2974 | |
| 2975 | retcode = drbd_adm_prepare(skb, info, 0); |
| 2976 | if (!adm_ctx.reply_skb) |
| 2977 | return retcode; |
| 2978 | if (retcode != NO_ERROR) |
| 2979 | goto out; |
| 2980 | |
| 2981 | retcode = drbd_check_conn_name(adm_ctx.conn_name); |
| 2982 | if (retcode != NO_ERROR) |
| 2983 | goto out; |
| 2984 | |
| 2985 | if (adm_ctx.tconn) { |
Lars Ellenberg | 38f1961 | 2011-03-14 13:22:35 +0100 | [diff] [blame] | 2986 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) { |
| 2987 | retcode = ERR_INVALID_REQUEST; |
| 2988 | drbd_msg_put_info("connection exists"); |
| 2989 | } |
| 2990 | /* else: still NO_ERROR */ |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2991 | goto out; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 2992 | } |
| 2993 | |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 2994 | if (!conn_create(adm_ctx.conn_name)) |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 2995 | retcode = ERR_NOMEM; |
| 2996 | out: |
| 2997 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 2998 | return 0; |
| 2999 | } |
| 3000 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3001 | 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] | 3002 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3003 | struct drbd_genlmsghdr *dh = info->userhdr; |
| 3004 | enum drbd_ret_code retcode; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3005 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3006 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
| 3007 | if (!adm_ctx.reply_skb) |
| 3008 | return retcode; |
| 3009 | if (retcode != NO_ERROR) |
| 3010 | goto out; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3011 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3012 | /* FIXME drop minor_count parameter, limit to MINORMASK */ |
| 3013 | if (dh->minor >= minor_count) { |
| 3014 | drbd_msg_put_info("requested minor out of range"); |
| 3015 | retcode = ERR_INVALID_REQUEST; |
| 3016 | goto out; |
| 3017 | } |
Andreas Gruenbacher | 0c8e36d | 2011-03-30 16:00:17 +0200 | [diff] [blame] | 3018 | if (adm_ctx.volume > DRBD_VOLUME_MAX) { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3019 | drbd_msg_put_info("requested volume id out of range"); |
| 3020 | retcode = ERR_INVALID_REQUEST; |
| 3021 | goto out; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3022 | } |
| 3023 | |
Lars Ellenberg | 38f1961 | 2011-03-14 13:22:35 +0100 | [diff] [blame] | 3024 | /* drbd_adm_prepare made sure already |
| 3025 | * that mdev->tconn and mdev->vnr match the request. */ |
| 3026 | if (adm_ctx.mdev) { |
| 3027 | if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) |
| 3028 | retcode = ERR_MINOR_EXISTS; |
| 3029 | /* else: still NO_ERROR */ |
| 3030 | goto out; |
| 3031 | } |
| 3032 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3033 | retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume); |
| 3034 | out: |
| 3035 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3036 | return 0; |
| 3037 | } |
| 3038 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3039 | static enum drbd_ret_code adm_delete_minor(struct drbd_conf *mdev) |
| 3040 | { |
| 3041 | if (mdev->state.disk == D_DISKLESS && |
| 3042 | /* no need to be mdev->state.conn == C_STANDALONE && |
| 3043 | * we may want to delete a minor from a live replication group. |
| 3044 | */ |
| 3045 | mdev->state.role == R_SECONDARY) { |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 3046 | idr_remove(&mdev->tconn->volumes, mdev->vnr); |
| 3047 | idr_remove(&minors, mdev_to_minor(mdev)); |
| 3048 | del_gendisk(mdev->vdisk); |
| 3049 | synchronize_rcu(); |
| 3050 | kref_put(&mdev->kref, &drbd_minor_destroy); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3051 | return NO_ERROR; |
| 3052 | } else |
| 3053 | return ERR_MINOR_CONFIGURED; |
| 3054 | } |
| 3055 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3056 | 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] | 3057 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3058 | enum drbd_ret_code retcode; |
| 3059 | |
| 3060 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR); |
| 3061 | if (!adm_ctx.reply_skb) |
| 3062 | return retcode; |
| 3063 | if (retcode != NO_ERROR) |
| 3064 | goto out; |
| 3065 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3066 | retcode = adm_delete_minor(adm_ctx.mdev); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3067 | out: |
| 3068 | drbd_adm_finish(info, retcode); |
| 3069 | return 0; |
| 3070 | } |
| 3071 | |
| 3072 | int drbd_adm_down(struct sk_buff *skb, struct genl_info *info) |
| 3073 | { |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3074 | int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */ |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3075 | struct drbd_conf *mdev; |
| 3076 | unsigned i; |
| 3077 | |
| 3078 | retcode = drbd_adm_prepare(skb, info, 0); |
| 3079 | if (!adm_ctx.reply_skb) |
| 3080 | return retcode; |
| 3081 | if (retcode != NO_ERROR) |
| 3082 | goto out; |
| 3083 | |
| 3084 | if (!adm_ctx.tconn) { |
| 3085 | retcode = ERR_CONN_NOT_KNOWN; |
| 3086 | goto out; |
| 3087 | } |
| 3088 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3089 | /* demote */ |
| 3090 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
| 3091 | retcode = drbd_set_role(mdev, R_SECONDARY, 0); |
| 3092 | if (retcode < SS_SUCCESS) { |
| 3093 | drbd_msg_put_info("failed to demote"); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3094 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3098 | retcode = conn_try_disconnect(adm_ctx.tconn, 0); |
| 3099 | if (retcode < SS_SUCCESS) { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3100 | drbd_msg_put_info("failed to disconnect"); |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3101 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | /* detach */ |
| 3105 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3106 | retcode = adm_detach(mdev); |
| 3107 | if (retcode < SS_SUCCESS) { |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3108 | drbd_msg_put_info("failed to detach"); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3109 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3110 | } |
| 3111 | } |
| 3112 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3113 | /* If we reach this, all volumes (of this tconn) are Secondary, |
| 3114 | * Disconnected, Diskless, aka Unconfigured. Make sure all threads have |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 3115 | * actually stopped, state handling only does drbd_thread_stop_nowait(). */ |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 3116 | drbd_thread_stop(&adm_ctx.tconn->worker); |
| 3117 | |
| 3118 | /* Now, nothing can fail anymore */ |
| 3119 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3120 | /* delete volumes */ |
| 3121 | idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) { |
| 3122 | retcode = adm_delete_minor(mdev); |
| 3123 | if (retcode != NO_ERROR) { |
| 3124 | /* "can not happen" */ |
| 3125 | drbd_msg_put_info("failed to delete volume"); |
Philipp Reisner | ef35626 | 2011-04-13 14:21:29 -0700 | [diff] [blame] | 3126 | goto out; |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3130 | /* delete connection */ |
| 3131 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 3132 | list_del_rcu(&adm_ctx.tconn->all_tconn); |
| 3133 | synchronize_rcu(); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 3134 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); |
| 3135 | |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3136 | retcode = NO_ERROR; |
| 3137 | } else { |
| 3138 | /* "can not happen" */ |
| 3139 | retcode = ERR_CONN_IN_USE; |
| 3140 | drbd_msg_put_info("failed to delete connection"); |
Lars Ellenberg | 85f75dd7 | 2011-03-15 16:26:37 +0100 | [diff] [blame] | 3141 | } |
Philipp Reisner | ef35626 | 2011-04-13 14:21:29 -0700 | [diff] [blame] | 3142 | goto out; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3143 | out: |
| 3144 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3145 | return 0; |
| 3146 | } |
| 3147 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3148 | 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] | 3149 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3150 | enum drbd_ret_code retcode; |
| 3151 | |
| 3152 | retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONN); |
| 3153 | if (!adm_ctx.reply_skb) |
| 3154 | return retcode; |
| 3155 | if (retcode != NO_ERROR) |
| 3156 | goto out; |
| 3157 | |
| 3158 | if (conn_lowest_minor(adm_ctx.tconn) < 0) { |
Philipp Reisner | ec0bddb | 2011-05-04 15:47:01 +0200 | [diff] [blame] | 3159 | list_del_rcu(&adm_ctx.tconn->all_tconn); |
| 3160 | synchronize_rcu(); |
Philipp Reisner | 9dc9fbb | 2011-04-22 15:23:32 +0200 | [diff] [blame] | 3161 | kref_put(&adm_ctx.tconn->kref, &conn_destroy); |
| 3162 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3163 | retcode = NO_ERROR; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3164 | } else { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3165 | retcode = ERR_CONN_IN_USE; |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3166 | } |
| 3167 | |
Lars Ellenberg | 992d6e9 | 2011-05-02 11:47:18 +0200 | [diff] [blame] | 3168 | if (retcode == NO_ERROR) |
| 3169 | drbd_thread_stop(&adm_ctx.tconn->worker); |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3170 | out: |
| 3171 | drbd_adm_finish(info, retcode); |
Philipp Reisner | 774b305 | 2011-02-22 02:07:03 -0500 | [diff] [blame] | 3172 | return 0; |
| 3173 | } |
| 3174 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3175 | 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] | 3176 | { |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3177 | static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */ |
| 3178 | struct sk_buff *msg; |
| 3179 | struct drbd_genlmsghdr *d_out; |
| 3180 | unsigned seq; |
| 3181 | int err = -ENOMEM; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3182 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3183 | seq = atomic_inc_return(&drbd_genl_seq); |
| 3184 | msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO); |
| 3185 | if (!msg) |
| 3186 | goto failed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3187 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3188 | err = -EMSGSIZE; |
| 3189 | d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT); |
| 3190 | if (!d_out) /* cannot happen, but anyways. */ |
| 3191 | goto nla_put_failure; |
| 3192 | d_out->minor = mdev_to_minor(mdev); |
Andreas Gruenbacher | 6f9b5f8 | 2011-05-06 01:03:32 +0200 | [diff] [blame] | 3193 | d_out->ret_code = NO_ERROR; |
Philipp Reisner | 9f5180e | 2009-10-06 09:30:14 +0200 | [diff] [blame] | 3194 | |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3195 | if (nla_put_status_info(msg, mdev, sib)) |
| 3196 | goto nla_put_failure; |
| 3197 | genlmsg_end(msg, d_out); |
| 3198 | err = drbd_genl_multicast_events(msg, 0); |
| 3199 | /* msg has been consumed or freed in netlink_broadcast() */ |
| 3200 | if (err && err != -ESRCH) |
| 3201 | goto failed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3202 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3203 | return; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 3204 | |
| 3205 | nla_put_failure: |
| 3206 | nlmsg_free(msg); |
| 3207 | failed: |
| 3208 | dev_err(DEV, "Error %d while broadcasting event. " |
| 3209 | "Event seq:%u sib_reason:%u\n", |
| 3210 | err, seq, sib->sib_reason); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3211 | } |