mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
rbd-nbd: generate and send device cookie with netlink connect request
[root@linux-vm1]# rbd-nbd map rbd-pool/image0 --try-netlink /dev/nbd0 [root@linux-vm1]# cat /sys/block/nbd0/backend c704cb91-c6cf-466e-a335-0e935c0d5e47 Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
parent
8a4649e651
commit
eee8d8a32e
@ -35,6 +35,7 @@ enum {
|
||||
NBD_ATTR_SOCKETS,
|
||||
NBD_ATTR_DEAD_CONN_TIMEOUT,
|
||||
NBD_ATTR_DEVICE_LIST,
|
||||
NBD_ATTR_BACKEND_IDENTIFIER,
|
||||
__NBD_ATTR_MAX,
|
||||
};
|
||||
#define NBD_ATTR_MAX (__NBD_ATTR_MAX - 1)
|
||||
|
@ -123,6 +123,7 @@ struct Config {
|
||||
|
||||
Command command = None;
|
||||
int pid = 0;
|
||||
std::string cookie;
|
||||
|
||||
std::string image_spec() const {
|
||||
std::string spec = poolname + "/";
|
||||
@ -1325,6 +1326,8 @@ static int netlink_connect(Config *cfg, struct nl_sock *sock, int nl_id, int fd,
|
||||
NLA_PUT_U64(msg, NBD_ATTR_BLOCK_SIZE_BYTES, RBD_NBD_BLKSIZE);
|
||||
NLA_PUT_U64(msg, NBD_ATTR_SERVER_FLAGS, flags);
|
||||
NLA_PUT_U64(msg, NBD_ATTR_DEAD_CONN_TIMEOUT, cfg->reattach_timeout);
|
||||
if (!cfg->cookie.empty())
|
||||
NLA_PUT_STRING(msg, NBD_ATTR_BACKEND_IDENTIFIER, cfg->cookie.c_str());
|
||||
|
||||
sock_attr = nla_nest_start(msg, NBD_ATTR_SOCKETS);
|
||||
if (!sock_attr) {
|
||||
@ -1719,6 +1722,11 @@ static int do_map(int argc, const char *argv[], Config *cfg, bool reconnect)
|
||||
|
||||
use_netlink = cfg->try_netlink || reconnect;
|
||||
if (use_netlink) {
|
||||
if (!reconnect) {
|
||||
uuid_d uuid_gen;
|
||||
uuid_gen.generate_random();
|
||||
cfg->cookie = uuid_gen.to_string();
|
||||
}
|
||||
r = try_netlink_setup(cfg, fd[0], size, flags, reconnect);
|
||||
if (r < 0) {
|
||||
goto free_server;
|
||||
|
Loading…
Reference in New Issue
Block a user