2009-09-25 23:07:19 +00:00
|
|
|
/*
|
|
|
|
drbd_nl.c
|
|
|
|
|
|
|
|
This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
|
|
|
|
|
|
|
|
Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
|
|
|
|
Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
|
|
|
|
Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
|
|
|
|
|
|
|
|
drbd is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
drbd is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with drbd; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/drbd.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/blkpg.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include "drbd_int.h"
|
2011-05-30 09:47:37 +00:00
|
|
|
#include "drbd_protocol.h"
|
2010-05-31 08:14:17 +00:00
|
|
|
#include "drbd_req.h"
|
2009-09-25 23:07:19 +00:00
|
|
|
#include "drbd_wrappers.h"
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
#include <linux/drbd_limits.h>
|
2010-06-11 11:56:33 +00:00
|
|
|
#include <linux/kthread.h>
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
#include <net/genetlink.h>
|
|
|
|
|
|
|
|
/* .doit */
|
|
|
|
// int drbd_adm_create_resource(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
// int drbd_adm_delete_resource(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
int drbd_adm_new_minor(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_del_minor(struct sk_buff *skb, struct genl_info *info);
|
2011-03-07 11:49:34 +00:00
|
|
|
|
2011-06-06 14:16:44 +00:00
|
|
|
int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info);
|
2011-03-15 15:26:37 +00:00
|
|
|
int drbd_adm_down(struct sk_buff *skb, struct genl_info *info);
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info);
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info);
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info);
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info);
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info);
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info);
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
/* .dumpit */
|
|
|
|
int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb);
|
|
|
|
|
|
|
|
#include <linux/drbd_genl_api.h>
|
2011-06-10 10:57:26 +00:00
|
|
|
#include "drbd_nla.h"
|
2011-03-07 11:49:34 +00:00
|
|
|
#include <linux/genl_magic_func.h>
|
|
|
|
|
|
|
|
/* used blkdev_get_by_path, to claim our meta data device(s) */
|
2009-09-25 23:07:19 +00:00
|
|
|
static char *drbd_m_holder = "Hands off! this is DRBD's meta data device.";
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
/* Configuration is strictly serialized, because generic netlink message
|
|
|
|
* processing is strictly serialized by the genl_lock().
|
|
|
|
* Which means we can use one static global drbd_config_context struct.
|
|
|
|
*/
|
|
|
|
static struct drbd_config_context {
|
|
|
|
/* assigned from drbd_genlmsghdr */
|
|
|
|
unsigned int minor;
|
|
|
|
/* assigned from request attributes, if present */
|
|
|
|
unsigned int volume;
|
|
|
|
#define VOLUME_UNSPECIFIED (-1U)
|
|
|
|
/* pointer into the request skb,
|
|
|
|
* limited lifetime! */
|
2011-06-09 15:52:12 +00:00
|
|
|
char *resource_name;
|
2011-06-14 16:28:09 +00:00
|
|
|
struct nlattr *my_addr;
|
|
|
|
struct nlattr *peer_addr;
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
/* reply buffer */
|
|
|
|
struct sk_buff *reply_skb;
|
|
|
|
/* pointer into reply buffer */
|
|
|
|
struct drbd_genlmsghdr *reply_dh;
|
|
|
|
/* resolved from attributes, if possible */
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-06-13 12:27:45 +00:00
|
|
|
struct drbd_resource *resource;
|
2011-05-30 14:32:41 +00:00
|
|
|
struct drbd_connection *connection;
|
2011-03-07 11:49:34 +00:00
|
|
|
} adm_ctx;
|
|
|
|
|
|
|
|
static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
genlmsg_end(skb, genlmsg_data(nlmsg_data(nlmsg_hdr(skb))));
|
|
|
|
if (genlmsg_reply(skb, info))
|
|
|
|
printk(KERN_ERR "drbd: error sending genl reply\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
/* Used on a fresh "drbd_adm_prepare"d reply_skb, this cannot fail: The only
|
|
|
|
* reason it could fail was no space in skb, and there are 4k available. */
|
2011-03-08 15:11:16 +00:00
|
|
|
int drbd_msg_put_info(const char *info)
|
2011-03-07 11:49:34 +00:00
|
|
|
{
|
|
|
|
struct sk_buff *skb = adm_ctx.reply_skb;
|
|
|
|
struct nlattr *nla;
|
|
|
|
int err = -EMSGSIZE;
|
|
|
|
|
|
|
|
if (!info || !info[0])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY);
|
|
|
|
if (!nla)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = nla_put_string(skb, T_info_text, info);
|
|
|
|
if (err) {
|
|
|
|
nla_nest_cancel(skb, nla);
|
|
|
|
return err;
|
|
|
|
} else
|
|
|
|
nla_nest_end(skb, nla);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
/* This would be a good candidate for a "pre_doit" hook,
|
|
|
|
* and per-family private info->pointers.
|
|
|
|
* But we need to stay compatible with older kernels.
|
|
|
|
* If it returns successfully, adm_ctx members are valid.
|
|
|
|
*/
|
|
|
|
#define DRBD_ADM_NEED_MINOR 1
|
2011-06-14 14:07:32 +00:00
|
|
|
#define DRBD_ADM_NEED_RESOURCE 2
|
2011-06-14 16:28:09 +00:00
|
|
|
#define DRBD_ADM_NEED_CONNECTION 4
|
2011-03-07 11:49:34 +00:00
|
|
|
static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
|
|
|
struct drbd_genlmsghdr *d_in = info->userhdr;
|
|
|
|
const u8 cmd = info->genlhdr->cmd;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&adm_ctx, 0, sizeof(adm_ctx));
|
|
|
|
|
|
|
|
/* genl_rcv_msg only checks for CAP_NET_ADMIN on "GENL_ADMIN_PERM" :( */
|
2012-11-09 13:18:43 +00:00
|
|
|
if (cmd != DRBD_ADM_GET_STATUS && !capable(CAP_NET_ADMIN))
|
2011-03-07 11:49:34 +00:00
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
adm_ctx.reply_skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
2011-05-24 12:17:08 +00:00
|
|
|
if (!adm_ctx.reply_skb) {
|
|
|
|
err = -ENOMEM;
|
2011-03-07 11:49:34 +00:00
|
|
|
goto fail;
|
2011-05-24 12:17:08 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
adm_ctx.reply_dh = genlmsg_put_reply(adm_ctx.reply_skb,
|
|
|
|
info, &drbd_genl_family, 0, cmd);
|
|
|
|
/* put of a few bytes into a fresh skb of >= 4k will always succeed.
|
|
|
|
* but anyways */
|
2011-05-24 12:17:08 +00:00
|
|
|
if (!adm_ctx.reply_dh) {
|
|
|
|
err = -ENOMEM;
|
2011-03-07 11:49:34 +00:00
|
|
|
goto fail;
|
2011-05-24 12:17:08 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
adm_ctx.reply_dh->minor = d_in->minor;
|
|
|
|
adm_ctx.reply_dh->ret_code = NO_ERROR;
|
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
adm_ctx.volume = VOLUME_UNSPECIFIED;
|
2011-03-07 11:49:34 +00:00
|
|
|
if (info->attrs[DRBD_NLA_CFG_CONTEXT]) {
|
|
|
|
struct nlattr *nla;
|
|
|
|
/* parse and validate only */
|
2011-03-23 13:31:09 +00:00
|
|
|
err = drbd_cfg_context_from_attrs(NULL, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* It was present, and valid,
|
|
|
|
* copy it over to the reply skb. */
|
|
|
|
err = nla_put_nohdr(adm_ctx.reply_skb,
|
|
|
|
info->attrs[DRBD_NLA_CFG_CONTEXT]->nla_len,
|
|
|
|
info->attrs[DRBD_NLA_CFG_CONTEXT]);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* and assign stuff to the global adm_ctx */
|
|
|
|
nla = nested_attr_tb[__nla_type(T_ctx_volume)];
|
2011-06-14 16:28:09 +00:00
|
|
|
if (nla)
|
|
|
|
adm_ctx.volume = nla_get_u32(nla);
|
2011-06-09 15:52:12 +00:00
|
|
|
nla = nested_attr_tb[__nla_type(T_ctx_resource_name)];
|
2011-03-07 11:49:34 +00:00
|
|
|
if (nla)
|
2011-06-09 15:52:12 +00:00
|
|
|
adm_ctx.resource_name = nla_data(nla);
|
2011-06-14 16:28:09 +00:00
|
|
|
adm_ctx.my_addr = nested_attr_tb[__nla_type(T_ctx_my_addr)];
|
|
|
|
adm_ctx.peer_addr = nested_attr_tb[__nla_type(T_ctx_peer_addr)];
|
|
|
|
if ((adm_ctx.my_addr &&
|
2011-05-30 14:32:41 +00:00
|
|
|
nla_len(adm_ctx.my_addr) > sizeof(adm_ctx.connection->my_addr)) ||
|
2011-06-14 16:28:09 +00:00
|
|
|
(adm_ctx.peer_addr &&
|
2011-05-30 14:32:41 +00:00
|
|
|
nla_len(adm_ctx.peer_addr) > sizeof(adm_ctx.connection->peer_addr))) {
|
2011-06-14 16:28:09 +00:00
|
|
|
err = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
adm_ctx.minor = d_in->minor;
|
2011-07-03 11:26:43 +00:00
|
|
|
adm_ctx.device = minor_to_device(d_in->minor);
|
2011-06-13 12:27:45 +00:00
|
|
|
if (adm_ctx.resource_name) {
|
|
|
|
adm_ctx.resource = drbd_find_resource(adm_ctx.resource_name);
|
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!adm_ctx.device && (flags & DRBD_ADM_NEED_MINOR)) {
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info("unknown minor");
|
|
|
|
return ERR_MINOR_INVALID;
|
|
|
|
}
|
2011-06-13 12:27:45 +00:00
|
|
|
if (!adm_ctx.resource && (flags & DRBD_ADM_NEED_RESOURCE)) {
|
2011-06-14 14:07:32 +00:00
|
|
|
drbd_msg_put_info("unknown resource");
|
2011-06-08 23:26:16 +00:00
|
|
|
if (adm_ctx.resource_name)
|
|
|
|
return ERR_RES_NOT_KNOWN;
|
2011-03-07 11:49:34 +00:00
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
if (flags & DRBD_ADM_NEED_CONNECTION) {
|
2011-07-06 13:05:58 +00:00
|
|
|
if (adm_ctx.resource) {
|
2011-06-14 16:28:09 +00:00
|
|
|
drbd_msg_put_info("no resource name expected");
|
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
if (adm_ctx.device) {
|
2011-06-14 16:28:09 +00:00
|
|
|
drbd_msg_put_info("no minor number expected");
|
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
|
|
|
if (adm_ctx.my_addr && adm_ctx.peer_addr)
|
2011-05-30 14:32:41 +00:00
|
|
|
adm_ctx.connection = conn_get_by_addrs(nla_data(adm_ctx.my_addr),
|
2011-06-14 16:28:09 +00:00
|
|
|
nla_len(adm_ctx.my_addr),
|
|
|
|
nla_data(adm_ctx.peer_addr),
|
|
|
|
nla_len(adm_ctx.peer_addr));
|
2011-05-30 14:32:41 +00:00
|
|
|
if (!adm_ctx.connection) {
|
2011-06-14 16:28:09 +00:00
|
|
|
drbd_msg_put_info("unknown connection");
|
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
/* some more paranoia, if the request was over-determined */
|
2011-06-13 12:27:45 +00:00
|
|
|
if (adm_ctx.device && adm_ctx.resource &&
|
|
|
|
adm_ctx.device->resource != adm_ctx.resource) {
|
|
|
|
pr_warning("request: minor=%u, resource=%s; but that minor belongs to resource %s\n",
|
|
|
|
adm_ctx.minor, adm_ctx.resource->name,
|
2011-06-08 23:38:00 +00:00
|
|
|
adm_ctx.device->resource->name);
|
2011-06-14 14:07:32 +00:00
|
|
|
drbd_msg_put_info("minor exists in different resource");
|
2011-03-14 12:58:03 +00:00
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
if (adm_ctx.device &&
|
2011-03-07 11:49:34 +00:00
|
|
|
adm_ctx.volume != VOLUME_UNSPECIFIED &&
|
2011-07-03 11:26:43 +00:00
|
|
|
adm_ctx.volume != adm_ctx.device->vnr) {
|
2011-03-07 11:49:34 +00:00
|
|
|
pr_warning("request: minor=%u, volume=%u; but that minor is volume %u in %s\n",
|
|
|
|
adm_ctx.minor, adm_ctx.volume,
|
2011-06-08 20:17:38 +00:00
|
|
|
adm_ctx.device->vnr,
|
2011-06-08 23:38:00 +00:00
|
|
|
adm_ctx.device->resource->name);
|
2011-03-14 12:58:03 +00:00
|
|
|
drbd_msg_put_info("minor exists as different volume");
|
2011-03-07 11:49:34 +00:00
|
|
|
return ERR_INVALID_REQUEST;
|
|
|
|
}
|
2011-04-24 08:53:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
nlmsg_free(adm_ctx.reply_skb);
|
|
|
|
adm_ctx.reply_skb = NULL;
|
2011-05-24 12:17:08 +00:00
|
|
|
return err;
|
2011-03-07 11:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int drbd_adm_finish(struct genl_info *info, int retcode)
|
|
|
|
{
|
2011-05-30 14:32:41 +00:00
|
|
|
if (adm_ctx.connection) {
|
2011-06-07 20:54:17 +00:00
|
|
|
kref_put(&adm_ctx.connection->kref, drbd_destroy_connection);
|
2011-05-30 14:32:41 +00:00
|
|
|
adm_ctx.connection = NULL;
|
2011-04-24 08:53:19 +00:00
|
|
|
}
|
2011-06-13 12:27:45 +00:00
|
|
|
if (adm_ctx.resource) {
|
|
|
|
kref_put(&adm_ctx.resource->kref, drbd_destroy_resource);
|
|
|
|
adm_ctx.resource = NULL;
|
|
|
|
}
|
2011-04-24 08:53:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
adm_ctx.reply_dh->ret_code = retcode;
|
|
|
|
drbd_adm_send_reply(adm_ctx.reply_skb, info);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static void setup_khelper_env(struct drbd_connection *connection, char **envp)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-16 16:39:12 +00:00
|
|
|
char *afs;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
/* FIXME: A future version will not allow this case. */
|
2011-05-30 14:32:41 +00:00
|
|
|
if (connection->my_addr_len == 0 || connection->peer_addr_len == 0)
|
2011-06-14 16:28:09 +00:00
|
|
|
return;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
switch (((struct sockaddr *)&connection->peer_addr)->sa_family) {
|
2011-06-14 16:28:09 +00:00
|
|
|
case AF_INET6:
|
|
|
|
afs = "ipv6";
|
|
|
|
snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI6",
|
2011-05-30 14:32:41 +00:00
|
|
|
&((struct sockaddr_in6 *)&connection->peer_addr)->sin6_addr);
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
2011-06-14 16:28:09 +00:00
|
|
|
case AF_INET:
|
|
|
|
afs = "ipv4";
|
|
|
|
snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4",
|
2011-05-30 14:32:41 +00:00
|
|
|
&((struct sockaddr_in *)&connection->peer_addr)->sin_addr);
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
2011-06-14 16:28:09 +00:00
|
|
|
default:
|
|
|
|
afs = "ssocks";
|
|
|
|
snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4",
|
2011-05-30 14:32:41 +00:00
|
|
|
&((struct sockaddr_in *)&connection->peer_addr)->sin_addr);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-06-14 16:28:09 +00:00
|
|
|
snprintf(envp[3], 20, "DRBD_PEER_AF=%s", afs);
|
2011-03-16 16:39:12 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
int drbd_khelper(struct drbd_device *device, char *cmd)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
|
|
|
char *envp[] = { "HOME=/",
|
|
|
|
"TERM=linux",
|
|
|
|
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
|
2011-03-16 16:39:12 +00:00
|
|
|
(char[20]) { }, /* address family */
|
|
|
|
(char[60]) { }, /* address */
|
2009-09-25 23:07:19 +00:00
|
|
|
NULL };
|
2011-03-16 16:39:12 +00:00
|
|
|
char mb[12];
|
2009-09-25 23:07:19 +00:00
|
|
|
char *argv[] = {usermode_helper, cmd, mb, NULL };
|
2011-05-31 12:33:49 +00:00
|
|
|
struct drbd_connection *connection = first_peer_device(device)->connection;
|
2011-03-16 16:39:12 +00:00
|
|
|
struct sib_info sib;
|
2009-09-25 23:07:19 +00:00
|
|
|
int ret;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
if (current == connection->worker.task)
|
|
|
|
set_bit(CALLBACK_PENDING, &connection->flags);
|
2012-06-14 13:14:06 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
snprintf(mb, 12, "minor-%d", device_to_minor(device));
|
2011-05-30 14:32:41 +00:00
|
|
|
setup_khelper_env(connection, envp);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2010-07-19 15:41:04 +00:00
|
|
|
/* The helper may take some time.
|
|
|
|
* write out any unsynced meta data changes now */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_sync(device);
|
2010-07-19 15:41:04 +00:00
|
|
|
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "helper command: %s %s %s\n", usermode_helper, cmd, mb);
|
2011-03-07 11:49:34 +00:00
|
|
|
sib.sib_reason = SIB_HELPER_PRE;
|
|
|
|
sib.helper_name = cmd;
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_bcast_event(device, &sib);
|
2012-03-23 22:02:46 +00:00
|
|
|
ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (ret)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "helper command: %s %s %s exit code %u (0x%x)\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
usermode_helper, cmd, mb,
|
|
|
|
(ret >> 8) & 0xff, ret);
|
|
|
|
else
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "helper command: %s %s %s exit code %u (0x%x)\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
usermode_helper, cmd, mb,
|
|
|
|
(ret >> 8) & 0xff, ret);
|
2011-03-07 11:49:34 +00:00
|
|
|
sib.sib_reason = SIB_HELPER_POST;
|
|
|
|
sib.helper_exit_code = ret;
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_bcast_event(device, &sib);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
if (current == connection->worker.task)
|
|
|
|
clear_bit(CALLBACK_PENDING, &connection->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (ret < 0) /* Ignore any ERRNOs we got. */
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static int conn_khelper(struct drbd_connection *connection, char *cmd)
|
2011-03-16 16:39:12 +00:00
|
|
|
{
|
|
|
|
char *envp[] = { "HOME=/",
|
|
|
|
"TERM=linux",
|
|
|
|
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
|
|
|
|
(char[20]) { }, /* address family */
|
|
|
|
(char[60]) { }, /* address */
|
|
|
|
NULL };
|
2011-06-08 20:17:38 +00:00
|
|
|
char *resource_name = connection->resource->name;
|
|
|
|
char *argv[] = {usermode_helper, cmd, resource_name, NULL };
|
2011-03-16 16:39:12 +00:00
|
|
|
int ret;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
setup_khelper_env(connection, envp);
|
|
|
|
conn_md_sync(connection);
|
2011-03-16 16:39:12 +00:00
|
|
|
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_info(connection, "helper command: %s %s %s\n", usermode_helper, cmd, resource_name);
|
2011-03-16 16:39:12 +00:00
|
|
|
/* TODO: conn_bcast_event() ?? */
|
|
|
|
|
2012-11-09 13:18:43 +00:00
|
|
|
ret = call_usermodehelper(usermode_helper, argv, envp, UMH_WAIT_PROC);
|
2011-03-16 16:39:12 +00:00
|
|
|
if (ret)
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_warn(connection, "helper command: %s %s %s exit code %u (0x%x)\n",
|
2011-06-08 20:17:38 +00:00
|
|
|
usermode_helper, cmd, resource_name,
|
2011-03-16 16:39:12 +00:00
|
|
|
(ret >> 8) & 0xff, ret);
|
|
|
|
else
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_info(connection, "helper command: %s %s %s exit code %u (0x%x)\n",
|
2011-06-08 20:17:38 +00:00
|
|
|
usermode_helper, cmd, resource_name,
|
2011-03-16 16:39:12 +00:00
|
|
|
(ret >> 8) & 0xff, ret);
|
|
|
|
/* TODO: conn_bcast_event() ?? */
|
2012-06-14 13:14:06 +00:00
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
if (ret < 0) /* Ignore any ERRNOs we got. */
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static enum drbd_fencing_p highest_fencing_policy(struct drbd_connection *connection)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-24 10:03:07 +00:00
|
|
|
enum drbd_fencing_p fp = FP_NOT_AVAIL;
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-24 10:03:07 +00:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_lock();
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (get_ldev_if_state(device, D_CONSISTENT)) {
|
2011-06-21 15:23:59 +00:00
|
|
|
struct disk_conf *disk_conf =
|
|
|
|
rcu_dereference(peer_device->device->ldev->disk_conf);
|
|
|
|
fp = max_t(enum drbd_fencing_p, fp, disk_conf->fencing);
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-03-24 10:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_unlock();
|
2011-03-24 10:03:07 +00:00
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
bool conn_try_outdate_peer(struct drbd_connection *connection)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2013-06-25 14:50:06 +00:00
|
|
|
unsigned int connect_cnt;
|
2011-03-24 10:03:07 +00:00
|
|
|
union drbd_state mask = { };
|
|
|
|
union drbd_state val = { };
|
|
|
|
enum drbd_fencing_p fp;
|
2009-09-25 23:07:19 +00:00
|
|
|
char *ex_to_string;
|
|
|
|
int r;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
if (connection->cstate >= C_WF_REPORT_PARAMS) {
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_err(connection, "Expected cstate < C_WF_REPORT_PARAMS\n");
|
2011-03-24 10:03:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 14:32:41 +00:00
|
|
|
connect_cnt = connection->connect_cnt;
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2013-06-25 14:50:06 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
fp = highest_fencing_policy(connection);
|
2011-03-24 10:03:07 +00:00
|
|
|
switch (fp) {
|
|
|
|
case FP_NOT_AVAIL:
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_warn(connection, "Not fencing peer, I'm not even Consistent myself.\n");
|
2010-09-08 21:20:21 +00:00
|
|
|
goto out;
|
2011-03-24 10:03:07 +00:00
|
|
|
case FP_DONT_CARE:
|
|
|
|
return true;
|
|
|
|
default: ;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
r = conn_khelper(connection, "fence-peer");
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
switch ((r>>8) & 0xff) {
|
|
|
|
case 3: /* peer is inconsistent */
|
|
|
|
ex_to_string = "peer is inconsistent or worse";
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.pdsk = D_MASK;
|
|
|
|
val.pdsk = D_INCONSISTENT;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
case 4: /* peer got outdated, or was already outdated */
|
|
|
|
ex_to_string = "peer was fenced";
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.pdsk = D_MASK;
|
|
|
|
val.pdsk = D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
case 5: /* peer was down */
|
2011-05-30 14:32:41 +00:00
|
|
|
if (conn_highest_disk(connection) == D_UP_TO_DATE) {
|
2009-09-25 23:07:19 +00:00
|
|
|
/* we will(have) create(d) a new UUID anyways... */
|
|
|
|
ex_to_string = "peer is unreachable, assumed to be dead";
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.pdsk = D_MASK;
|
|
|
|
val.pdsk = D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
} else {
|
|
|
|
ex_to_string = "peer unreachable, doing nothing since disk != UpToDate";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: /* Peer is primary, voluntarily outdate myself.
|
|
|
|
* This is useful when an unconnected R_SECONDARY is asked to
|
|
|
|
* become R_PRIMARY, but finds the other peer being active. */
|
|
|
|
ex_to_string = "peer is active";
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_warn(connection, "Peer is primary, outdating myself.\n");
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.disk = D_MASK;
|
|
|
|
val.disk = D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (fp != FP_STONITH)
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_err(connection, "fence-peer() = 7 && fencing != Stonith !!!\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
ex_to_string = "peer was stonithed";
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.pdsk = D_MASK;
|
|
|
|
val.pdsk = D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* The script is broken ... */
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_err(connection, "fence-peer helper broken, returned %d\n", (r>>8)&0xff);
|
2011-03-24 10:03:07 +00:00
|
|
|
return false; /* Eventually leave IO frozen */
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_info(connection, "fence-peer helper returned %d (%s)\n",
|
2011-03-24 10:03:07 +00:00
|
|
|
(r>>8) & 0xff, ex_to_string);
|
2010-09-08 21:20:21 +00:00
|
|
|
|
2011-03-24 10:03:07 +00:00
|
|
|
out:
|
2010-09-08 21:20:21 +00:00
|
|
|
|
2011-03-24 10:03:07 +00:00
|
|
|
/* Not using
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_request_state(connection, mask, val, CS_VERBOSE);
|
2011-03-24 10:03:07 +00:00
|
|
|
here, because we might were able to re-establish the connection in the
|
|
|
|
meantime. */
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 14:32:41 +00:00
|
|
|
if (connection->cstate < C_WF_REPORT_PARAMS && !test_bit(STATE_SENT, &connection->flags)) {
|
|
|
|
if (connection->connect_cnt != connect_cnt)
|
2013-06-25 14:50:06 +00:00
|
|
|
/* In case the connection was established and droped
|
|
|
|
while the fence-peer handler was running, ignore it */
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_info(connection, "Ignoring fence-peer exit code\n");
|
2013-06-25 14:50:06 +00:00
|
|
|
else
|
2011-05-30 14:32:41 +00:00
|
|
|
_conn_request_state(connection, mask, val, CS_VERBOSE);
|
2013-06-25 14:50:06 +00:00
|
|
|
}
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2011-03-24 10:03:07 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
return conn_highest_pdsk(connection) <= D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 11:56:33 +00:00
|
|
|
static int _try_outdate_peer_async(void *data)
|
|
|
|
{
|
2011-05-30 14:32:41 +00:00
|
|
|
struct drbd_connection *connection = (struct drbd_connection *)data;
|
2010-06-11 11:56:33 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_try_outdate_peer(connection);
|
2010-06-11 11:56:33 +00:00
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
kref_put(&connection->kref, drbd_destroy_connection);
|
2010-06-11 11:56:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
void conn_try_outdate_peer_async(struct drbd_connection *connection)
|
2010-06-11 11:56:33 +00:00
|
|
|
{
|
|
|
|
struct task_struct *opa;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
kref_get(&connection->kref);
|
|
|
|
opa = kthread_run(_try_outdate_peer_async, connection, "drbd_async_h");
|
2011-04-22 13:23:32 +00:00
|
|
|
if (IS_ERR(opa)) {
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_err(connection, "out of mem, failed to invoke fence-peer helper\n");
|
2011-06-07 20:54:17 +00:00
|
|
|
kref_put(&connection->kref, drbd_destroy_connection);
|
2011-04-22 13:23:32 +00:00
|
|
|
}
|
2010-06-11 11:56:33 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2010-12-07 23:39:32 +00:00
|
|
|
enum drbd_state_rv
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_set_role(struct drbd_device *device, enum drbd_role new_role, int force)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
|
|
|
const int max_tries = 4;
|
2010-12-07 23:39:32 +00:00
|
|
|
enum drbd_state_rv rv = SS_UNKNOWN_ERROR;
|
2011-04-19 15:10:19 +00:00
|
|
|
struct net_conf *nc;
|
2009-09-25 23:07:19 +00:00
|
|
|
int try = 0;
|
|
|
|
int forced = 0;
|
|
|
|
union drbd_state mask, val;
|
|
|
|
|
2011-07-06 13:03:31 +00:00
|
|
|
if (new_role == R_PRIMARY) {
|
|
|
|
struct drbd_connection *connection;
|
|
|
|
|
|
|
|
/* Detect dead peers as soon as possible. */
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
for_each_connection(connection, device->resource)
|
|
|
|
request_ping(connection);
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
mutex_lock(device->state_mutex);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
mask.i = 0; mask.role = R_MASK;
|
|
|
|
val.i = 0; val.role = new_role;
|
|
|
|
|
|
|
|
while (try++ < max_tries) {
|
2011-07-03 11:26:43 +00:00
|
|
|
rv = _drbd_request_state(device, mask, val, CS_WAIT_COMPLETE);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* in case we first succeeded to outdate,
|
|
|
|
* but now suddenly could establish a connection */
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_CW_FAILED_BY_PEER && mask.pdsk != 0) {
|
2009-09-25 23:07:19 +00:00
|
|
|
val.pdsk = 0;
|
|
|
|
mask.pdsk = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_NO_UP_TO_DATE_DISK && force &&
|
2011-07-03 11:26:43 +00:00
|
|
|
(device->state.disk < D_UP_TO_DATE &&
|
|
|
|
device->state.disk >= D_INCONSISTENT)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
mask.disk = D_MASK;
|
|
|
|
val.disk = D_UP_TO_DATE;
|
|
|
|
forced = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_NO_UP_TO_DATE_DISK &&
|
2011-07-03 11:26:43 +00:00
|
|
|
device->state.disk == D_CONSISTENT && mask.pdsk == 0) {
|
2011-06-27 14:23:33 +00:00
|
|
|
D_ASSERT(device, device->state.pdsk == D_UNKNOWN);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-31 12:33:49 +00:00
|
|
|
if (conn_try_outdate_peer(first_peer_device(device)->connection)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
val.disk = D_UP_TO_DATE;
|
|
|
|
mask.disk = D_MASK;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_NOTHING_TO_DO)
|
2011-03-07 11:49:34 +00:00
|
|
|
goto out;
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) {
|
2011-05-31 12:33:49 +00:00
|
|
|
if (!conn_try_outdate_peer(first_peer_device(device)->connection) && force) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "Forced into split brain situation!\n");
|
2011-03-24 10:03:07 +00:00
|
|
|
mask.pdsk = D_MASK;
|
|
|
|
val.pdsk = D_OUTDATED;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-24 10:03:07 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv == SS_TWO_PRIMARIES) {
|
2009-09-25 23:07:19 +00:00
|
|
|
/* Maybe the peer is detected as dead very soon...
|
|
|
|
retry at most once more in this case. */
|
2011-04-19 15:10:19 +00:00
|
|
|
int timeo;
|
|
|
|
rcu_read_lock();
|
2011-05-31 12:33:49 +00:00
|
|
|
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
|
2011-04-19 15:10:19 +00:00
|
|
|
timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1;
|
|
|
|
rcu_read_unlock();
|
|
|
|
schedule_timeout_interruptible(timeo);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (try < max_tries)
|
|
|
|
try = max_tries - 1;
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv < SS_SUCCESS) {
|
2011-07-03 11:26:43 +00:00
|
|
|
rv = _drbd_request_state(device, mask, val,
|
2009-09-25 23:07:19 +00:00
|
|
|
CS_VERBOSE + CS_WAIT_COMPLETE);
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv < SS_SUCCESS)
|
2011-03-07 11:49:34 +00:00
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-07 23:39:32 +00:00
|
|
|
if (rv < SS_SUCCESS)
|
2011-03-07 11:49:34 +00:00
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (forced)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "Forced to consider local data as UpToDate!\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* Wait until nothing is on the fly :) */
|
2011-07-03 11:26:43 +00:00
|
|
|
wait_event(device->misc_wait, atomic_read(&device->ap_pending_cnt) == 0);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-11-28 14:04:49 +00:00
|
|
|
/* FIXME also wait for all pending P_BARRIER_ACK? */
|
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
if (new_role == R_SECONDARY) {
|
2011-07-03 11:26:43 +00:00
|
|
|
set_disk_ro(device->vdisk, true);
|
|
|
|
if (get_ldev(device)) {
|
|
|
|
device->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
|
|
|
|
put_ldev(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_lock(&device->resource->conf_update);
|
2011-05-31 12:33:49 +00:00
|
|
|
nc = first_peer_device(device)->connection->net_conf;
|
2011-04-19 15:10:19 +00:00
|
|
|
if (nc)
|
2011-05-06 18:00:02 +00:00
|
|
|
nc->discard_my_data = 0; /* without copy; single bit op is atomic */
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&device->resource->conf_update);
|
2011-04-20 15:47:29 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
set_disk_ro(device->vdisk, false);
|
|
|
|
if (get_ldev(device)) {
|
|
|
|
if (((device->state.conn < C_CONNECTED ||
|
|
|
|
device->state.pdsk <= D_FAILED)
|
|
|
|
&& device->ldev->md.uuid[UI_BITMAP] == 0) || forced)
|
|
|
|
drbd_uuid_new_current(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.uuid[UI_CURRENT] |= (u64)1;
|
|
|
|
put_ldev(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 07:59:11 +00:00
|
|
|
/* writeout of activity log covered areas of the bitmap
|
|
|
|
* to stable storage done in after state change already */
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn >= C_WF_REPORT_PARAMS) {
|
2009-09-25 23:07:19 +00:00
|
|
|
/* if this was forced, we should consider sync */
|
|
|
|
if (forced)
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_send_uuids(device);
|
|
|
|
drbd_send_current_state(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_sync(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
2011-07-03 11:26:43 +00:00
|
|
|
mutex_unlock(device->state_mutex);
|
2010-12-07 23:39:32 +00:00
|
|
|
return rv;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
static const char *from_attrs_err_to_txt(int err)
|
2010-09-01 12:39:30 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
return err == -ENOMSG ? "required attribute missing" :
|
|
|
|
err == -EOPNOTSUPP ? "unknown mandatory attribute" :
|
2011-03-23 13:31:09 +00:00
|
|
|
err == -EEXIST ? "can not change invariant setting" :
|
2011-03-07 11:49:34 +00:00
|
|
|
"invalid attribute value";
|
2010-09-01 12:39:30 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
struct set_role_parms parms;
|
|
|
|
int err;
|
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
memset(&parms, 0, sizeof(parms));
|
|
|
|
if (info->attrs[DRBD_NLA_SET_ROLE_PARMS]) {
|
2011-03-23 13:31:09 +00:00
|
|
|
err = set_role_parms_from_attrs(&parms, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
if (info->genlhdr->cmd == DRBD_ADM_PRIMARY)
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_set_role(adm_ctx.device, R_PRIMARY, parms.assume_uptodate);
|
2011-03-07 11:49:34 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_set_role(adm_ctx.device, R_SECONDARY, 0);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-19 17:16:43 +00:00
|
|
|
/* Initializes the md.*_offset members, so we are able to find
|
|
|
|
* the on disk meta data.
|
|
|
|
*
|
|
|
|
* We currently have two possible layouts:
|
|
|
|
* external:
|
|
|
|
* |----------- md_size_sect ------------------|
|
|
|
|
* [ 4k superblock ][ activity log ][ Bitmap ]
|
|
|
|
* | al_offset == 8 |
|
|
|
|
* | bm_offset = al_offset + X |
|
|
|
|
* ==> bitmap sectors = md_size_sect - bm_offset
|
|
|
|
*
|
|
|
|
* internal:
|
|
|
|
* |----------- md_size_sect ------------------|
|
|
|
|
* [data.....][ Bitmap ][ activity log ][ 4k superblock ]
|
|
|
|
* | al_offset < 0 |
|
|
|
|
* | bm_offset = al_offset - Y |
|
|
|
|
* ==> bitmap sectors = Y = al_offset - bm_offset
|
|
|
|
*
|
|
|
|
* Activity log size used to be fixed 32kB,
|
|
|
|
* but is about to become configurable.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
static void drbd_md_set_sector_offsets(struct drbd_device *device,
|
2009-09-25 23:07:19 +00:00
|
|
|
struct drbd_backing_dev *bdev)
|
|
|
|
{
|
|
|
|
sector_t md_size_sect = 0;
|
2013-03-19 17:16:47 +00:00
|
|
|
unsigned int al_size_sect = bdev->md.al_size_4k * 8;
|
2011-05-03 13:00:55 +00:00
|
|
|
|
2013-03-19 17:16:44 +00:00
|
|
|
bdev->md.md_offset = drbd_md_ss(bdev);
|
|
|
|
|
2013-03-19 17:16:45 +00:00
|
|
|
switch (bdev->md.meta_dev_idx) {
|
2009-09-25 23:07:19 +00:00
|
|
|
default:
|
|
|
|
/* v07 style fixed size indexed meta data */
|
2013-03-19 17:16:43 +00:00
|
|
|
bdev->md.md_size_sect = MD_128MB_SECT;
|
|
|
|
bdev->md.al_offset = MD_4kB_SECT;
|
|
|
|
bdev->md.bm_offset = MD_4kB_SECT + al_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
case DRBD_MD_INDEX_FLEX_EXT:
|
|
|
|
/* just occupy the full device; unit: sectors */
|
|
|
|
bdev->md.md_size_sect = drbd_get_capacity(bdev->md_bdev);
|
2013-03-19 17:16:43 +00:00
|
|
|
bdev->md.al_offset = MD_4kB_SECT;
|
|
|
|
bdev->md.bm_offset = MD_4kB_SECT + al_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
case DRBD_MD_INDEX_INTERNAL:
|
|
|
|
case DRBD_MD_INDEX_FLEX_INT:
|
|
|
|
/* al size is still fixed */
|
2013-03-19 17:16:43 +00:00
|
|
|
bdev->md.al_offset = -al_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
/* we need (slightly less than) ~ this much bitmap sectors: */
|
|
|
|
md_size_sect = drbd_get_capacity(bdev->backing_bdev);
|
|
|
|
md_size_sect = ALIGN(md_size_sect, BM_SECT_PER_EXT);
|
|
|
|
md_size_sect = BM_SECT_TO_EXT(md_size_sect);
|
|
|
|
md_size_sect = ALIGN(md_size_sect, 8);
|
|
|
|
|
|
|
|
/* plus the "drbd meta data super block",
|
|
|
|
* and the activity log; */
|
2013-03-19 17:16:43 +00:00
|
|
|
md_size_sect += MD_4kB_SECT + al_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
bdev->md.md_size_sect = md_size_sect;
|
|
|
|
/* bitmap offset is adjusted by 'super' block size */
|
2013-03-19 17:16:43 +00:00
|
|
|
bdev->md.bm_offset = -md_size_sect + MD_4kB_SECT;
|
2009-09-25 23:07:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-14 14:13:04 +00:00
|
|
|
/* input size is expected to be in KB */
|
2009-09-25 23:07:19 +00:00
|
|
|
char *ppsize(char *buf, unsigned long long size)
|
|
|
|
{
|
2010-12-14 14:13:04 +00:00
|
|
|
/* Needs 9 bytes at max including trailing NUL:
|
|
|
|
* -1ULL ==> "16384 EB" */
|
2009-09-25 23:07:19 +00:00
|
|
|
static char units[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
|
|
|
|
int base = 0;
|
2010-12-14 14:13:04 +00:00
|
|
|
while (size >= 10000 && base < sizeof(units)-1) {
|
2009-09-25 23:07:19 +00:00
|
|
|
/* shift + round */
|
|
|
|
size = (size >> 10) + !!(size & (1<<9));
|
|
|
|
base++;
|
|
|
|
}
|
2010-12-14 14:13:04 +00:00
|
|
|
sprintf(buf, "%u %cB", (unsigned)size, units[base]);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there is still a theoretical deadlock when called from receiver
|
|
|
|
* on an D_INCONSISTENT R_PRIMARY:
|
|
|
|
* remote READ does inc_ap_bio, receiver would need to receive answer
|
|
|
|
* packet from remote to dec_ap_bio again.
|
|
|
|
* receiver receive_sizes(), comes here,
|
|
|
|
* waits for ap_bio_cnt == 0. -> deadlock.
|
|
|
|
* but this cannot happen, actually, because:
|
|
|
|
* R_PRIMARY D_INCONSISTENT, and peer's disk is unreachable
|
|
|
|
* (not connected, or bad/no disk on peer):
|
|
|
|
* see drbd_fail_request_early, ap_bio_cnt is zero.
|
|
|
|
* R_PRIMARY D_INCONSISTENT, and C_SYNC_TARGET:
|
|
|
|
* peer may not initiate a resize.
|
|
|
|
*/
|
2011-03-07 11:49:34 +00:00
|
|
|
/* Note these are not to be confused with
|
|
|
|
* drbd_adm_suspend_io/drbd_adm_resume_io,
|
|
|
|
* which are (sub) state changes triggered by admin (drbdsetup),
|
|
|
|
* and can be long lived.
|
2011-07-03 11:26:43 +00:00
|
|
|
* This changes an device->flag, is triggered by drbd internals,
|
2011-03-07 11:49:34 +00:00
|
|
|
* and should be short-lived. */
|
2011-07-03 11:26:43 +00:00
|
|
|
void drbd_suspend_io(struct drbd_device *device)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(SUSPEND_IO, &device->flags);
|
|
|
|
if (drbd_suspended(device))
|
2010-05-31 08:14:17 +00:00
|
|
|
return;
|
2011-07-03 11:26:43 +00:00
|
|
|
wait_event(device->misc_wait, !atomic_read(&device->ap_bio_cnt));
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
void drbd_resume_io(struct drbd_device *device)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(SUSPEND_IO, &device->flags);
|
|
|
|
wake_up(&device->misc_wait);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_determine_dev_size() - Sets the right device size obeying all constraints
|
2011-07-03 11:26:43 +00:00
|
|
|
* @device: DRBD device.
|
2009-09-25 23:07:19 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, negative return values indicate errors.
|
|
|
|
* You should call drbd_md_sync() after calling this function.
|
|
|
|
*/
|
2013-06-25 14:50:08 +00:00
|
|
|
enum determine_dev_size
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_determine_dev_size(struct drbd_device *device, enum dds_flags flags, struct resize_parms *rs) __must_hold(local)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
|
|
|
sector_t prev_first_sect, prev_size; /* previous meta location */
|
2013-03-19 17:16:46 +00:00
|
|
|
sector_t la_size_sect, u_size;
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_md *md = &device->ldev->md;
|
2013-06-25 14:50:08 +00:00
|
|
|
u32 prev_al_stripe_size_4k;
|
|
|
|
u32 prev_al_stripes;
|
2009-09-25 23:07:19 +00:00
|
|
|
sector_t size;
|
|
|
|
char ppb[10];
|
2013-06-25 14:50:08 +00:00
|
|
|
void *buffer;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
int md_moved, la_size_changed;
|
2013-06-25 14:50:07 +00:00
|
|
|
enum determine_dev_size rv = DS_UNCHANGED;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* race:
|
|
|
|
* application request passes inc_ap_bio,
|
|
|
|
* but then cannot get an AL-reference.
|
|
|
|
* this function later may wait on ap_bio_cnt == 0. -> deadlock.
|
|
|
|
*
|
|
|
|
* to avoid that:
|
|
|
|
* Suspend IO right here.
|
|
|
|
* still lock the act_log to not trigger ASSERTs there.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
buffer = drbd_md_get_buffer(device); /* Lock meta-data IO */
|
2013-06-25 14:50:08 +00:00
|
|
|
if (!buffer) {
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_resume_io(device);
|
2013-06-25 14:50:08 +00:00
|
|
|
return DS_ERROR;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* no wait necessary anymore, actually we could assert that */
|
2011-07-03 11:26:43 +00:00
|
|
|
wait_event(device->al_wait, lc_try_lock(device->act_log));
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
prev_first_sect = drbd_md_first_sector(device->ldev);
|
|
|
|
prev_size = device->ldev->md.md_size_sect;
|
|
|
|
la_size_sect = device->ldev->md.la_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2013-06-25 14:50:08 +00:00
|
|
|
if (rs) {
|
|
|
|
/* rs is non NULL if we should change the AL layout only */
|
|
|
|
|
|
|
|
prev_al_stripes = md->al_stripes;
|
|
|
|
prev_al_stripe_size_4k = md->al_stripe_size_4k;
|
|
|
|
|
|
|
|
md->al_stripes = rs->al_stripes;
|
|
|
|
md->al_stripe_size_4k = rs->al_stripe_size / 4;
|
|
|
|
md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_set_sector_offsets(device, device->ldev);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_lock();
|
2011-07-03 11:26:43 +00:00
|
|
|
u_size = rcu_dereference(device->ldev->disk_conf)->disk_size;
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_unlock();
|
2011-07-03 11:26:43 +00:00
|
|
|
size = drbd_new_dev_size(device, device->ldev, u_size, flags & DDSF_FORCED);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2013-06-25 14:50:08 +00:00
|
|
|
if (size < la_size_sect) {
|
|
|
|
if (rs && u_size == 0) {
|
|
|
|
/* Remove "rs &&" later. This check should always be active, but
|
|
|
|
right now the receiver expects the permissive behavior */
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "Implicit shrink not allowed. "
|
2013-06-25 14:50:08 +00:00
|
|
|
"Use --size=%llus for explicit shrink.\n",
|
|
|
|
(unsigned long long)size);
|
|
|
|
rv = DS_ERROR_SHRINK;
|
|
|
|
}
|
|
|
|
if (u_size > size)
|
|
|
|
rv = DS_ERROR_SPACE_MD;
|
|
|
|
if (rv != DS_UNCHANGED)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_get_capacity(device->this_bdev) != size ||
|
|
|
|
drbd_bm_capacity(device) != size) {
|
2009-09-25 23:07:19 +00:00
|
|
|
int err;
|
2011-07-03 11:26:43 +00:00
|
|
|
err = drbd_bm_resize(device, size, !(flags & DDSF_NO_RESYNC));
|
2009-09-25 23:07:19 +00:00
|
|
|
if (unlikely(err)) {
|
|
|
|
/* currently there is only one error: ENOMEM! */
|
2011-07-03 11:26:43 +00:00
|
|
|
size = drbd_bm_capacity(device)>>1;
|
2009-09-25 23:07:19 +00:00
|
|
|
if (size == 0) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "OUT OF MEMORY! "
|
2009-09-25 23:07:19 +00:00
|
|
|
"Could not allocate bitmap!\n");
|
|
|
|
} else {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "BM resizing failed. "
|
2009-09-25 23:07:19 +00:00
|
|
|
"Leaving size unchanged at size = %lu KB\n",
|
|
|
|
(unsigned long)size);
|
|
|
|
}
|
2013-06-25 14:50:07 +00:00
|
|
|
rv = DS_ERROR;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
/* racy, see comments above. */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_set_my_capacity(device, size);
|
|
|
|
device->ldev->md.la_size_sect = size;
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "size = %s (%llu KB)\n", ppsize(ppb, size>>1),
|
2009-09-25 23:07:19 +00:00
|
|
|
(unsigned long long)size>>1);
|
|
|
|
}
|
2013-06-25 14:50:08 +00:00
|
|
|
if (rv <= DS_ERROR)
|
|
|
|
goto err_out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
la_size_changed = (la_size_sect != device->ldev->md.la_size_sect);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
md_moved = prev_first_sect != drbd_md_first_sector(device->ldev)
|
|
|
|
|| prev_size != device->ldev->md.md_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2013-06-25 14:50:08 +00:00
|
|
|
if (la_size_changed || md_moved || rs) {
|
|
|
|
u32 prev_flags;
|
2010-12-12 16:45:41 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_al_shrink(device); /* All extents inactive. */
|
2013-06-25 14:50:08 +00:00
|
|
|
|
|
|
|
prev_flags = md->flags;
|
|
|
|
md->flags &= ~MDF_PRIMARY_IND;
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_write(device, buffer);
|
2013-06-25 14:50:08 +00:00
|
|
|
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Writing the whole bitmap, %s\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
la_size_changed && md_moved ? "size changed and md moved" :
|
|
|
|
la_size_changed ? "size changed" : "md moved");
|
2011-01-21 09:56:44 +00:00
|
|
|
/* next line implicitly does drbd_suspend_io()+drbd_resume_io() */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_bitmap_io(device, md_moved ? &drbd_bm_write_all : &drbd_bm_write,
|
2013-06-25 14:50:08 +00:00
|
|
|
"size changed", BM_LOCKED_MASK);
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_initialize_al(device, buffer);
|
2013-06-25 14:50:08 +00:00
|
|
|
|
|
|
|
md->flags = prev_flags;
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_write(device, buffer);
|
2013-06-25 14:50:08 +00:00
|
|
|
|
|
|
|
if (rs)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Changed AL layout to al-stripes = %d, al-stripe-size-kB = %d\n",
|
|
|
|
md->al_stripes, md->al_stripe_size_4k * 4);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 17:16:46 +00:00
|
|
|
if (size > la_size_sect)
|
2013-10-23 08:59:17 +00:00
|
|
|
rv = la_size_sect ? DS_GREW : DS_GREW_FROM_ZERO;
|
2013-03-19 17:16:46 +00:00
|
|
|
if (size < la_size_sect)
|
2013-06-25 14:50:07 +00:00
|
|
|
rv = DS_SHRUNK;
|
2013-06-25 14:50:08 +00:00
|
|
|
|
|
|
|
if (0) {
|
|
|
|
err_out:
|
|
|
|
if (rs) {
|
|
|
|
md->al_stripes = prev_al_stripes;
|
|
|
|
md->al_stripe_size_4k = prev_al_stripe_size_4k;
|
|
|
|
md->al_size_4k = (u64)prev_al_stripes * prev_al_stripe_size_4k;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_set_sector_offsets(device, device->ldev);
|
2013-06-25 14:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
lc_unlock(device->act_log);
|
|
|
|
wake_up(&device->al_wait);
|
|
|
|
drbd_md_put_buffer(device);
|
|
|
|
drbd_resume_io(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
sector_t
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_new_dev_size(struct drbd_device *device, struct drbd_backing_dev *bdev,
|
2011-05-03 11:27:43 +00:00
|
|
|
sector_t u_size, int assume_peer_has_space)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
sector_t p_size = device->p_size; /* partner's disk size. */
|
2013-03-19 17:16:46 +00:00
|
|
|
sector_t la_size_sect = bdev->md.la_size_sect; /* last agreed size. */
|
2009-09-25 23:07:19 +00:00
|
|
|
sector_t m_size; /* my size */
|
|
|
|
sector_t size = 0;
|
|
|
|
|
|
|
|
m_size = drbd_get_max_capacity(bdev);
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn < C_CONNECTED && assume_peer_has_space) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "Resize while not connected was forced by the user!\n");
|
2009-12-22 12:35:52 +00:00
|
|
|
p_size = m_size;
|
|
|
|
}
|
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
if (p_size && m_size) {
|
|
|
|
size = min_t(sector_t, p_size, m_size);
|
|
|
|
} else {
|
2013-03-19 17:16:46 +00:00
|
|
|
if (la_size_sect) {
|
|
|
|
size = la_size_sect;
|
2009-09-25 23:07:19 +00:00
|
|
|
if (m_size && m_size < size)
|
|
|
|
size = m_size;
|
|
|
|
if (p_size && p_size < size)
|
|
|
|
size = p_size;
|
|
|
|
} else {
|
|
|
|
if (m_size)
|
|
|
|
size = m_size;
|
|
|
|
if (p_size)
|
|
|
|
size = p_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 0)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Both nodes diskless!\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (u_size) {
|
|
|
|
if (u_size > size)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Requested disk size is too big (%lu > %lu)\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
(unsigned long)u_size>>1, (unsigned long)size>>1);
|
|
|
|
else
|
|
|
|
size = u_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_check_al_size() - Ensures that the AL is of the right size
|
2011-07-03 11:26:43 +00:00
|
|
|
* @device: DRBD device.
|
2009-09-25 23:07:19 +00:00
|
|
|
*
|
|
|
|
* Returns -EBUSY if current al lru is still used, -ENOMEM when allocation
|
|
|
|
* failed, and 0 on success. You should call drbd_md_sync() after you called
|
|
|
|
* this function.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
|
|
|
struct lru_cache *n, *t;
|
|
|
|
struct lc_element *e;
|
|
|
|
unsigned int in_use;
|
|
|
|
int i;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->act_log &&
|
|
|
|
device->act_log->nr_elements == dc->al_extents)
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
in_use = 0;
|
2011-07-03 11:26:43 +00:00
|
|
|
t = device->act_log;
|
2011-02-21 12:21:03 +00:00
|
|
|
n = lc_create("act_log", drbd_al_ext_cache, AL_UPDATES_PER_TRANSACTION,
|
2011-03-23 13:31:09 +00:00
|
|
|
dc->al_extents, sizeof(struct lc_element), 0);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (n == NULL) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Cannot allocate act_log lru!\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
spin_lock_irq(&device->al_lock);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (t) {
|
|
|
|
for (i = 0; i < t->nr_elements; i++) {
|
|
|
|
e = lc_element_by_index(t, i);
|
|
|
|
if (e->refcnt)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "refcnt(%d)==%d\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
e->lc_number, e->refcnt);
|
|
|
|
in_use += e->refcnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!in_use)
|
2011-07-03 11:26:43 +00:00
|
|
|
device->act_log = n;
|
|
|
|
spin_unlock_irq(&device->al_lock);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (in_use) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Activity log still in use!\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
lc_destroy(n);
|
|
|
|
return -EBUSY;
|
|
|
|
} else {
|
|
|
|
if (t)
|
|
|
|
lc_destroy(t);
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_mark_dirty(device); /* we changed device->act_log->nr_elemens */
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
static void drbd_setup_queue_param(struct drbd_device *device, unsigned int max_bio_size)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct request_queue * const q = device->rq_queue;
|
2012-06-25 17:15:58 +00:00
|
|
|
unsigned int max_hw_sectors = max_bio_size >> 9;
|
|
|
|
unsigned int max_segments = 0;
|
2011-05-20 14:39:13 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (get_ldev_if_state(device, D_ATTACHING)) {
|
|
|
|
struct request_queue * const b = device->ldev->backing_bdev->bd_disk->queue;
|
2011-05-20 14:39:13 +00:00
|
|
|
|
|
|
|
max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9);
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_lock();
|
2011-07-03 11:26:43 +00:00
|
|
|
max_segments = rcu_dereference(device->ldev->disk_conf)->max_bio_bvecs;
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_unlock();
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-05-20 14:39:13 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
blk_queue_logical_block_size(q, 512);
|
2010-11-11 14:19:07 +00:00
|
|
|
blk_queue_max_hw_sectors(q, max_hw_sectors);
|
|
|
|
/* This is the workaround for "bio would need to, but cannot, be split" */
|
|
|
|
blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
|
|
|
|
blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (get_ldev_if_state(device, D_ATTACHING)) {
|
|
|
|
struct request_queue * const b = device->ldev->backing_bdev->bd_disk->queue;
|
2011-05-20 14:39:13 +00:00
|
|
|
|
|
|
|
blk_queue_stack_limits(q, b);
|
|
|
|
|
|
|
|
if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
|
2011-05-20 14:39:13 +00:00
|
|
|
q->backing_dev_info.ra_pages,
|
|
|
|
b->backing_dev_info.ra_pages);
|
|
|
|
q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages;
|
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-05-20 14:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
void drbd_reconsider_max_bio_size(struct drbd_device *device)
|
2011-05-20 14:39:13 +00:00
|
|
|
{
|
2012-06-25 17:15:58 +00:00
|
|
|
unsigned int now, new, local, peer;
|
2011-05-20 14:39:13 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
now = queue_max_hw_sectors(device->rq_queue) << 9;
|
|
|
|
local = device->local_max_bio_size; /* Eventually last known value, from volatile memory */
|
|
|
|
peer = device->peer_max_bio_size; /* Eventually last known value, from meta data */
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (get_ldev_if_state(device, D_ATTACHING)) {
|
|
|
|
local = queue_max_hw_sectors(device->ldev->backing_bdev->bd_disk->queue) << 9;
|
|
|
|
device->local_max_bio_size = local;
|
|
|
|
put_ldev(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2012-06-25 17:15:58 +00:00
|
|
|
local = min(local, DRBD_MAX_BIO_SIZE);
|
2011-05-20 14:39:13 +00:00
|
|
|
|
|
|
|
/* We may ignore peer limits if the peer is modern enough.
|
|
|
|
Because new from 8.3.8 onwards the peer can use multiple
|
|
|
|
BIOs for a single peer_request */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn >= C_WF_REPORT_PARAMS) {
|
2011-05-31 12:33:49 +00:00
|
|
|
if (first_peer_device(device)->connection->agreed_pro_version < 94)
|
2011-07-03 11:26:43 +00:00
|
|
|
peer = min(device->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET);
|
2011-06-30 13:43:06 +00:00
|
|
|
/* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */
|
2011-05-31 12:33:49 +00:00
|
|
|
else if (first_peer_device(device)->connection->agreed_pro_version == 94)
|
2011-05-20 14:39:13 +00:00
|
|
|
peer = DRBD_MAX_SIZE_H80_PACKET;
|
2011-05-31 12:33:49 +00:00
|
|
|
else if (first_peer_device(device)->connection->agreed_pro_version < 100)
|
2011-06-30 13:43:06 +00:00
|
|
|
peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */
|
|
|
|
else
|
2011-05-20 14:39:13 +00:00
|
|
|
peer = DRBD_MAX_BIO_SIZE;
|
|
|
|
}
|
|
|
|
|
2012-06-25 17:15:58 +00:00
|
|
|
new = min(local, peer);
|
2011-05-20 14:39:13 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.role == R_PRIMARY && new < now)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "ASSERT FAILED new < now; (%u < %u)\n", new, now);
|
2011-05-20 14:39:13 +00:00
|
|
|
|
|
|
|
if (new != now)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "max BIO size = %u\n", new);
|
2011-05-20 14:39:13 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_setup_queue_param(device, new);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-24 09:09:55 +00:00
|
|
|
/* Starts the worker thread */
|
2011-05-30 14:32:41 +00:00
|
|
|
static void conn_reconfig_start(struct drbd_connection *connection)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-05-30 14:32:41 +00:00
|
|
|
drbd_thread_start(&connection->worker);
|
|
|
|
conn_flush_workqueue(connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-24 09:09:55 +00:00
|
|
|
/* if still unconfigured, stops worker again. */
|
2011-05-30 14:32:41 +00:00
|
|
|
static void conn_reconfig_done(struct drbd_connection *connection)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-05-02 09:47:18 +00:00
|
|
|
bool stop_threads;
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 14:32:41 +00:00
|
|
|
stop_threads = conn_all_vols_unconf(connection) &&
|
|
|
|
connection->cstate == C_STANDALONE;
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2011-05-02 09:47:18 +00:00
|
|
|
if (stop_threads) {
|
|
|
|
/* asender is implicitly stopped by receiver
|
2011-05-04 13:10:30 +00:00
|
|
|
* in conn_disconnect() */
|
2011-05-30 14:32:41 +00:00
|
|
|
drbd_thread_stop(&connection->receiver);
|
|
|
|
drbd_thread_stop(&connection->worker);
|
2011-05-02 09:47:18 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 10:00:50 +00:00
|
|
|
/* Make sure IO is suspended before calling this function(). */
|
2011-07-03 11:26:43 +00:00
|
|
|
static void drbd_suspend_al(struct drbd_device *device)
|
2010-08-31 10:00:50 +00:00
|
|
|
{
|
|
|
|
int s = 0;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!lc_try_lock(device->act_log)) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "Failed to lock al in drbd_suspend_al()\n");
|
2010-08-31 10:00:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_al_shrink(device);
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&device->resource->req_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn < C_CONNECTED)
|
|
|
|
s = !test_and_set_bit(AL_SUSPENDED, &device->flags);
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&device->resource->req_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
lc_unlock(device->act_log);
|
2010-08-31 10:00:50 +00:00
|
|
|
|
|
|
|
if (s)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Suspended AL updates\n");
|
2010-08-31 10:00:50 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 19:09:55 +00:00
|
|
|
|
|
|
|
static bool should_set_defaults(struct genl_info *info)
|
|
|
|
{
|
|
|
|
unsigned flags = ((struct drbd_genlmsghdr*)info->userhdr)->flags;
|
|
|
|
return 0 != (flags & DRBD_GENL_F_SET_DEFAULTS);
|
|
|
|
}
|
|
|
|
|
2013-03-19 17:16:59 +00:00
|
|
|
static unsigned int drbd_al_extents_max(struct drbd_backing_dev *bdev)
|
2011-05-04 08:06:52 +00:00
|
|
|
{
|
2013-03-19 17:16:59 +00:00
|
|
|
/* This is limited by 16 bit "slot" numbers,
|
|
|
|
* and by available on-disk context storage.
|
|
|
|
*
|
|
|
|
* Also (u16)~0 is special (denotes a "free" extent).
|
|
|
|
*
|
|
|
|
* One transaction occupies one 4kB on-disk block,
|
|
|
|
* we have n such blocks in the on disk ring buffer,
|
|
|
|
* the "current" transaction may fail (n-1),
|
|
|
|
* and there is 919 slot numbers context information per transaction.
|
|
|
|
*
|
|
|
|
* 72 transaction blocks amounts to more than 2**16 context slots,
|
|
|
|
* so cap there first.
|
|
|
|
*/
|
|
|
|
const unsigned int max_al_nr = DRBD_AL_EXTENTS_MAX;
|
|
|
|
const unsigned int sufficient_on_disk =
|
|
|
|
(max_al_nr + AL_CONTEXT_PER_TRANSACTION -1)
|
|
|
|
/AL_CONTEXT_PER_TRANSACTION;
|
2011-05-04 08:06:52 +00:00
|
|
|
|
2013-03-19 17:16:59 +00:00
|
|
|
unsigned int al_size_4k = bdev->md.al_size_4k;
|
|
|
|
|
|
|
|
if (al_size_4k > sufficient_on_disk)
|
|
|
|
return max_al_nr;
|
|
|
|
|
|
|
|
return (al_size_4k - 1) * AL_CONTEXT_PER_TRANSACTION;
|
2011-05-04 08:06:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
enum drbd_ret_code retcode;
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-05-03 13:00:55 +00:00
|
|
|
struct disk_conf *new_disk_conf, *old_disk_conf;
|
2011-05-03 14:47:02 +00:00
|
|
|
struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
|
2011-03-23 13:31:09 +00:00
|
|
|
int err, fifo_size;
|
|
|
|
|
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2011-03-23 13:31:09 +00:00
|
|
|
|
|
|
|
/* we also need a disk
|
|
|
|
* to change the options on */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!get_ldev(device)) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_NO_DISK;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
|
2011-04-27 19:14:57 +00:00
|
|
|
if (!new_disk_conf) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_lock(&device->resource->conf_update);
|
2011-07-03 11:26:43 +00:00
|
|
|
old_disk_conf = device->ldev->disk_conf;
|
2011-05-03 13:00:55 +00:00
|
|
|
*new_disk_conf = *old_disk_conf;
|
2011-04-27 19:09:55 +00:00
|
|
|
if (should_set_defaults(info))
|
2011-05-03 12:56:09 +00:00
|
|
|
set_disk_conf_defaults(new_disk_conf);
|
2011-04-27 19:09:55 +00:00
|
|
|
|
2011-04-27 19:14:57 +00:00
|
|
|
err = disk_conf_from_attrs_for_change(new_disk_conf, info);
|
2011-05-24 12:18:31 +00:00
|
|
|
if (err && err != -ENOMSG) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2013-08-01 08:21:47 +00:00
|
|
|
goto fail_unlock;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 19:14:57 +00:00
|
|
|
if (!expect(new_disk_conf->resync_rate >= 1))
|
|
|
|
new_disk_conf->resync_rate = 1;
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2013-03-19 17:16:59 +00:00
|
|
|
if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN)
|
|
|
|
new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (new_disk_conf->al_extents > drbd_al_extents_max(device->ldev))
|
|
|
|
new_disk_conf->al_extents = drbd_al_extents_max(device->ldev);
|
2013-03-19 17:16:59 +00:00
|
|
|
|
|
|
|
if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX)
|
|
|
|
new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX;
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-04-27 19:14:57 +00:00
|
|
|
fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (fifo_size != device->rs_plan_s->size) {
|
2011-05-03 14:47:02 +00:00
|
|
|
new_plan = fifo_alloc(fifo_size);
|
|
|
|
if (!new_plan) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "kmalloc of fifo_buffer failed");
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_NOMEM;
|
2011-05-03 13:00:55 +00:00
|
|
|
goto fail_unlock;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
wait_event(device->al_wait, lc_try_lock(device->act_log));
|
|
|
|
drbd_al_shrink(device);
|
|
|
|
err = drbd_check_al_size(device, new_disk_conf);
|
|
|
|
lc_unlock(device->act_log);
|
|
|
|
wake_up(&device->al_wait);
|
|
|
|
drbd_resume_io(device);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
retcode = ERR_NOMEM;
|
2011-05-03 13:00:55 +00:00
|
|
|
goto fail_unlock;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 12:27:15 +00:00
|
|
|
write_lock_irq(&global_state_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_resync_after_valid(device, new_disk_conf->resync_after);
|
2011-05-03 12:27:15 +00:00
|
|
|
if (retcode == NO_ERROR) {
|
2011-07-03 11:26:43 +00:00
|
|
|
rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf);
|
|
|
|
drbd_resync_after_changed(device);
|
2011-05-03 12:27:15 +00:00
|
|
|
}
|
|
|
|
write_unlock_irq(&global_state_lock);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail_unlock;
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-05-03 14:47:02 +00:00
|
|
|
if (new_plan) {
|
2011-07-03 11:26:43 +00:00
|
|
|
old_plan = device->rs_plan_s;
|
|
|
|
rcu_assign_pointer(device->rs_plan_s, new_plan);
|
2011-05-03 14:19:31 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&device->resource->conf_update);
|
2012-03-30 12:12:15 +00:00
|
|
|
|
2012-02-20 20:53:28 +00:00
|
|
|
if (new_disk_conf->al_updates)
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.flags &= ~MDF_AL_DISABLED;
|
2012-02-20 20:53:28 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.flags |= MDF_AL_DISABLED;
|
2012-02-20 20:53:28 +00:00
|
|
|
|
2012-10-25 22:41:50 +00:00
|
|
|
if (new_disk_conf->md_flushes)
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(MD_NO_FUA, &device->flags);
|
2012-10-25 22:41:50 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(MD_NO_FUA, &device->flags);
|
2012-10-25 22:41:50 +00:00
|
|
|
|
2011-05-31 12:33:49 +00:00
|
|
|
drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush);
|
2012-03-30 12:12:15 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_sync(device);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn >= C_CONNECTED)
|
|
|
|
drbd_send_sync_param(device);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
synchronize_rcu();
|
|
|
|
kfree(old_disk_conf);
|
2011-05-03 14:47:02 +00:00
|
|
|
kfree(old_plan);
|
2011-07-03 11:26:43 +00:00
|
|
|
mod_timer(&device->request_timer, jiffies + HZ);
|
2011-05-03 13:00:55 +00:00
|
|
|
goto success;
|
|
|
|
|
|
|
|
fail_unlock:
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&device->resource->conf_update);
|
2011-03-23 13:31:09 +00:00
|
|
|
fail:
|
2011-04-27 19:14:57 +00:00
|
|
|
kfree(new_disk_conf);
|
2011-05-03 14:47:02 +00:00
|
|
|
kfree(new_plan);
|
2011-05-03 13:00:55 +00:00
|
|
|
success:
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-03-23 13:31:09 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
int err;
|
2010-12-08 12:33:11 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
enum determine_dev_size dd;
|
|
|
|
sector_t max_possible_sectors;
|
|
|
|
sector_t min_md_device_sectors;
|
|
|
|
struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */
|
2011-05-03 13:00:55 +00:00
|
|
|
struct disk_conf *new_disk_conf = NULL;
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
struct block_device *bdev;
|
2009-09-25 23:07:19 +00:00
|
|
|
struct lru_cache *resync_lru = NULL;
|
2011-05-03 14:19:31 +00:00
|
|
|
struct fifo_buffer *new_plan = NULL;
|
2009-09-25 23:07:19 +00:00
|
|
|
union drbd_state ns, os;
|
2010-12-10 12:44:05 +00:00
|
|
|
enum drbd_state_rv rv;
|
2011-04-19 15:10:19 +00:00
|
|
|
struct net_conf *nc;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
2011-03-16 15:52:10 +00:00
|
|
|
goto finish;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2011-05-31 12:33:49 +00:00
|
|
|
conn_reconfig_start(first_peer_device(device)->connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* if you want to reconfigure, please tear down first */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.disk > D_DISKLESS) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_DISK_CONFIGURED;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-10-16 10:13:47 +00:00
|
|
|
/* It may just now have detached because of IO error. Make sure
|
|
|
|
* drbd_ldev_destroy is done already, we may end up here very fast,
|
|
|
|
* e.g. if someone calls attach from the on-io-error handler,
|
|
|
|
* to realize a "hot spare" feature (not that I'd recommend that) */
|
2011-07-03 11:26:43 +00:00
|
|
|
wait_event(device->misc_wait, !atomic_read(&device->local_cnt));
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2012-06-14 12:21:32 +00:00
|
|
|
/* make sure there is no leftover from previous force-detach attempts */
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(FORCE_DETACH, &device->flags);
|
|
|
|
clear_bit(WAS_IO_ERROR, &device->flags);
|
|
|
|
clear_bit(WAS_READ_ERROR, &device->flags);
|
2012-06-14 12:21:32 +00:00
|
|
|
|
2012-06-14 16:02:52 +00:00
|
|
|
/* and no leftover from previously aborted resync or verify, either */
|
2011-07-03 11:26:43 +00:00
|
|
|
device->rs_total = 0;
|
|
|
|
device->rs_failed = 0;
|
|
|
|
atomic_set(&device->rs_pending_cnt, 0);
|
2012-06-14 16:02:52 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
/* allocation not in the IO path, drbdsetup context */
|
2009-09-25 23:07:19 +00:00
|
|
|
nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL);
|
|
|
|
if (!nbc) {
|
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-08-16 12:25:58 +00:00
|
|
|
spin_lock_init(&nbc->md.uuid_lock);
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
|
|
|
|
if (!new_disk_conf) {
|
|
|
|
retcode = ERR_NOMEM;
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-05-03 13:00:55 +00:00
|
|
|
nbc->disk_conf = new_disk_conf;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
set_disk_conf_defaults(new_disk_conf);
|
|
|
|
err = disk_conf_from_attrs(new_disk_conf, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2013-03-19 17:16:59 +00:00
|
|
|
if (new_disk_conf->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX)
|
|
|
|
new_disk_conf->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX;
|
2011-05-04 08:06:52 +00:00
|
|
|
|
2011-05-03 14:19:31 +00:00
|
|
|
new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ);
|
|
|
|
if (!new_plan) {
|
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
if (new_disk_conf->meta_dev_idx < DRBD_MD_INDEX_FLEX_INT) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_MD_IDX_INVALID;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2013-03-27 13:08:43 +00:00
|
|
|
write_lock_irq(&global_state_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_resync_after_valid(device, new_disk_conf->resync_after);
|
2013-03-27 13:08:43 +00:00
|
|
|
write_unlock_irq(&global_state_lock);
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail;
|
|
|
|
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_lock();
|
2011-05-31 12:33:49 +00:00
|
|
|
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
|
2011-04-19 15:10:19 +00:00
|
|
|
if (nc) {
|
2011-05-03 13:00:55 +00:00
|
|
|
if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) {
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_unlock();
|
2010-06-18 11:56:57 +00:00
|
|
|
retcode = ERR_STONITH_AND_PROT_A;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_unlock();
|
2010-06-18 11:56:57 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
bdev = blkdev_get_by_path(new_disk_conf->backing_dev,
|
2011-07-03 11:26:43 +00:00
|
|
|
FMODE_READ | FMODE_WRITE | FMODE_EXCL, device);
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
if (IS_ERR(bdev)) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "open(\"%s\") failed with %ld\n", new_disk_conf->backing_dev,
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
PTR_ERR(bdev));
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_OPEN_DISK;
|
|
|
|
goto fail;
|
|
|
|
}
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
nbc->backing_bdev = bdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* meta_dev_idx >= 0: external fixed size, possibly multiple
|
|
|
|
* drbd sharing one meta device. TODO in that case, paranoia
|
|
|
|
* check that [md_bdev, meta_dev_idx] is not yet used by some
|
|
|
|
* other drbd minor! (if you use drbd.conf + drbdadm, that
|
|
|
|
* should check it for you already; but if you don't, or
|
|
|
|
* someone fooled it, we need to double check here)
|
|
|
|
*/
|
2011-05-03 13:00:55 +00:00
|
|
|
bdev = blkdev_get_by_path(new_disk_conf->meta_dev,
|
2010-11-13 10:55:18 +00:00
|
|
|
FMODE_READ | FMODE_WRITE | FMODE_EXCL,
|
2011-05-03 13:00:55 +00:00
|
|
|
(new_disk_conf->meta_dev_idx < 0) ?
|
2011-07-03 11:26:43 +00:00
|
|
|
(void *)device : (void *)drbd_m_holder);
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
if (IS_ERR(bdev)) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "open(\"%s\") failed with %ld\n", new_disk_conf->meta_dev,
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
PTR_ERR(bdev));
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_OPEN_MD_DISK;
|
|
|
|
goto fail;
|
|
|
|
}
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
nbc->md_bdev = bdev;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
if ((nbc->backing_bdev == nbc->md_bdev) !=
|
2011-05-03 13:00:55 +00:00
|
|
|
(new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_INTERNAL ||
|
|
|
|
new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) {
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
retcode = ERR_MD_IDX_INVALID;
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
resync_lru = lc_create("resync", drbd_bm_ext_cache,
|
2011-02-21 12:21:01 +00:00
|
|
|
1, 61, sizeof(struct bm_extent),
|
2009-09-25 23:07:19 +00:00
|
|
|
offsetof(struct bm_extent, lce));
|
|
|
|
if (!resync_lru) {
|
|
|
|
retcode = ERR_NOMEM;
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 17:16:47 +00:00
|
|
|
/* Read our meta data super block early.
|
|
|
|
* This also sets other on-disk offsets. */
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_md_read(device, nbc);
|
2013-03-19 17:16:47 +00:00
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2013-03-19 17:16:59 +00:00
|
|
|
if (new_disk_conf->al_extents < DRBD_AL_EXTENTS_MIN)
|
|
|
|
new_disk_conf->al_extents = DRBD_AL_EXTENTS_MIN;
|
|
|
|
if (new_disk_conf->al_extents > drbd_al_extents_max(nbc))
|
|
|
|
new_disk_conf->al_extents = drbd_al_extents_max(nbc);
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "max capacity %llu smaller than disk size %llu\n",
|
2009-09-25 23:07:19 +00:00
|
|
|
(unsigned long long) drbd_get_max_capacity(nbc),
|
2011-05-03 13:00:55 +00:00
|
|
|
(unsigned long long) new_disk_conf->disk_size);
|
2011-06-06 13:36:04 +00:00
|
|
|
retcode = ERR_DISK_TOO_SMALL;
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
if (new_disk_conf->meta_dev_idx < 0) {
|
2009-09-25 23:07:19 +00:00
|
|
|
max_possible_sectors = DRBD_MAX_SECTORS_FLEX;
|
|
|
|
/* at least one MB, otherwise it does not make sense */
|
|
|
|
min_md_device_sectors = (2<<10);
|
|
|
|
} else {
|
|
|
|
max_possible_sectors = DRBD_MAX_SECTORS;
|
2013-03-19 17:16:43 +00:00
|
|
|
min_md_device_sectors = MD_128MB_SECT * (new_disk_conf->meta_dev_idx + 1);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) {
|
2011-06-06 13:36:04 +00:00
|
|
|
retcode = ERR_MD_DISK_TOO_SMALL;
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "refusing attach: md-device too small, "
|
2009-09-25 23:07:19 +00:00
|
|
|
"at least %llu sectors needed for this meta-disk type\n",
|
|
|
|
(unsigned long long) min_md_device_sectors);
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the new disk is big enough
|
|
|
|
* (we may currently be R_PRIMARY with no local disk...) */
|
|
|
|
if (drbd_get_max_capacity(nbc) <
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_get_capacity(device->this_bdev)) {
|
2011-06-06 13:36:04 +00:00
|
|
|
retcode = ERR_DISK_TOO_SMALL;
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nbc->known_size = drbd_get_capacity(nbc->backing_bdev);
|
|
|
|
|
2009-10-12 17:07:49 +00:00
|
|
|
if (nbc->known_size > max_possible_sectors) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "==> truncating very big lower level device "
|
2009-10-12 17:07:49 +00:00
|
|
|
"to currently maximum possible %llu sectors <==\n",
|
|
|
|
(unsigned long long) max_possible_sectors);
|
2011-05-03 13:00:55 +00:00
|
|
|
if (new_disk_conf->meta_dev_idx >= 0)
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "==>> using internal or flexible "
|
2009-10-12 17:07:49 +00:00
|
|
|
"meta data may help <<==\n");
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
/* also wait for the last barrier ack. */
|
2011-11-28 14:04:49 +00:00
|
|
|
/* FIXME see also https://daiquiri.linbit/cgi-bin/bugzilla/show_bug.cgi?id=171
|
|
|
|
* We need a way to either ignore barrier acks for barriers sent before a device
|
|
|
|
* was attached, or a way to wait for all pending barrier acks to come in.
|
|
|
|
* As barriers are counted per resource,
|
|
|
|
* we'd need to suspend io on all devices of a resource.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
wait_event(device->misc_wait, !atomic_read(&device->ap_pending_cnt) || drbd_suspended(device));
|
2009-09-25 23:07:19 +00:00
|
|
|
/* and for any other previously queued work */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_flush_workqueue(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
rv = _drbd_request_state(device, NS(disk, D_ATTACHING), CS_VERBOSE);
|
2010-12-10 12:44:05 +00:00
|
|
|
retcode = rv; /* FIXME: Type mismatch. */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_resume_io(device);
|
2010-12-10 12:44:05 +00:00
|
|
|
if (rv < SS_SUCCESS)
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!get_ldev_if_state(device, D_ATTACHING))
|
2009-09-25 23:07:19 +00:00
|
|
|
goto force_diskless;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!device->bitmap) {
|
|
|
|
if (drbd_bm_init(device)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn < C_CONNECTED &&
|
|
|
|
device->state.role == R_PRIMARY &&
|
|
|
|
(device->ed_uuid & ~((u64)1)) != (nbc->md.uuid[UI_CURRENT] & ~((u64)1))) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Can only attach to data with current UUID=%016llX\n",
|
2011-07-03 11:26:43 +00:00
|
|
|
(unsigned long long)device->ed_uuid);
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_DATA_NOT_CURRENT;
|
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since we are diskless, fix the activity log first... */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_check_al_size(device, new_disk_conf)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prevent shrinking of consistent devices ! */
|
|
|
|
if (drbd_md_test_flag(nbc, MDF_CONSISTENT) &&
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_new_dev_size(device, nbc, nbc->disk_conf->disk_size, 0) < nbc->md.la_size_sect) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_warn(device, "refusing to truncate a consistent device\n");
|
2011-06-06 13:36:04 +00:00
|
|
|
retcode = ERR_DISK_TOO_SMALL;
|
2009-09-25 23:07:19 +00:00
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the "barriers don't work" bits here, then force meta data to
|
|
|
|
* be written, to ensure we determine if barriers are supported. */
|
2011-05-04 13:25:35 +00:00
|
|
|
if (new_disk_conf->md_flushes)
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(MD_NO_FUA, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(MD_NO_FUA, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* Point of no return reached.
|
|
|
|
* Devices and memory are no longer released by error cleanup below.
|
2011-07-03 11:26:43 +00:00
|
|
|
* now device takes over responsibility, and the state engine should
|
2009-09-25 23:07:19 +00:00
|
|
|
* clean it up somewhere. */
|
2011-06-27 14:23:33 +00:00
|
|
|
D_ASSERT(device, device->ldev == NULL);
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev = nbc;
|
|
|
|
device->resync = resync_lru;
|
|
|
|
device->rs_plan_s = new_plan;
|
2009-09-25 23:07:19 +00:00
|
|
|
nbc = NULL;
|
|
|
|
resync_lru = NULL;
|
2011-05-03 13:00:55 +00:00
|
|
|
new_disk_conf = NULL;
|
2011-05-03 14:19:31 +00:00
|
|
|
new_plan = NULL;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-31 12:33:49 +00:00
|
|
|
drbd_bump_write_ordering(first_peer_device(device)->connection, WO_bdev_flush);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_CRASHED_PRIMARY))
|
|
|
|
set_bit(CRASHED_PRIMARY, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(CRASHED_PRIMARY, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_PRIMARY_IND) &&
|
2011-07-07 23:19:44 +00:00
|
|
|
!(device->state.role == R_PRIMARY && device->resource->susp_nod))
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(CRASHED_PRIMARY, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device->send_cnt = 0;
|
|
|
|
device->recv_cnt = 0;
|
|
|
|
device->read_cnt = 0;
|
|
|
|
device->writ_cnt = 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_reconsider_max_bio_size(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
/* If I am currently not R_PRIMARY,
|
|
|
|
* but meta data primary indicator is set,
|
|
|
|
* I just now recover from a hard crash,
|
|
|
|
* and have been R_PRIMARY before that crash.
|
|
|
|
*
|
|
|
|
* Now, if I had no connection before that crash
|
|
|
|
* (have been degraded R_PRIMARY), chances are that
|
|
|
|
* I won't find my peer now either.
|
|
|
|
*
|
|
|
|
* In that case, and _only_ in that case,
|
|
|
|
* we use the degr-wfc-timeout instead of the default,
|
|
|
|
* so we can automatically recover from a crash of a
|
|
|
|
* degraded but active "cluster" after a certain timeout.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
clear_bit(USE_DEGR_WFC_T, &device->flags);
|
|
|
|
if (device->state.role != R_PRIMARY &&
|
|
|
|
drbd_md_test_flag(device->ldev, MDF_PRIMARY_IND) &&
|
|
|
|
!drbd_md_test_flag(device->ldev, MDF_CONNECTED_IND))
|
|
|
|
set_bit(USE_DEGR_WFC_T, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
dd = drbd_determine_dev_size(device, 0, NULL);
|
2013-06-25 14:50:08 +00:00
|
|
|
if (dd <= DS_ERROR) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM_BITMAP;
|
|
|
|
goto force_diskless_dec;
|
2013-06-25 14:50:07 +00:00
|
|
|
} else if (dd == DS_GREW)
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(RESYNC_AFTER_NEG, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_FULL_SYNC) ||
|
|
|
|
(test_bit(CRASHED_PRIMARY, &device->flags) &&
|
|
|
|
drbd_md_test_flag(device->ldev, MDF_AL_DISABLED))) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Assuming that all blocks are out of sync "
|
2009-09-25 23:07:19 +00:00
|
|
|
"(aka FullSync)\n");
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_bitmap_io(device, &drbd_bmio_set_n_write,
|
2011-01-21 09:56:44 +00:00
|
|
|
"set_n_write from attaching", BM_LOCKED_MASK)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_IO_MD_DISK;
|
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
|
|
|
} else {
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_bitmap_io(device, &drbd_bm_read,
|
2010-12-13 00:44:11 +00:00
|
|
|
"read from attaching", BM_LOCKED_MASK)) {
|
2010-12-15 07:59:11 +00:00
|
|
|
retcode = ERR_IO_MD_DISK;
|
|
|
|
goto force_diskless_dec;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (_drbd_bm_total_weight(device) == drbd_bm_bits(device))
|
|
|
|
drbd_suspend_al(device); /* IO is still suspended here... */
|
2010-08-31 10:00:50 +00:00
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&device->resource->req_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
os = drbd_read_state(device);
|
2011-03-28 13:40:12 +00:00
|
|
|
ns = os;
|
2009-09-25 23:07:19 +00:00
|
|
|
/* If MDF_CONSISTENT is not set go into inconsistent state,
|
|
|
|
otherwise investigate MDF_WasUpToDate...
|
|
|
|
If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state,
|
|
|
|
otherwise into D_CONSISTENT state.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_CONSISTENT)) {
|
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_WAS_UP_TO_DATE))
|
2009-09-25 23:07:19 +00:00
|
|
|
ns.disk = D_CONSISTENT;
|
|
|
|
else
|
|
|
|
ns.disk = D_OUTDATED;
|
|
|
|
} else {
|
|
|
|
ns.disk = D_INCONSISTENT;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_md_test_flag(device->ldev, MDF_PEER_OUT_DATED))
|
2009-09-25 23:07:19 +00:00
|
|
|
ns.pdsk = D_OUTDATED;
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
if (ns.disk == D_CONSISTENT &&
|
2011-07-03 11:26:43 +00:00
|
|
|
(ns.pdsk == D_OUTDATED || rcu_dereference(device->ldev->disk_conf)->fencing == FP_DONT_CARE))
|
2009-09-25 23:07:19 +00:00
|
|
|
ns.disk = D_UP_TO_DATE;
|
|
|
|
|
|
|
|
/* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND,
|
|
|
|
MDF_CONSISTENT and MDF_WAS_UP_TO_DATE must happen before
|
|
|
|
this point, because drbd_request_state() modifies these
|
|
|
|
flags. */
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (rcu_dereference(device->ldev->disk_conf)->al_updates)
|
|
|
|
device->ldev->md.flags &= ~MDF_AL_DISABLED;
|
2012-02-20 20:53:28 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.flags |= MDF_AL_DISABLED;
|
2012-02-20 20:53:28 +00:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
/* In case we are C_CONNECTED postpone any decision on the new disk
|
|
|
|
state after the negotiation phase. */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_CONNECTED) {
|
|
|
|
device->new_state_tmp.i = ns.i;
|
2009-09-25 23:07:19 +00:00
|
|
|
ns.i = os.i;
|
|
|
|
ns.disk = D_NEGOTIATING;
|
2010-06-02 12:31:29 +00:00
|
|
|
|
|
|
|
/* We expect to receive up-to-date UUIDs soon.
|
|
|
|
To avoid a race in receive_state, free p_uuid while
|
|
|
|
holding req_lock. I.e. atomic with the state change */
|
2011-07-03 11:26:43 +00:00
|
|
|
kfree(device->p_uuid);
|
|
|
|
device->p_uuid = NULL;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
rv = _drbd_set_state(device, ns, CS_VERBOSE, NULL);
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&device->resource->req_lock);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (rv < SS_SUCCESS)
|
|
|
|
goto force_diskless_dec;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
mod_timer(&device->request_timer, jiffies + HZ);
|
2011-07-05 13:38:59 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.role == R_PRIMARY)
|
|
|
|
device->ldev->md.uuid[UI_CURRENT] |= (u64)1;
|
2009-09-25 23:07:19 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_mark_dirty(device);
|
|
|
|
drbd_md_sync(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
kobject_uevent(&disk_to_dev(device->vdisk)->kobj, KOBJ_CHANGE);
|
|
|
|
put_ldev(device);
|
2011-05-31 12:33:49 +00:00
|
|
|
conn_reconfig_done(first_peer_device(device)->connection);
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
force_diskless_dec:
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
force_diskless:
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_force_state(device, NS(disk, D_DISKLESS));
|
|
|
|
drbd_md_sync(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
fail:
|
2011-05-31 12:33:49 +00:00
|
|
|
conn_reconfig_done(first_peer_device(device)->connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (nbc) {
|
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
2010-11-13 10:55:17 +00:00
|
|
|
if (nbc->backing_bdev)
|
|
|
|
blkdev_put(nbc->backing_bdev,
|
|
|
|
FMODE_READ | FMODE_WRITE | FMODE_EXCL);
|
|
|
|
if (nbc->md_bdev)
|
|
|
|
blkdev_put(nbc->md_bdev,
|
|
|
|
FMODE_READ | FMODE_WRITE | FMODE_EXCL);
|
2009-09-25 23:07:19 +00:00
|
|
|
kfree(nbc);
|
|
|
|
}
|
2011-05-03 13:00:55 +00:00
|
|
|
kfree(new_disk_conf);
|
2009-09-25 23:07:19 +00:00
|
|
|
lc_destroy(resync_lru);
|
2011-05-03 14:19:31 +00:00
|
|
|
kfree(new_plan);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-16 15:52:10 +00:00
|
|
|
finish:
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
static int adm_detach(struct drbd_device *device, int force)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-29 12:21:03 +00:00
|
|
|
enum drbd_state_rv retcode;
|
2011-05-02 09:51:31 +00:00
|
|
|
int ret;
|
2011-03-14 10:54:47 +00:00
|
|
|
|
2011-07-05 13:38:59 +00:00
|
|
|
if (force) {
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(FORCE_DETACH, &device->flags);
|
|
|
|
drbd_force_state(device, NS(disk, D_FAILED));
|
2011-07-05 13:38:59 +00:00
|
|
|
retcode = SS_SUCCESS;
|
2011-03-14 10:54:47 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device); /* so no-one is stuck in drbd_al_begin_io */
|
|
|
|
drbd_md_get_buffer(device); /* make sure there is no in-flight meta-data IO */
|
|
|
|
retcode = drbd_request_state(device, NS(disk, D_FAILED));
|
|
|
|
drbd_md_put_buffer(device);
|
2011-05-02 09:51:31 +00:00
|
|
|
/* D_FAILED will transition to DISKLESS. */
|
2011-07-03 11:26:43 +00:00
|
|
|
ret = wait_event_interruptible(device->misc_wait,
|
|
|
|
device->state.disk != D_FAILED);
|
|
|
|
drbd_resume_io(device);
|
2011-05-24 08:27:38 +00:00
|
|
|
if ((int)retcode == (int)SS_IS_DISKLESS)
|
2011-05-02 09:51:31 +00:00
|
|
|
retcode = SS_NOTHING_TO_DO;
|
|
|
|
if (ret)
|
|
|
|
retcode = ERR_INTR;
|
2011-03-14 10:54:47 +00:00
|
|
|
out:
|
2011-03-15 15:26:37 +00:00
|
|
|
return retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-10-16 10:13:47 +00:00
|
|
|
/* Detaching the disk is a process in multiple stages. First we need to lock
|
|
|
|
* out application IO, in-flight IO, IO stuck in drbd_al_begin_io.
|
|
|
|
* Then we transition to D_DISKLESS, and wait for put_ldev() to return all
|
|
|
|
* internal references as well.
|
|
|
|
* Only then we have finally detached. */
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2010-12-08 12:33:11 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2011-07-05 13:38:59 +00:00
|
|
|
struct detach_parms parms = { };
|
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-05 13:38:59 +00:00
|
|
|
if (info->attrs[DRBD_NLA_DETACH_PARMS]) {
|
|
|
|
err = detach_parms_from_attrs(&parms, info);
|
|
|
|
if (err) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = adm_detach(adm_ctx.device, parms.force_detach);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static bool conn_resync_running(struct drbd_connection *connection)
|
2011-03-23 13:31:09 +00:00
|
|
|
{
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-04-12 05:53:32 +00:00
|
|
|
bool rv = false;
|
2011-03-23 13:31:09 +00:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_lock();
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_SYNC_SOURCE ||
|
|
|
|
device->state.conn == C_SYNC_TARGET ||
|
|
|
|
device->state.conn == C_PAUSED_SYNC_S ||
|
|
|
|
device->state.conn == C_PAUSED_SYNC_T) {
|
2011-04-12 05:53:32 +00:00
|
|
|
rv = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_unlock();
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
return rv;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
2010-06-18 11:56:57 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static bool conn_ov_running(struct drbd_connection *connection)
|
2011-03-23 13:31:09 +00:00
|
|
|
{
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-04-12 05:53:32 +00:00
|
|
|
bool rv = false;
|
2011-03-23 13:31:09 +00:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_lock();
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_VERIFY_S ||
|
|
|
|
device->state.conn == C_VERIFY_T) {
|
2011-04-12 05:53:32 +00:00
|
|
|
rv = true;
|
|
|
|
break;
|
2010-06-18 11:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_unlock();
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
return rv;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
2010-10-27 09:12:07 +00:00
|
|
|
|
2011-04-14 01:00:59 +00:00
|
|
|
static enum drbd_ret_code
|
2011-07-06 12:42:39 +00:00
|
|
|
_check_net_options(struct drbd_connection *connection, struct net_conf *old_net_conf, struct net_conf *new_net_conf)
|
2011-04-14 01:00:59 +00:00
|
|
|
{
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-04-14 01:00:59 +00:00
|
|
|
int i;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (old_net_conf && connection->cstate == C_WF_REPORT_PARAMS && connection->agreed_pro_version < 100) {
|
|
|
|
if (new_net_conf->wire_protocol != old_net_conf->wire_protocol)
|
2011-05-16 12:30:24 +00:00
|
|
|
return ERR_NEED_APV_100;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (new_net_conf->two_primaries != old_net_conf->two_primaries)
|
2011-05-16 12:30:24 +00:00
|
|
|
return ERR_NEED_APV_100;
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (strcmp(new_net_conf->integrity_alg, old_net_conf->integrity_alg))
|
2011-05-16 12:30:24 +00:00
|
|
|
return ERR_NEED_APV_100;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (!new_net_conf->two_primaries &&
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_highest_role(connection) == R_PRIMARY &&
|
|
|
|
conn_highest_peer(connection) == R_PRIMARY)
|
2011-05-16 12:30:24 +00:00
|
|
|
return ERR_NEED_ALLOW_TWO_PRI;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (new_net_conf->two_primaries &&
|
|
|
|
(new_net_conf->wire_protocol != DRBD_PROT_C))
|
2011-04-14 01:00:59 +00:00
|
|
|
return ERR_NOT_PROTO_C;
|
|
|
|
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, i) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (get_ldev(device)) {
|
|
|
|
enum drbd_fencing_p fp = rcu_dereference(device->ldev->disk_conf)->fencing;
|
|
|
|
put_ldev(device);
|
2011-07-06 12:42:39 +00:00
|
|
|
if (new_net_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH)
|
2011-04-14 01:00:59 +00:00
|
|
|
return ERR_STONITH_AND_PROT_A;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-07-06 12:42:39 +00:00
|
|
|
if (device->state.role == R_PRIMARY && new_net_conf->discard_my_data)
|
2012-08-01 10:46:20 +00:00
|
|
|
return ERR_DISCARD_IMPOSSIBLE;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (new_net_conf->on_congestion != OC_BLOCK && new_net_conf->wire_protocol != DRBD_PROT_A)
|
2011-04-14 01:00:59 +00:00
|
|
|
return ERR_CONG_NOT_PROTO_A;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-14 01:00:59 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-19 15:10:19 +00:00
|
|
|
static enum drbd_ret_code
|
2011-07-06 12:42:39 +00:00
|
|
|
check_net_options(struct drbd_connection *connection, struct net_conf *new_net_conf)
|
2011-04-19 15:10:19 +00:00
|
|
|
{
|
|
|
|
static enum drbd_ret_code rv;
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-04-19 15:10:19 +00:00
|
|
|
int i;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_lock();
|
2011-07-06 12:42:39 +00:00
|
|
|
rv = _check_net_options(connection, rcu_dereference(connection->net_conf), new_net_conf);
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_unlock();
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
/* connection->volumes protected by genl_lock() here */
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, i) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!device->bitmap) {
|
|
|
|
if (drbd_bm_init(device))
|
2011-04-19 15:10:19 +00:00
|
|
|
return ERR_NOMEM;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-19 15:10:19 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
struct crypto {
|
|
|
|
struct crypto_hash *verify_tfm;
|
|
|
|
struct crypto_hash *csums_tfm;
|
|
|
|
struct crypto_hash *cram_hmac_tfm;
|
2011-04-27 18:59:18 +00:00
|
|
|
struct crypto_hash *integrity_tfm;
|
2011-04-27 09:27:47 +00:00
|
|
|
};
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
static int
|
2011-04-29 08:20:08 +00:00
|
|
|
alloc_hash(struct crypto_hash **tfm, char *tfm_name, int err_alg)
|
2011-04-27 09:27:47 +00:00
|
|
|
{
|
|
|
|
if (!tfm_name[0])
|
|
|
|
return NO_ERROR;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
*tfm = crypto_alloc_hash(tfm_name, 0, CRYPTO_ALG_ASYNC);
|
|
|
|
if (IS_ERR(*tfm)) {
|
|
|
|
*tfm = NULL;
|
|
|
|
return err_alg;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
static enum drbd_ret_code
|
2011-07-06 12:42:39 +00:00
|
|
|
alloc_crypto(struct crypto *crypto, struct net_conf *new_net_conf)
|
2011-04-27 09:27:47 +00:00
|
|
|
{
|
|
|
|
char hmac_name[CRYPTO_MAX_ALG_NAME];
|
|
|
|
enum drbd_ret_code rv;
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
rv = alloc_hash(&crypto->csums_tfm, new_net_conf->csums_alg,
|
2011-04-29 08:20:08 +00:00
|
|
|
ERR_CSUMS_ALG);
|
2011-04-27 09:27:47 +00:00
|
|
|
if (rv != NO_ERROR)
|
|
|
|
return rv;
|
2011-07-06 12:42:39 +00:00
|
|
|
rv = alloc_hash(&crypto->verify_tfm, new_net_conf->verify_alg,
|
2011-04-29 08:20:08 +00:00
|
|
|
ERR_VERIFY_ALG);
|
2011-04-27 09:27:47 +00:00
|
|
|
if (rv != NO_ERROR)
|
|
|
|
return rv;
|
2011-07-06 12:42:39 +00:00
|
|
|
rv = alloc_hash(&crypto->integrity_tfm, new_net_conf->integrity_alg,
|
2011-04-29 08:20:08 +00:00
|
|
|
ERR_INTEGRITY_ALG);
|
2011-04-27 09:27:47 +00:00
|
|
|
if (rv != NO_ERROR)
|
|
|
|
return rv;
|
2011-07-06 12:42:39 +00:00
|
|
|
if (new_net_conf->cram_hmac_alg[0] != 0) {
|
2011-04-27 09:27:47 +00:00
|
|
|
snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)",
|
2011-07-06 12:42:39 +00:00
|
|
|
new_net_conf->cram_hmac_alg);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-29 08:20:08 +00:00
|
|
|
rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name,
|
|
|
|
ERR_AUTH_ALG);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 09:27:47 +00:00
|
|
|
static void free_crypto(struct crypto *crypto)
|
|
|
|
{
|
|
|
|
crypto_free_hash(crypto->cram_hmac_tfm);
|
2011-04-27 18:59:18 +00:00
|
|
|
crypto_free_hash(crypto->integrity_tfm);
|
2011-04-27 09:27:47 +00:00
|
|
|
crypto_free_hash(crypto->csums_tfm);
|
|
|
|
crypto_free_hash(crypto->verify_tfm);
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
enum drbd_ret_code retcode;
|
2011-05-30 14:32:41 +00:00
|
|
|
struct drbd_connection *connection;
|
2011-07-06 12:42:39 +00:00
|
|
|
struct net_conf *old_net_conf, *new_net_conf = NULL;
|
2011-03-23 13:31:09 +00:00
|
|
|
int err;
|
|
|
|
int ovr; /* online verify running */
|
|
|
|
int rsr; /* re-sync running */
|
2011-04-27 09:27:47 +00:00
|
|
|
struct crypto crypto = { };
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION);
|
2011-03-23 13:31:09 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
connection = adm_ctx.connection;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL);
|
|
|
|
if (!new_net_conf) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_reconfig_start(connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
mutex_lock(&connection->data.mutex);
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_lock(&connection->resource->conf_update);
|
2011-07-06 12:42:39 +00:00
|
|
|
old_net_conf = connection->net_conf;
|
2010-12-03 14:22:48 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
if (!old_net_conf) {
|
2011-03-23 13:31:09 +00:00
|
|
|
drbd_msg_put_info("net conf missing, try connect");
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
2010-12-03 14:22:48 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
*new_net_conf = *old_net_conf;
|
2011-04-27 19:09:55 +00:00
|
|
|
if (should_set_defaults(info))
|
2011-07-06 12:42:39 +00:00
|
|
|
set_net_conf_defaults(new_net_conf);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
err = net_conf_from_attrs_for_change(new_net_conf, info);
|
2011-05-24 12:18:31 +00:00
|
|
|
if (err && err != -ENOMSG) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto fail;
|
2010-12-03 14:22:48 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
retcode = check_net_options(connection, new_net_conf);
|
2011-04-14 01:00:59 +00:00
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-23 13:31:09 +00:00
|
|
|
/* re-sync running */
|
2011-05-30 14:32:41 +00:00
|
|
|
rsr = conn_resync_running(connection);
|
2011-07-06 12:42:39 +00:00
|
|
|
if (rsr && strcmp(new_net_conf->csums_alg, old_net_conf->csums_alg)) {
|
2011-03-23 13:31:09 +00:00
|
|
|
retcode = ERR_CSUMS_RESYNC_RUNNING;
|
2011-04-20 15:47:29 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 13:31:09 +00:00
|
|
|
/* online verify running */
|
2011-05-30 14:32:41 +00:00
|
|
|
ovr = conn_ov_running(connection);
|
2011-07-06 12:42:39 +00:00
|
|
|
if (ovr && strcmp(new_net_conf->verify_alg, old_net_conf->verify_alg)) {
|
2011-04-27 09:27:47 +00:00
|
|
|
retcode = ERR_VERIFY_RUNNING;
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
retcode = alloc_crypto(&crypto, new_net_conf);
|
2011-04-27 09:27:47 +00:00
|
|
|
if (retcode != NO_ERROR)
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
rcu_assign_pointer(connection->net_conf, new_net_conf);
|
2011-03-23 13:31:09 +00:00
|
|
|
|
|
|
|
if (!rsr) {
|
2011-05-30 14:32:41 +00:00
|
|
|
crypto_free_hash(connection->csums_tfm);
|
|
|
|
connection->csums_tfm = crypto.csums_tfm;
|
2011-04-27 09:27:47 +00:00
|
|
|
crypto.csums_tfm = NULL;
|
2011-03-23 13:31:09 +00:00
|
|
|
}
|
|
|
|
if (!ovr) {
|
2011-05-30 14:32:41 +00:00
|
|
|
crypto_free_hash(connection->verify_tfm);
|
|
|
|
connection->verify_tfm = crypto.verify_tfm;
|
2011-04-27 09:27:47 +00:00
|
|
|
crypto.verify_tfm = NULL;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
crypto_free_hash(connection->integrity_tfm);
|
|
|
|
connection->integrity_tfm = crypto.integrity_tfm;
|
|
|
|
if (connection->cstate >= C_WF_REPORT_PARAMS && connection->agreed_pro_version >= 100)
|
|
|
|
/* Do this without trying to take connection->data.mutex again. */
|
|
|
|
__drbd_send_protocol(connection, P_PROTOCOL_UPDATE);
|
2011-04-27 09:27:47 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
crypto_free_hash(connection->cram_hmac_tfm);
|
|
|
|
connection->cram_hmac_tfm = crypto.cram_hmac_tfm;
|
2011-04-27 09:27:47 +00:00
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&connection->resource->conf_update);
|
2011-05-30 14:32:41 +00:00
|
|
|
mutex_unlock(&connection->data.mutex);
|
2011-04-20 15:47:29 +00:00
|
|
|
synchronize_rcu();
|
2011-07-06 12:42:39 +00:00
|
|
|
kfree(old_net_conf);
|
2011-04-20 15:47:29 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
if (connection->cstate >= C_WF_REPORT_PARAMS)
|
|
|
|
drbd_send_sync_param(minor_to_device(conn_lowest_minor(connection)));
|
2011-03-23 13:31:09 +00:00
|
|
|
|
2011-04-20 15:47:29 +00:00
|
|
|
goto done;
|
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
fail:
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&connection->resource->conf_update);
|
2011-05-30 14:32:41 +00:00
|
|
|
mutex_unlock(&connection->data.mutex);
|
2011-04-27 09:27:47 +00:00
|
|
|
free_crypto(&crypto);
|
2011-07-06 12:42:39 +00:00
|
|
|
kfree(new_net_conf);
|
2011-04-20 15:47:29 +00:00
|
|
|
done:
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_reconfig_done(connection);
|
2011-03-23 13:31:09 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-06-21 15:23:59 +00:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-07-06 12:42:39 +00:00
|
|
|
struct net_conf *old_net_conf, *new_net_conf = NULL;
|
2011-04-27 09:27:47 +00:00
|
|
|
struct crypto crypto = { };
|
2011-06-08 20:17:38 +00:00
|
|
|
struct drbd_resource *resource;
|
2011-05-30 14:32:41 +00:00
|
|
|
struct drbd_connection *connection;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
|
|
|
int i;
|
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 14:07:32 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2011-06-14 16:28:09 +00:00
|
|
|
if (!(adm_ctx.my_addr && adm_ctx.peer_addr)) {
|
|
|
|
drbd_msg_put_info("connection endpoint(s) missing");
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
/* No need for _rcu here. All reconfiguration is
|
|
|
|
* strictly serialized on genl_lock(). We are protected against
|
|
|
|
* concurrent reconfiguration/addition/deletion */
|
2011-06-08 20:17:38 +00:00
|
|
|
for_each_resource(resource, &drbd_resources) {
|
|
|
|
for_each_connection(connection, resource) {
|
|
|
|
if (nla_len(adm_ctx.my_addr) == connection->my_addr_len &&
|
|
|
|
!memcmp(nla_data(adm_ctx.my_addr), &connection->my_addr,
|
|
|
|
connection->my_addr_len)) {
|
|
|
|
retcode = ERR_LOCAL_ADDR;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-08 20:17:38 +00:00
|
|
|
if (nla_len(adm_ctx.peer_addr) == connection->peer_addr_len &&
|
|
|
|
!memcmp(nla_data(adm_ctx.peer_addr), &connection->peer_addr,
|
|
|
|
connection->peer_addr_len)) {
|
|
|
|
retcode = ERR_PEER_ADDR;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-06-14 16:28:09 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 13:05:58 +00:00
|
|
|
connection = first_connection(adm_ctx.resource);
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_reconfig_start(connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
if (connection->cstate > C_STANDALONE) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NET_CONFIGURED;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-08-17 10:43:25 +00:00
|
|
|
/* allocation not in the IO path, drbdsetup / netlink process context */
|
2011-07-06 12:42:39 +00:00
|
|
|
new_net_conf = kzalloc(sizeof(*new_net_conf), GFP_KERNEL);
|
|
|
|
if (!new_net_conf) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
set_net_conf_defaults(new_net_conf);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
err = net_conf_from_attrs(new_net_conf, info);
|
2011-08-19 08:39:00 +00:00
|
|
|
if (err && err != -ENOMSG) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
retcode = check_net_options(connection, new_net_conf);
|
2011-04-14 01:00:59 +00:00
|
|
|
if (retcode != NO_ERROR)
|
2010-10-27 09:12:07 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
retcode = alloc_crypto(&crypto, new_net_conf);
|
2011-04-27 09:27:47 +00:00
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 12:42:39 +00:00
|
|
|
((char *)new_net_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0;
|
2011-09-28 20:15:04 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_flush_workqueue(connection);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_lock(&adm_ctx.resource->conf_update);
|
2011-07-06 12:42:39 +00:00
|
|
|
old_net_conf = connection->net_conf;
|
|
|
|
if (old_net_conf) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NET_CONFIGURED;
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&adm_ctx.resource->conf_update);
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2011-07-06 12:42:39 +00:00
|
|
|
rcu_assign_pointer(connection->net_conf, new_net_conf);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_free_crypto(connection);
|
|
|
|
connection->cram_hmac_tfm = crypto.cram_hmac_tfm;
|
|
|
|
connection->integrity_tfm = crypto.integrity_tfm;
|
|
|
|
connection->csums_tfm = crypto.csums_tfm;
|
|
|
|
connection->verify_tfm = crypto.verify_tfm;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
connection->my_addr_len = nla_len(adm_ctx.my_addr);
|
|
|
|
memcpy(&connection->my_addr, nla_data(adm_ctx.my_addr), connection->my_addr_len);
|
|
|
|
connection->peer_addr_len = nla_len(adm_ctx.peer_addr);
|
|
|
|
memcpy(&connection->peer_addr, nla_data(adm_ctx.peer_addr), connection->peer_addr_len);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&adm_ctx.resource->conf_update);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_lock();
|
2011-06-21 15:23:59 +00:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, i) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 11:26:43 +00:00
|
|
|
device->send_cnt = 0;
|
|
|
|
device->recv_cnt = 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-04-12 05:53:32 +00:00
|
|
|
rcu_read_unlock();
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
retcode = conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_reconfig_done(connection);
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2011-04-27 09:27:47 +00:00
|
|
|
free_crypto(&crypto);
|
2011-07-06 12:42:39 +00:00
|
|
|
kfree(new_net_conf);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
conn_reconfig_done(connection);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
static enum drbd_state_rv conn_try_disconnect(struct drbd_connection *connection, bool force)
|
2011-03-15 15:26:37 +00:00
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_request_state(connection, NS(conn, C_DISCONNECTING),
|
2011-05-02 08:45:05 +00:00
|
|
|
force ? CS_HARD : 0);
|
2011-03-15 15:26:37 +00:00
|
|
|
|
|
|
|
switch (rv) {
|
|
|
|
case SS_NOTHING_TO_DO:
|
2011-05-02 08:45:05 +00:00
|
|
|
break;
|
2011-03-15 15:26:37 +00:00
|
|
|
case SS_ALREADY_STANDALONE:
|
|
|
|
return SS_SUCCESS;
|
|
|
|
case SS_PRIMARY_NOP:
|
|
|
|
/* Our state checking code wants to see the peer outdated. */
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_request_state(connection, NS2(conn, C_DISCONNECTING, pdsk, D_OUTDATED), 0);
|
2013-03-27 13:08:40 +00:00
|
|
|
|
|
|
|
if (rv == SS_OUTDATE_WO_CONN) /* lost connection before graceful disconnect succeeded */
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_VERBOSE);
|
2013-03-27 13:08:40 +00:00
|
|
|
|
2011-03-15 15:26:37 +00:00
|
|
|
break;
|
|
|
|
case SS_CW_FAILED_BY_PEER:
|
|
|
|
/* The peer probably wants to see us outdated. */
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_request_state(connection, NS2(conn, C_DISCONNECTING,
|
2011-03-15 15:26:37 +00:00
|
|
|
disk, D_OUTDATED), 0);
|
|
|
|
if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) {
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_request_state(connection, NS(conn, C_DISCONNECTING),
|
2011-05-02 08:45:05 +00:00
|
|
|
CS_HARD);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-15 15:26:37 +00:00
|
|
|
break;
|
|
|
|
default:;
|
|
|
|
/* no special handling necessary */
|
|
|
|
}
|
|
|
|
|
2011-05-02 08:45:05 +00:00
|
|
|
if (rv >= SS_SUCCESS) {
|
|
|
|
enum drbd_state_rv rv2;
|
|
|
|
/* No one else can reconfigure the network while I am here.
|
|
|
|
* The state handling only uses drbd_thread_stop_nowait(),
|
|
|
|
* we want to really wait here until the receiver is no more.
|
|
|
|
*/
|
2011-06-21 11:58:18 +00:00
|
|
|
drbd_thread_stop(&connection->receiver);
|
2011-05-02 08:45:05 +00:00
|
|
|
|
|
|
|
/* Race breaker. This additional state change request may be
|
|
|
|
* necessary, if this was a forced disconnect during a receiver
|
|
|
|
* restart. We may have "killed" the receiver thread just
|
2011-07-22 09:04:36 +00:00
|
|
|
* after drbd_receiver() returned. Typically, we should be
|
2011-05-02 08:45:05 +00:00
|
|
|
* C_STANDALONE already, now, and this becomes a no-op.
|
|
|
|
*/
|
2011-05-30 14:32:41 +00:00
|
|
|
rv2 = conn_request_state(connection, NS(conn, C_STANDALONE),
|
2011-05-02 08:45:05 +00:00
|
|
|
CS_VERBOSE | CS_HARD);
|
|
|
|
if (rv2 < SS_SUCCESS)
|
2011-07-06 09:01:44 +00:00
|
|
|
drbd_err(connection,
|
2011-05-02 08:45:05 +00:00
|
|
|
"unexpected rv2=%d in conn_try_disconnect()\n",
|
|
|
|
rv2);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-15 15:26:37 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
struct disconnect_parms parms;
|
2011-05-30 14:32:41 +00:00
|
|
|
struct drbd_connection *connection;
|
2011-03-15 15:26:37 +00:00
|
|
|
enum drbd_state_rv rv;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
|
|
|
int err;
|
2010-12-03 14:22:48 +00:00
|
|
|
|
2011-06-14 16:28:09 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
2010-12-03 14:22:48 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
connection = adm_ctx.connection;
|
2011-03-07 11:49:34 +00:00
|
|
|
memset(&parms, 0, sizeof(parms));
|
|
|
|
if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) {
|
2011-03-23 13:31:09 +00:00
|
|
|
err = disconnect_parms_from_attrs(&parms, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
rv = conn_try_disconnect(connection, parms.force_disconnect);
|
2011-03-15 15:26:37 +00:00
|
|
|
if (rv < SS_SUCCESS)
|
2011-05-02 08:45:05 +00:00
|
|
|
retcode = rv; /* FIXME: Type mismatch. */
|
|
|
|
else
|
|
|
|
retcode = NO_ERROR;
|
2009-09-25 23:07:19 +00:00
|
|
|
fail:
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
void resync_after_online_grow(struct drbd_device *device)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
|
|
|
int iass; /* I am sync source */
|
|
|
|
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Resync of new storage after online grow\n");
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.role != device->state.peer)
|
|
|
|
iass = (device->state.role == R_PRIMARY);
|
2009-09-25 23:07:19 +00:00
|
|
|
else
|
2011-05-31 12:33:49 +00:00
|
|
|
iass = test_bit(RESOLVE_CONFLICTS, &first_peer_device(device)->connection->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (iass)
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_start_resync(device, C_SYNC_SOURCE);
|
2009-09-25 23:07:19 +00:00
|
|
|
else
|
2011-07-03 11:26:43 +00:00
|
|
|
_drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-05-03 13:00:55 +00:00
|
|
|
struct disk_conf *old_disk_conf, *new_disk_conf = NULL;
|
2011-03-07 11:49:34 +00:00
|
|
|
struct resize_parms rs;
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
enum determine_dev_size dd;
|
2013-06-25 14:50:08 +00:00
|
|
|
bool change_al_layout = false;
|
2010-03-24 15:07:04 +00:00
|
|
|
enum dds_flags ddsf;
|
2011-05-03 13:00:55 +00:00
|
|
|
sector_t u_size;
|
2011-03-07 11:49:34 +00:00
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
2011-03-07 11:49:34 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
|
|
|
if (!get_ldev(device)) {
|
2013-06-25 14:50:08 +00:00
|
|
|
retcode = ERR_NO_DISK;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
memset(&rs, 0, sizeof(struct resize_parms));
|
2011-07-03 11:26:43 +00:00
|
|
|
rs.al_stripes = device->ldev->md.al_stripes;
|
|
|
|
rs.al_stripe_size = device->ldev->md.al_stripe_size_4k * 4;
|
2011-03-07 11:49:34 +00:00
|
|
|
if (info->attrs[DRBD_NLA_RESIZE_PARMS]) {
|
2011-03-23 13:31:09 +00:00
|
|
|
err = resize_parms_from_attrs(&rs, info);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (err) {
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2013-06-25 14:50:08 +00:00
|
|
|
goto fail_ldev;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn > C_CONNECTED) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_RESIZE_RESYNC;
|
2013-06-25 14:50:08 +00:00
|
|
|
goto fail_ldev;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.role == R_SECONDARY &&
|
|
|
|
device->state.peer == R_SECONDARY) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NO_PRIMARY;
|
2013-06-25 14:50:08 +00:00
|
|
|
goto fail_ldev;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-05-31 12:33:49 +00:00
|
|
|
if (rs.no_resync && first_peer_device(device)->connection->agreed_pro_version < 93) {
|
2010-03-24 15:07:04 +00:00
|
|
|
retcode = ERR_NEED_APV_93;
|
2011-09-29 11:00:14 +00:00
|
|
|
goto fail_ldev;
|
2010-03-24 15:07:04 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_lock();
|
2011-07-03 11:26:43 +00:00
|
|
|
u_size = rcu_dereference(device->ldev->disk_conf)->disk_size;
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
if (u_size != (sector_t)rs.resize_size) {
|
|
|
|
new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
|
|
|
|
if (!new_disk_conf) {
|
2010-07-06 09:14:00 +00:00
|
|
|
retcode = ERR_NOMEM;
|
2011-09-29 11:00:14 +00:00
|
|
|
goto fail_ldev;
|
2010-07-06 09:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->ldev->md.al_stripes != rs.al_stripes ||
|
|
|
|
device->ldev->md.al_stripe_size_4k != rs.al_stripe_size / 4) {
|
2013-06-25 14:50:08 +00:00
|
|
|
u32 al_size_k = rs.al_stripes * rs.al_stripe_size;
|
|
|
|
|
|
|
|
if (al_size_k > (16 * 1024 * 1024)) {
|
|
|
|
retcode = ERR_MD_LAYOUT_TOO_BIG;
|
|
|
|
goto fail_ldev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (al_size_k < MD_32kB_SECT/2) {
|
|
|
|
retcode = ERR_MD_LAYOUT_TOO_SMALL;
|
|
|
|
goto fail_ldev;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn != C_CONNECTED) {
|
2013-06-25 14:50:08 +00:00
|
|
|
retcode = ERR_MD_LAYOUT_CONNECTED;
|
|
|
|
goto fail_ldev;
|
|
|
|
}
|
|
|
|
|
|
|
|
change_al_layout = true;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev))
|
|
|
|
device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
if (new_disk_conf) {
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_lock(&device->resource->conf_update);
|
2011-07-03 11:26:43 +00:00
|
|
|
old_disk_conf = device->ldev->disk_conf;
|
2011-05-03 13:00:55 +00:00
|
|
|
*new_disk_conf = *old_disk_conf;
|
|
|
|
new_disk_conf->disk_size = (sector_t)rs.resize_size;
|
2011-07-03 11:26:43 +00:00
|
|
|
rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf);
|
2011-07-07 12:19:42 +00:00
|
|
|
mutex_unlock(&device->resource->conf_update);
|
2011-05-03 13:00:55 +00:00
|
|
|
synchronize_rcu();
|
|
|
|
kfree(old_disk_conf);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 15:07:04 +00:00
|
|
|
ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0);
|
2011-07-03 11:26:43 +00:00
|
|
|
dd = drbd_determine_dev_size(device, ddsf, change_al_layout ? &rs : NULL);
|
|
|
|
drbd_md_sync(device);
|
|
|
|
put_ldev(device);
|
2013-06-25 14:50:07 +00:00
|
|
|
if (dd == DS_ERROR) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM_BITMAP;
|
|
|
|
goto fail;
|
2013-06-25 14:50:08 +00:00
|
|
|
} else if (dd == DS_ERROR_SPACE_MD) {
|
|
|
|
retcode = ERR_MD_LAYOUT_NO_FIT;
|
|
|
|
goto fail;
|
|
|
|
} else if (dd == DS_ERROR_SHRINK) {
|
|
|
|
retcode = ERR_IMPLICIT_SHRINK;
|
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2010-07-06 09:14:00 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_CONNECTED) {
|
2013-06-25 14:50:07 +00:00
|
|
|
if (dd == DS_GREW)
|
2011-07-03 11:26:43 +00:00
|
|
|
set_bit(RESIZE_PENDING, &device->flags);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_send_uuids(device);
|
|
|
|
drbd_send_sizes(device, 1, ddsf);
|
2010-07-06 09:14:00 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 23:07:19 +00:00
|
|
|
fail:
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-09-29 11:00:14 +00:00
|
|
|
fail_ldev:
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-09-29 11:00:14 +00:00
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 13:31:09 +00:00
|
|
|
int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2011-04-27 19:17:33 +00:00
|
|
|
struct res_opts res_opts;
|
2011-03-23 13:31:09 +00:00
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 14:07:32 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto fail;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-21 14:11:28 +00:00
|
|
|
res_opts = adm_ctx.resource->res_opts;
|
2011-04-27 19:09:55 +00:00
|
|
|
if (should_set_defaults(info))
|
2011-05-03 12:56:09 +00:00
|
|
|
set_res_opts_defaults(&res_opts);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-04-27 19:17:33 +00:00
|
|
|
err = res_opts_from_attrs(&res_opts, info);
|
2011-05-24 12:18:31 +00:00
|
|
|
if (err && err != -ENOMSG) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_MANDATORY_TAG;
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
2009-09-25 23:07:19 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-06-21 14:11:28 +00:00
|
|
|
err = set_resource_options(adm_ctx.resource, &res_opts);
|
2011-06-16 15:58:02 +00:00
|
|
|
if (err) {
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
|
|
|
if (err == -ENOMEM)
|
|
|
|
retcode = ERR_NOMEM;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
|
|
|
|
|
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-01-18 09:38:01 +00:00
|
|
|
/* If there is still bitmap IO pending, probably because of a previous
|
2012-06-19 08:27:58 +00:00
|
|
|
* resync just being finished, wait for it before requesting a new resync.
|
|
|
|
* Also wait for it's after_state_ch(). */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags));
|
|
|
|
drbd_flush_workqueue(device);
|
2011-01-18 09:38:01 +00:00
|
|
|
|
2013-03-27 13:08:38 +00:00
|
|
|
/* If we happen to be C_STANDALONE R_SECONDARY, just change to
|
|
|
|
* D_INCONSISTENT, and set all bits in the bitmap. Otherwise,
|
|
|
|
* try to start a resync handshake as sync target for full sync.
|
2013-03-27 13:08:36 +00:00
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_STANDALONE && device->state.role == R_SECONDARY) {
|
|
|
|
retcode = drbd_request_state(device, NS(disk, D_INCONSISTENT));
|
2013-03-27 13:08:38 +00:00
|
|
|
if (retcode >= SS_SUCCESS) {
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_bitmap_io(device, &drbd_bmio_set_n_write,
|
2013-03-27 13:08:38 +00:00
|
|
|
"set_n_write from invalidate", BM_LOCKED_MASK))
|
|
|
|
retcode = ERR_IO_MD_DISK;
|
|
|
|
}
|
|
|
|
} else
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_T));
|
|
|
|
drbd_resume_io(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
static int drbd_adm_simple_request_state(struct sk_buff *skb, struct genl_info *info,
|
|
|
|
union drbd_state mask, union drbd_state val)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2011-01-18 09:38:01 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_request_state(adm_ctx.device, mask, val);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
static int drbd_bmio_set_susp_al(struct drbd_device *device)
|
2010-08-31 10:00:50 +00:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
rv = drbd_bmio_set_n_write(device);
|
|
|
|
drbd_suspend_al(device);
|
2010-08-31 10:00:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2012-02-14 11:12:35 +00:00
|
|
|
int retcode; /* drbd_ret_code, drbd_state_rv */
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2012-02-14 11:12:35 +00:00
|
|
|
|
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-01-18 09:38:01 +00:00
|
|
|
/* If there is still bitmap IO pending, probably because of a previous
|
2012-06-19 08:27:58 +00:00
|
|
|
* resync just being finished, wait for it before requesting a new resync.
|
|
|
|
* Also wait for it's after_state_ch(). */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags));
|
|
|
|
drbd_flush_workqueue(device);
|
2011-01-18 09:38:01 +00:00
|
|
|
|
2013-03-27 13:08:38 +00:00
|
|
|
/* If we happen to be C_STANDALONE R_PRIMARY, just set all bits
|
|
|
|
* in the bitmap. Otherwise, try to start a resync handshake
|
|
|
|
* as sync source for full sync.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn == C_STANDALONE && device->state.role == R_PRIMARY) {
|
2013-03-27 13:08:38 +00:00
|
|
|
/* The peer will get a resync upon connect anyways. Just make that
|
|
|
|
into a full resync. */
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_request_state(device, NS(pdsk, D_INCONSISTENT));
|
2013-03-27 13:08:38 +00:00
|
|
|
if (retcode >= SS_SUCCESS) {
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_bitmap_io(device, &drbd_bmio_set_susp_al,
|
2013-03-27 13:08:38 +00:00
|
|
|
"set_n_write from invalidate_peer",
|
|
|
|
BM_LOCKED_SET_ALLOWED))
|
|
|
|
retcode = ERR_IO_MD_DISK;
|
|
|
|
}
|
|
|
|
} else
|
2011-07-03 11:26:43 +00:00
|
|
|
retcode = drbd_request_state(device, NS(conn, C_STARTING_SYNC_S));
|
|
|
|
drbd_resume_io(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2012-02-14 11:12:35 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_request_state(adm_ctx.device, NS(user_isp, 1)) == SS_NOTHING_TO_DO)
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = ERR_PAUSE_IS_SET;
|
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-29 08:52:01 +00:00
|
|
|
union drbd_dev_state s;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
|
|
|
|
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (drbd_request_state(adm_ctx.device, NS(user_isp, 0)) == SS_NOTHING_TO_DO) {
|
|
|
|
s = adm_ctx.device->state;
|
2011-01-20 10:46:41 +00:00
|
|
|
if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) {
|
|
|
|
retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP :
|
|
|
|
s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR;
|
|
|
|
} else {
|
|
|
|
retcode = ERR_PAUSE_IS_CLEAR;
|
|
|
|
}
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
return drbd_adm_simple_request_state(skb, info, NS(susp, 1));
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
|
|
|
|
|
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
|
|
|
if (test_bit(NEW_CUR_UUID, &device->flags)) {
|
|
|
|
drbd_uuid_new_current(device);
|
|
|
|
clear_bit(NEW_CUR_UUID, &device->flags);
|
2010-06-11 09:26:34 +00:00
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
retcode = drbd_request_state(device, NS3(susp, 0, susp_nod, 0, susp_fen, 0));
|
2011-03-07 11:49:34 +00:00
|
|
|
if (retcode == SS_SUCCESS) {
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.conn < C_CONNECTED)
|
2011-05-31 12:33:49 +00:00
|
|
|
tl_clear(first_peer_device(device)->connection);
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.disk == D_DISKLESS || device->state.disk == D_FAILED)
|
2011-05-31 12:33:49 +00:00
|
|
|
tl_restart(first_peer_device(device)->connection, FAIL_FROZEN_DISK_IO);
|
2010-05-31 08:14:17 +00:00
|
|
|
}
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_resume_io(device);
|
2010-05-31 08:14:17 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED));
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-05 16:23:07 +00:00
|
|
|
static int nla_put_drbd_cfg_context(struct sk_buff *skb,
|
|
|
|
struct drbd_resource *resource,
|
|
|
|
struct drbd_connection *connection,
|
|
|
|
struct drbd_device *device)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-10 21:18:18 +00:00
|
|
|
struct nlattr *nla;
|
|
|
|
nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT);
|
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
2011-07-05 16:23:07 +00:00
|
|
|
if (device &&
|
|
|
|
nla_put_u32(skb, T_ctx_volume, device->vnr))
|
2012-07-11 18:36:03 +00:00
|
|
|
goto nla_put_failure;
|
2011-06-08 20:17:38 +00:00
|
|
|
if (nla_put_string(skb, T_ctx_resource_name, connection->resource->name))
|
2012-07-11 18:36:03 +00:00
|
|
|
goto nla_put_failure;
|
2011-07-05 16:23:07 +00:00
|
|
|
if (connection) {
|
|
|
|
if (connection->my_addr_len &&
|
|
|
|
nla_put(skb, T_ctx_my_addr, connection->my_addr_len, &connection->my_addr))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (connection->peer_addr_len &&
|
|
|
|
nla_put(skb, T_ctx_peer_addr, connection->peer_addr_len, &connection->peer_addr))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
2011-03-10 21:18:18 +00:00
|
|
|
nla_nest_end(skb, nla);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-10 21:18:18 +00:00
|
|
|
nla_put_failure:
|
|
|
|
if (nla)
|
|
|
|
nla_nest_cancel(skb, nla);
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-05 16:23:07 +00:00
|
|
|
/*
|
|
|
|
* Return the connection of @resource if @resource has exactly one connection.
|
|
|
|
*/
|
|
|
|
static struct drbd_connection *the_only_connection(struct drbd_resource *resource)
|
|
|
|
{
|
|
|
|
struct list_head *connections = &resource->connections;
|
|
|
|
|
|
|
|
if (list_empty(connections) || connections->next->next != connections)
|
|
|
|
return NULL;
|
|
|
|
return list_first_entry(&resource->connections, struct drbd_connection, connections);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nla_put_status_info(struct sk_buff *skb, struct drbd_device *device,
|
2011-03-07 11:49:34 +00:00
|
|
|
const struct sib_info *sib)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-05 16:23:07 +00:00
|
|
|
struct drbd_resource *resource = device->resource;
|
2011-03-07 11:49:34 +00:00
|
|
|
struct state_info *si = NULL; /* for sizeof(si->member); */
|
|
|
|
struct nlattr *nla;
|
|
|
|
int got_ldev;
|
|
|
|
int err = 0;
|
|
|
|
int exclude_sensitive;
|
|
|
|
|
|
|
|
/* If sib != NULL, this is drbd_bcast_event, which anyone can listen
|
|
|
|
* to. So we better exclude_sensitive information.
|
|
|
|
*
|
|
|
|
* If sib == NULL, this is drbd_adm_get_status, executed synchronously
|
|
|
|
* in the context of the requesting user process. Exclude sensitive
|
|
|
|
* information, unless current has superuser.
|
|
|
|
*
|
|
|
|
* NOTE: for drbd_adm_get_status_all(), this is a netlink dump, and
|
|
|
|
* relies on the current implementation of netlink_dump(), which
|
|
|
|
* executes the dump callback successively from netlink_recvmsg(),
|
|
|
|
* always in the context of the receiving process */
|
|
|
|
exclude_sensitive = sib || !capable(CAP_SYS_ADMIN);
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
got_ldev = get_ldev(device);
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
/* We need to add connection name and volume number information still.
|
|
|
|
* Minor number is in drbd_genlmsghdr. */
|
2011-07-05 16:23:07 +00:00
|
|
|
if (nla_put_drbd_cfg_context(skb, resource, the_only_connection(resource), device))
|
2011-03-07 11:49:34 +00:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
2011-06-21 14:11:28 +00:00
|
|
|
if (res_opts_to_skb(skb, &device->resource->res_opts, exclude_sensitive))
|
2011-03-23 13:31:09 +00:00
|
|
|
goto nla_put_failure;
|
|
|
|
|
2011-05-03 13:00:55 +00:00
|
|
|
rcu_read_lock();
|
2013-06-25 14:50:05 +00:00
|
|
|
if (got_ldev) {
|
|
|
|
struct disk_conf *disk_conf;
|
2011-04-19 15:10:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
disk_conf = rcu_dereference(device->ldev->disk_conf);
|
2013-06-25 14:50:05 +00:00
|
|
|
err = disk_conf_to_skb(skb, disk_conf, exclude_sensitive);
|
|
|
|
}
|
|
|
|
if (!err) {
|
|
|
|
struct net_conf *nc;
|
|
|
|
|
2011-05-31 12:33:49 +00:00
|
|
|
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
|
2013-06-25 14:50:05 +00:00
|
|
|
if (nc)
|
|
|
|
err = net_conf_to_skb(skb, nc, exclude_sensitive);
|
|
|
|
}
|
2011-04-19 15:10:19 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
if (err)
|
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
nla = nla_nest_start(skb, DRBD_NLA_STATE_INFO);
|
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
2012-07-11 18:36:03 +00:00
|
|
|
if (nla_put_u32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY) ||
|
2011-07-03 11:26:43 +00:00
|
|
|
nla_put_u32(skb, T_current_state, device->state.i) ||
|
|
|
|
nla_put_u64(skb, T_ed_uuid, device->ed_uuid) ||
|
|
|
|
nla_put_u64(skb, T_capacity, drbd_get_capacity(device->this_bdev)) ||
|
|
|
|
nla_put_u64(skb, T_send_cnt, device->send_cnt) ||
|
|
|
|
nla_put_u64(skb, T_recv_cnt, device->recv_cnt) ||
|
|
|
|
nla_put_u64(skb, T_read_cnt, device->read_cnt) ||
|
|
|
|
nla_put_u64(skb, T_writ_cnt, device->writ_cnt) ||
|
|
|
|
nla_put_u64(skb, T_al_writ_cnt, device->al_writ_cnt) ||
|
|
|
|
nla_put_u64(skb, T_bm_writ_cnt, device->bm_writ_cnt) ||
|
|
|
|
nla_put_u32(skb, T_ap_bio_cnt, atomic_read(&device->ap_bio_cnt)) ||
|
|
|
|
nla_put_u32(skb, T_ap_pending_cnt, atomic_read(&device->ap_pending_cnt)) ||
|
|
|
|
nla_put_u32(skb, T_rs_pending_cnt, atomic_read(&device->rs_pending_cnt)))
|
2012-07-11 18:36:03 +00:00
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
|
|
|
|
if (got_ldev) {
|
2012-08-08 19:19:09 +00:00
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
spin_lock_irq(&device->ldev->md.uuid_lock);
|
|
|
|
err = nla_put(skb, T_uuids, sizeof(si->uuids), device->ldev->md.uuid);
|
|
|
|
spin_unlock_irq(&device->ldev->md.uuid_lock);
|
2012-08-08 19:19:09 +00:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (nla_put_u32(skb, T_disk_flags, device->ldev->md.flags) ||
|
|
|
|
nla_put_u64(skb, T_bits_total, drbd_bm_bits(device)) ||
|
|
|
|
nla_put_u64(skb, T_bits_oos, drbd_bm_total_weight(device)))
|
2012-07-11 18:36:03 +00:00
|
|
|
goto nla_put_failure;
|
2011-07-03 11:26:43 +00:00
|
|
|
if (C_SYNC_SOURCE <= device->state.conn &&
|
|
|
|
C_PAUSED_SYNC_T >= device->state.conn) {
|
|
|
|
if (nla_put_u64(skb, T_bits_rs_total, device->rs_total) ||
|
|
|
|
nla_put_u64(skb, T_bits_rs_failed, device->rs_failed))
|
2012-07-11 18:36:03 +00:00
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
if (sib) {
|
|
|
|
switch(sib->sib_reason) {
|
|
|
|
case SIB_SYNC_PROGRESS:
|
|
|
|
case SIB_GET_STATUS_REPLY:
|
|
|
|
break;
|
|
|
|
case SIB_STATE_CHANGE:
|
2012-07-11 18:36:03 +00:00
|
|
|
if (nla_put_u32(skb, T_prev_state, sib->os.i) ||
|
|
|
|
nla_put_u32(skb, T_new_state, sib->ns.i))
|
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
break;
|
|
|
|
case SIB_HELPER_POST:
|
2012-07-11 18:36:03 +00:00
|
|
|
if (nla_put_u32(skb, T_helper_exit_code,
|
|
|
|
sib->helper_exit_code))
|
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
/* fall through */
|
|
|
|
case SIB_HELPER_PRE:
|
2012-07-11 18:36:03 +00:00
|
|
|
if (nla_put_string(skb, T_helper, sib->helper_name))
|
|
|
|
goto nla_put_failure;
|
2011-03-07 11:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
nla_nest_end(skb, nla);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
if (0)
|
|
|
|
nla_put_failure:
|
|
|
|
err = -EMSGSIZE;
|
|
|
|
if (got_ldev)
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2011-03-07 11:49:34 +00:00
|
|
|
return err;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.device, NULL);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
|
|
|
nlmsg_free(adm_ctx.reply_skb);
|
|
|
|
return err;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 09:47:33 +00:00
|
|
|
static int get_one_status(struct sk_buff *skb, struct netlink_callback *cb)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
struct drbd_genlmsghdr *dh;
|
2011-06-08 20:17:38 +00:00
|
|
|
struct drbd_resource *pos = (struct drbd_resource *)cb->args[0];
|
|
|
|
struct drbd_resource *resource = NULL;
|
|
|
|
struct drbd_resource *tmp;
|
2011-03-10 21:18:18 +00:00
|
|
|
unsigned volume = cb->args[1];
|
|
|
|
|
|
|
|
/* Open coded, deferred, iteration:
|
2011-06-08 20:17:38 +00:00
|
|
|
* for_each_resource_safe(resource, tmp, &drbd_resources) {
|
2011-07-05 16:23:07 +00:00
|
|
|
* connection = "first connection of resource or undefined";
|
|
|
|
* idr_for_each_entry(&resource->devices, device, i) {
|
2011-03-10 21:18:18 +00:00
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
* }
|
2011-06-08 20:17:38 +00:00
|
|
|
* where resource is cb->args[0];
|
2011-03-10 21:18:18 +00:00
|
|
|
* and i is cb->args[1];
|
|
|
|
*
|
2011-04-18 07:43:25 +00:00
|
|
|
* cb->args[2] indicates if we shall loop over all resources,
|
|
|
|
* or just dump all volumes of a single resource.
|
|
|
|
*
|
2011-03-07 11:49:34 +00:00
|
|
|
* This may miss entries inserted after this dump started,
|
|
|
|
* or entries deleted before they are reached.
|
2011-03-10 21:18:18 +00:00
|
|
|
*
|
2011-07-03 11:26:43 +00:00
|
|
|
* We need to make sure the device won't disappear while
|
2011-03-10 21:18:18 +00:00
|
|
|
* we are looking at it, and revalidate our iterators
|
|
|
|
* on each iteration.
|
|
|
|
*/
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
/* synchronize with conn_create()/drbd_destroy_connection() */
|
2011-05-05 14:13:10 +00:00
|
|
|
rcu_read_lock();
|
2011-03-10 21:18:18 +00:00
|
|
|
/* revalidate iterator position */
|
2011-06-08 20:17:38 +00:00
|
|
|
for_each_resource_rcu(tmp, &drbd_resources) {
|
2011-03-10 21:18:18 +00:00
|
|
|
if (pos == NULL) {
|
|
|
|
/* first iteration */
|
|
|
|
pos = tmp;
|
2011-06-08 20:17:38 +00:00
|
|
|
resource = pos;
|
2011-03-10 21:18:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tmp == pos) {
|
2011-06-08 20:17:38 +00:00
|
|
|
resource = pos;
|
2011-03-10 21:18:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-06-08 20:17:38 +00:00
|
|
|
if (resource) {
|
|
|
|
next_resource:
|
2011-07-05 16:23:07 +00:00
|
|
|
device = idr_get_next(&resource->devices, &volume);
|
|
|
|
if (!device) {
|
2011-06-08 20:17:38 +00:00
|
|
|
/* No more volumes to dump on this resource.
|
|
|
|
* Advance resource iterator. */
|
|
|
|
pos = list_entry_rcu(resource->resources.next,
|
|
|
|
struct drbd_resource, resources);
|
|
|
|
/* Did we dump any volume of this resource yet? */
|
2011-03-10 21:18:18 +00:00
|
|
|
if (volume != 0) {
|
2011-04-18 07:43:25 +00:00
|
|
|
/* If we reached the end of the list,
|
|
|
|
* or only a single resource dump was requested,
|
|
|
|
* we are done. */
|
2011-06-08 20:17:38 +00:00
|
|
|
if (&pos->resources == &drbd_resources || cb->args[2])
|
2011-04-18 07:43:25 +00:00
|
|
|
goto out;
|
2011-03-10 21:18:18 +00:00
|
|
|
volume = 0;
|
2011-06-08 20:17:38 +00:00
|
|
|
resource = pos;
|
|
|
|
goto next_resource;
|
2011-03-10 21:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-09 13:18:43 +00:00
|
|
|
dh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
|
2011-03-07 11:49:34 +00:00
|
|
|
cb->nlh->nlmsg_seq, &drbd_genl_family,
|
|
|
|
NLM_F_MULTI, DRBD_ADM_GET_STATUS);
|
|
|
|
if (!dh)
|
2011-03-10 21:18:18 +00:00
|
|
|
goto out;
|
|
|
|
|
2011-07-05 16:23:07 +00:00
|
|
|
if (!device) {
|
2011-05-30 14:32:41 +00:00
|
|
|
/* This is a connection without a single volume.
|
2011-07-11 21:49:55 +00:00
|
|
|
* Suprisingly enough, it may have a network
|
|
|
|
* configuration. */
|
2011-07-05 16:23:07 +00:00
|
|
|
struct drbd_connection *connection;
|
|
|
|
|
2011-03-10 21:18:18 +00:00
|
|
|
dh->minor = -1U;
|
|
|
|
dh->ret_code = NO_ERROR;
|
2011-07-05 16:23:07 +00:00
|
|
|
connection = the_only_connection(resource);
|
|
|
|
if (nla_put_drbd_cfg_context(skb, resource, connection, NULL))
|
2011-07-11 21:49:55 +00:00
|
|
|
goto cancel;
|
2011-07-05 16:23:07 +00:00
|
|
|
if (connection) {
|
|
|
|
struct net_conf *nc;
|
|
|
|
|
|
|
|
nc = rcu_dereference(connection->net_conf);
|
|
|
|
if (nc && net_conf_to_skb(skb, nc, 1) != 0)
|
|
|
|
goto cancel;
|
|
|
|
}
|
2011-07-11 21:49:55 +00:00
|
|
|
goto done;
|
2011-03-10 21:18:18 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-27 14:23:33 +00:00
|
|
|
D_ASSERT(device, device->vnr == volume);
|
2011-07-05 16:23:07 +00:00
|
|
|
D_ASSERT(device, device->resource == resource);
|
2011-03-07 11:49:34 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
dh->minor = device_to_minor(device);
|
2011-03-07 11:49:34 +00:00
|
|
|
dh->ret_code = NO_ERROR;
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (nla_put_status_info(skb, device, NULL)) {
|
2011-07-11 21:49:55 +00:00
|
|
|
cancel:
|
2011-03-07 11:49:34 +00:00
|
|
|
genlmsg_cancel(skb, dh);
|
2011-03-10 21:18:18 +00:00
|
|
|
goto out;
|
2011-03-07 11:49:34 +00:00
|
|
|
}
|
2011-07-11 21:49:55 +00:00
|
|
|
done:
|
2011-03-07 11:49:34 +00:00
|
|
|
genlmsg_end(skb, dh);
|
2011-05-30 14:32:41 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-10 21:18:18 +00:00
|
|
|
out:
|
2011-05-05 14:13:10 +00:00
|
|
|
rcu_read_unlock();
|
2011-03-10 21:18:18 +00:00
|
|
|
/* where to start the next iteration */
|
2011-05-30 14:32:41 +00:00
|
|
|
cb->args[0] = (long)pos;
|
2011-06-08 20:17:38 +00:00
|
|
|
cb->args[1] = (pos == resource) ? volume + 1 : 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-08 20:17:38 +00:00
|
|
|
/* No more resources/volumes/minors found results in an empty skb.
|
2011-03-10 21:18:18 +00:00
|
|
|
* Which will terminate the dump. */
|
2011-03-07 11:49:34 +00:00
|
|
|
return skb->len;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 07:43:25 +00:00
|
|
|
/*
|
|
|
|
* Request status of all resources, or of all volumes within a single resource.
|
|
|
|
*
|
|
|
|
* This is a dump, as the answer may not fit in a single reply skb otherwise.
|
|
|
|
* Which means we cannot use the family->attrbuf or other such members, because
|
|
|
|
* dump is NOT protected by the genl_lock(). During dump, we only have access
|
|
|
|
* to the incoming skb, and need to opencode "parsing" of the nlattr payload.
|
|
|
|
*
|
|
|
|
* Once things are setup properly, we call into get_one_status().
|
2009-09-25 23:07:19 +00:00
|
|
|
*/
|
2011-04-18 07:43:25 +00:00
|
|
|
int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-04-18 07:43:25 +00:00
|
|
|
const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
|
|
|
|
struct nlattr *nla;
|
2011-06-09 15:52:12 +00:00
|
|
|
const char *resource_name;
|
2011-06-13 12:27:45 +00:00
|
|
|
struct drbd_resource *resource;
|
2011-06-09 15:52:12 +00:00
|
|
|
int maxtype;
|
2011-04-18 07:43:25 +00:00
|
|
|
|
|
|
|
/* Is this a followup call? */
|
|
|
|
if (cb->args[0]) {
|
|
|
|
/* ... of a single resource dump,
|
|
|
|
* and the resource iterator has been advanced already? */
|
|
|
|
if (cb->args[2] && cb->args[2] != cb->args[0])
|
|
|
|
return 0; /* DONE. */
|
|
|
|
goto dump;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First call (from netlink_dump_start). We need to figure out
|
|
|
|
* which resource(s) the user wants us to dump. */
|
|
|
|
nla = nla_find(nlmsg_attrdata(cb->nlh, hdrlen),
|
|
|
|
nlmsg_attrlen(cb->nlh, hdrlen),
|
|
|
|
DRBD_NLA_CFG_CONTEXT);
|
|
|
|
|
|
|
|
/* No explicit context given. Dump all. */
|
|
|
|
if (!nla)
|
|
|
|
goto dump;
|
2011-06-09 15:52:12 +00:00
|
|
|
maxtype = ARRAY_SIZE(drbd_cfg_context_nl_policy) - 1;
|
|
|
|
nla = drbd_nla_find_nested(maxtype, nla, __nla_type(T_ctx_resource_name));
|
|
|
|
if (IS_ERR(nla))
|
|
|
|
return PTR_ERR(nla);
|
2011-04-18 07:43:25 +00:00
|
|
|
/* context given, but no name present? */
|
|
|
|
if (!nla)
|
|
|
|
return -EINVAL;
|
2011-06-09 15:52:12 +00:00
|
|
|
resource_name = nla_data(nla);
|
2011-06-13 12:27:45 +00:00
|
|
|
if (!*resource_name)
|
|
|
|
return -ENODEV;
|
|
|
|
resource = drbd_find_resource(resource_name);
|
|
|
|
if (!resource)
|
2011-04-18 07:43:25 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2011-06-13 12:27:45 +00:00
|
|
|
kref_put(&resource->kref, drbd_destroy_resource); /* get_one_status() revalidates the resource */
|
2011-04-24 08:53:19 +00:00
|
|
|
|
2011-04-18 07:43:25 +00:00
|
|
|
/* prime iterators, and set "filter" mode mark:
|
2011-05-30 14:32:41 +00:00
|
|
|
* only dump this connection. */
|
2011-06-13 12:27:45 +00:00
|
|
|
cb->args[0] = (long)resource;
|
2011-04-18 07:43:25 +00:00
|
|
|
/* cb->args[1] = 0; passed in this way. */
|
2011-06-13 12:27:45 +00:00
|
|
|
cb->args[2] = (long)resource;
|
2011-04-18 07:43:25 +00:00
|
|
|
|
|
|
|
dump:
|
|
|
|
return get_one_status(skb, cb);
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
|
|
|
struct timeout_parms tp;
|
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
tp.timeout_type =
|
2011-07-03 11:26:43 +00:00
|
|
|
adm_ctx.device->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED :
|
|
|
|
test_bit(USE_DEGR_WFC_T, &adm_ctx.device->flags) ? UT_DEGRADED :
|
2011-03-07 11:49:34 +00:00
|
|
|
UT_DEFAULT;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp);
|
|
|
|
if (err) {
|
|
|
|
nlmsg_free(adm_ctx.reply_skb);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2012-07-26 12:09:49 +00:00
|
|
|
struct start_ov_parms parms;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2011-01-21 21:53:48 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2012-07-26 12:09:49 +00:00
|
|
|
|
|
|
|
/* resume from last known position, if possible */
|
2011-07-03 11:26:43 +00:00
|
|
|
parms.ov_start_sector = device->ov_start_sector;
|
2012-07-26 12:09:49 +00:00
|
|
|
parms.ov_stop_sector = ULLONG_MAX;
|
2011-03-07 11:49:34 +00:00
|
|
|
if (info->attrs[DRBD_NLA_START_OV_PARMS]) {
|
2011-03-23 13:31:09 +00:00
|
|
|
int err = start_ov_parms_from_attrs(&parms, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2012-07-26 12:09:49 +00:00
|
|
|
/* w_make_ov_request expects position to be aligned */
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ov_start_sector = parms.ov_start_sector & ~(BM_SECT_PER_BIT-1);
|
|
|
|
device->ov_stop_sector = parms.ov_stop_sector;
|
2011-01-21 21:53:48 +00:00
|
|
|
|
|
|
|
/* If there is still bitmap IO pending, e.g. previous resync or verify
|
|
|
|
* just being finished, wait for it before requesting a new resync. */
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_suspend_io(device);
|
|
|
|
wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags));
|
|
|
|
retcode = drbd_request_state(device, NS(conn, C_VERIFY_S));
|
|
|
|
drbd_resume_io(device);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
struct drbd_device *device;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
int skip_initial_sync = 0;
|
|
|
|
int err;
|
2011-03-07 11:49:34 +00:00
|
|
|
struct new_c_uuid_parms args;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out_nolock;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
device = adm_ctx.device;
|
2011-03-07 11:49:34 +00:00
|
|
|
memset(&args, 0, sizeof(args));
|
|
|
|
if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) {
|
2011-03-23 13:31:09 +00:00
|
|
|
err = new_c_uuid_parms_from_attrs(&args, info);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (err) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto out_nolock;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
mutex_lock(device->state_mutex); /* Protects us against serialized state changes. */
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (!get_ldev(device)) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NO_DISK;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is "skip initial sync", assume to be clean */
|
2011-05-31 12:33:49 +00:00
|
|
|
if (device->state.conn == C_CONNECTED &&
|
|
|
|
first_peer_device(device)->connection->agreed_pro_version >= 90 &&
|
2011-07-03 11:26:43 +00:00
|
|
|
device->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_info(device, "Preparing to skip initial sync\n");
|
2009-09-25 23:07:19 +00:00
|
|
|
skip_initial_sync = 1;
|
2011-07-03 11:26:43 +00:00
|
|
|
} else if (device->state.conn != C_STANDALONE) {
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_CONNECTED;
|
|
|
|
goto out_dec;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_uuid_set(device, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */
|
|
|
|
drbd_uuid_new_current(device); /* New current, previous to UI_BITMAP */
|
2009-09-25 23:07:19 +00:00
|
|
|
|
|
|
|
if (args.clear_bm) {
|
2011-07-03 11:26:43 +00:00
|
|
|
err = drbd_bitmap_io(device, &drbd_bmio_clear_n_write,
|
2011-01-21 09:56:44 +00:00
|
|
|
"clear_n_write from new_c_uuid", BM_LOCKED_MASK);
|
2009-09-25 23:07:19 +00:00
|
|
|
if (err) {
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Writing bitmap failed with %d\n", err);
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_IO_MD_DISK;
|
|
|
|
}
|
|
|
|
if (skip_initial_sync) {
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_send_uuids_skip_initial_sync(device);
|
|
|
|
_drbd_uuid_set(device, UI_BITMAP, 0);
|
|
|
|
drbd_print_uuids(device, "cleared bitmap UUID");
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_lock_irq(&device->resource->req_lock);
|
2011-07-03 11:26:43 +00:00
|
|
|
_drbd_set_state(_NS2(device, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE),
|
2009-09-25 23:07:19 +00:00
|
|
|
CS_VERBOSE, NULL);
|
2011-07-07 12:19:42 +00:00
|
|
|
spin_unlock_irq(&device->resource->req_lock);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
drbd_md_sync(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
out_dec:
|
2011-07-03 11:26:43 +00:00
|
|
|
put_ldev(device);
|
2009-09-25 23:07:19 +00:00
|
|
|
out:
|
2011-07-03 11:26:43 +00:00
|
|
|
mutex_unlock(device->state_mutex);
|
2011-03-07 11:49:34 +00:00
|
|
|
out_nolock:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
static enum drbd_ret_code
|
2011-06-09 15:52:12 +00:00
|
|
|
drbd_check_resource_name(const char *name)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!name || !name[0]) {
|
2011-06-09 15:52:12 +00:00
|
|
|
drbd_msg_put_info("resource name missing");
|
2011-03-07 11:49:34 +00:00
|
|
|
return ERR_MANDATORY_TAG;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
/* if we want to use these in sysfs/configfs/debugfs some day,
|
|
|
|
* we must not allow slashes */
|
|
|
|
if (strchr(name, '/')) {
|
2011-06-09 15:52:12 +00:00
|
|
|
drbd_msg_put_info("invalid resource name");
|
2011-03-07 11:49:34 +00:00
|
|
|
return ERR_INVALID_REQUEST;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-07 11:49:34 +00:00
|
|
|
return NO_ERROR;
|
2011-02-22 07:07:03 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-06 14:16:44 +00:00
|
|
|
int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2011-06-16 15:58:02 +00:00
|
|
|
struct res_opts res_opts;
|
|
|
|
int err;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, 0);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-16 15:58:02 +00:00
|
|
|
set_res_opts_defaults(&res_opts);
|
|
|
|
err = res_opts_from_attrs(&res_opts, info);
|
|
|
|
if (err && err != -ENOMSG) {
|
|
|
|
retcode = ERR_MANDATORY_TAG;
|
|
|
|
drbd_msg_put_info(from_attrs_err_to_txt(err));
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 15:52:12 +00:00
|
|
|
retcode = drbd_check_resource_name(adm_ctx.resource_name);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-05 16:26:00 +00:00
|
|
|
if (adm_ctx.resource) {
|
2011-03-14 12:22:35 +00:00
|
|
|
if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) {
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
2011-06-06 14:16:44 +00:00
|
|
|
drbd_msg_put_info("resource exists");
|
2011-03-14 12:22:35 +00:00
|
|
|
}
|
|
|
|
/* else: still NO_ERROR */
|
2011-03-07 11:49:34 +00:00
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-16 15:58:02 +00:00
|
|
|
if (!conn_create(adm_ctx.resource_name, &res_opts))
|
2009-09-25 23:07:19 +00:00
|
|
|
retcode = ERR_NOMEM;
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
int drbd_adm_new_minor(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
struct drbd_genlmsghdr *dh = info->userhdr;
|
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 14:07:32 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-14 14:00:40 +00:00
|
|
|
if (dh->minor > MINORMASK) {
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info("requested minor out of range");
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-30 14:00:17 +00:00
|
|
|
if (adm_ctx.volume > DRBD_VOLUME_MAX) {
|
2011-03-07 11:49:34 +00:00
|
|
|
drbd_msg_put_info("requested volume id out of range");
|
|
|
|
retcode = ERR_INVALID_REQUEST;
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 12:22:35 +00:00
|
|
|
/* drbd_adm_prepare made sure already
|
2011-05-31 12:33:49 +00:00
|
|
|
* that first_peer_device(device)->connection and device->vnr match the request. */
|
2011-07-03 11:26:43 +00:00
|
|
|
if (adm_ctx.device) {
|
2011-03-14 12:22:35 +00:00
|
|
|
if (info->nlhdr->nlmsg_flags & NLM_F_EXCL)
|
|
|
|
retcode = ERR_MINOR_EXISTS;
|
|
|
|
/* else: still NO_ERROR */
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
2011-03-14 12:22:35 +00:00
|
|
|
|
2011-07-06 12:20:49 +00:00
|
|
|
retcode = drbd_create_device(adm_ctx.resource, dh->minor, adm_ctx.volume);
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
static enum drbd_ret_code adm_del_minor(struct drbd_device *device)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-03 11:26:43 +00:00
|
|
|
if (device->state.disk == D_DISKLESS &&
|
|
|
|
/* no need to be device->state.conn == C_STANDALONE &&
|
2011-03-15 15:26:37 +00:00
|
|
|
* we may want to delete a minor from a live replication group.
|
|
|
|
*/
|
2011-07-03 11:26:43 +00:00
|
|
|
device->state.role == R_SECONDARY) {
|
|
|
|
_drbd_request_state(device, NS(conn, C_WF_REPORT_PARAMS),
|
2011-07-06 21:04:44 +00:00
|
|
|
CS_VERBOSE + CS_WAIT_COMPLETE);
|
2011-07-03 21:32:26 +00:00
|
|
|
drbd_delete_device(device);
|
2011-03-15 15:26:37 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} else
|
|
|
|
return ERR_MINOR_CONFIGURED;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
int drbd_adm_del_minor(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
|
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-07 20:54:17 +00:00
|
|
|
retcode = adm_del_minor(adm_ctx.device);
|
2011-03-15 15:26:37 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 15:26:37 +00:00
|
|
|
int drbd_adm_down(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-07-06 13:03:31 +00:00
|
|
|
struct drbd_resource *resource;
|
|
|
|
struct drbd_connection *connection;
|
|
|
|
struct drbd_device *device;
|
2011-05-02 08:45:05 +00:00
|
|
|
int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
|
2011-03-15 15:26:37 +00:00
|
|
|
unsigned i;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-08 23:26:16 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
|
2011-03-15 15:26:37 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 13:03:31 +00:00
|
|
|
resource = adm_ctx.resource;
|
2011-03-15 15:26:37 +00:00
|
|
|
/* demote */
|
2011-07-06 13:03:31 +00:00
|
|
|
for_each_connection(connection, resource) {
|
|
|
|
struct drbd_peer_device *peer_device;
|
|
|
|
|
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, i) {
|
|
|
|
retcode = drbd_set_role(peer_device->device, R_SECONDARY, 0);
|
|
|
|
if (retcode < SS_SUCCESS) {
|
|
|
|
drbd_msg_put_info("failed to demote");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retcode = conn_try_disconnect(connection, 0);
|
2011-03-15 15:26:37 +00:00
|
|
|
if (retcode < SS_SUCCESS) {
|
2011-07-06 13:03:31 +00:00
|
|
|
drbd_msg_put_info("failed to disconnect");
|
2011-05-05 14:13:10 +00:00
|
|
|
goto out;
|
2011-03-15 15:26:37 +00:00
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 15:26:37 +00:00
|
|
|
/* detach */
|
2011-07-06 13:03:31 +00:00
|
|
|
idr_for_each_entry(&resource->devices, device, i) {
|
|
|
|
retcode = adm_detach(device, 0);
|
2012-07-24 08:13:55 +00:00
|
|
|
if (retcode < SS_SUCCESS || retcode > NO_ERROR) {
|
2011-03-15 15:26:37 +00:00
|
|
|
drbd_msg_put_info("failed to detach");
|
2011-05-05 14:13:10 +00:00
|
|
|
goto out;
|
2011-03-15 15:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-30 14:32:41 +00:00
|
|
|
/* If we reach this, all volumes (of this connection) are Secondary,
|
2011-05-02 08:45:05 +00:00
|
|
|
* Disconnected, Diskless, aka Unconfigured. Make sure all threads have
|
2011-05-05 14:13:10 +00:00
|
|
|
* actually stopped, state handling only does drbd_thread_stop_nowait(). */
|
2011-07-06 13:03:31 +00:00
|
|
|
for_each_connection(connection, resource)
|
|
|
|
drbd_thread_stop(&connection->worker);
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-05-02 08:45:05 +00:00
|
|
|
/* Now, nothing can fail anymore */
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-15 15:26:37 +00:00
|
|
|
/* delete volumes */
|
2011-07-06 13:03:31 +00:00
|
|
|
idr_for_each_entry(&resource->devices, device, i) {
|
|
|
|
retcode = adm_del_minor(device);
|
2011-03-15 15:26:37 +00:00
|
|
|
if (retcode != NO_ERROR) {
|
|
|
|
/* "can not happen" */
|
|
|
|
drbd_msg_put_info("failed to delete volume");
|
2011-04-13 21:21:29 +00:00
|
|
|
goto out;
|
2011-03-15 15:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-07-06 13:03:31 +00:00
|
|
|
list_del_rcu(&resource->resources);
|
|
|
|
synchronize_rcu();
|
|
|
|
drbd_free_resource(resource);
|
|
|
|
retcode = NO_ERROR;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
|
|
|
return 0;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 14:16:44 +00:00
|
|
|
int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-06-08 20:17:38 +00:00
|
|
|
struct drbd_resource *resource;
|
|
|
|
struct drbd_connection *connection;
|
2011-03-07 11:49:34 +00:00
|
|
|
enum drbd_ret_code retcode;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-14 14:07:32 +00:00
|
|
|
retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
|
2011-03-07 11:49:34 +00:00
|
|
|
if (!adm_ctx.reply_skb)
|
|
|
|
return retcode;
|
|
|
|
if (retcode != NO_ERROR)
|
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-06-08 20:17:38 +00:00
|
|
|
resource = adm_ctx.resource;
|
|
|
|
for_each_connection(connection, resource) {
|
|
|
|
if (connection->cstate > C_STANDALONE) {
|
|
|
|
retcode = ERR_NET_CONFIGURED;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!idr_is_empty(&resource->devices)) {
|
2011-06-06 14:16:44 +00:00
|
|
|
retcode = ERR_RES_IN_USE;
|
2011-06-08 20:17:38 +00:00
|
|
|
goto out;
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 20:17:38 +00:00
|
|
|
list_del_rcu(&resource->resources);
|
|
|
|
for_each_connection(connection, resource)
|
|
|
|
drbd_thread_stop(&connection->worker);
|
|
|
|
synchronize_rcu();
|
|
|
|
drbd_free_resource(resource);
|
|
|
|
retcode = NO_ERROR;
|
2011-03-07 11:49:34 +00:00
|
|
|
out:
|
|
|
|
drbd_adm_finish(info, retcode);
|
2009-09-25 23:07:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
|
2009-09-25 23:07:19 +00:00
|
|
|
{
|
2011-03-07 11:49:34 +00:00
|
|
|
static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
|
|
|
|
struct sk_buff *msg;
|
|
|
|
struct drbd_genlmsghdr *d_out;
|
|
|
|
unsigned seq;
|
|
|
|
int err = -ENOMEM;
|
|
|
|
|
2012-12-06 09:34:34 +00:00
|
|
|
if (sib->sib_reason == SIB_SYNC_PROGRESS) {
|
2011-07-03 11:26:43 +00:00
|
|
|
if (time_after(jiffies, device->rs_last_bcast + HZ))
|
|
|
|
device->rs_last_bcast = jiffies;
|
2012-12-06 09:34:34 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
seq = atomic_inc_return(&drbd_genl_seq);
|
|
|
|
msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
|
|
|
|
if (!msg)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
err = -EMSGSIZE;
|
|
|
|
d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT);
|
|
|
|
if (!d_out) /* cannot happen, but anyways. */
|
|
|
|
goto nla_put_failure;
|
2011-07-03 11:26:43 +00:00
|
|
|
d_out->minor = device_to_minor(device);
|
2011-05-05 23:03:32 +00:00
|
|
|
d_out->ret_code = NO_ERROR;
|
2011-03-07 11:49:34 +00:00
|
|
|
|
2011-07-03 11:26:43 +00:00
|
|
|
if (nla_put_status_info(msg, device, sib))
|
2011-03-07 11:49:34 +00:00
|
|
|
goto nla_put_failure;
|
|
|
|
genlmsg_end(msg, d_out);
|
|
|
|
err = drbd_genl_multicast_events(msg, 0);
|
|
|
|
/* msg has been consumed or freed in netlink_broadcast() */
|
|
|
|
if (err && err != -ESRCH)
|
|
|
|
goto failed;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
return;
|
2009-09-25 23:07:19 +00:00
|
|
|
|
2011-03-07 11:49:34 +00:00
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
failed:
|
2011-07-03 15:53:52 +00:00
|
|
|
drbd_err(device, "Error %d while broadcasting event. "
|
2011-03-07 11:49:34 +00:00
|
|
|
"Event seq:%u sib_reason:%u\n",
|
|
|
|
err, seq, sib->sib_reason);
|
2009-09-25 23:07:19 +00:00
|
|
|
}
|