rbd-nbd: show per device cookie with list command

[root@linux-vm1]# rbd-nbd list-mapped
id    pool      namespace  image   snap  device     cookie
8133  rbd-pool             image0  -     /dev/nbd0  c704cb91-c6cf-466e-a335-0e935c0d5e47

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2021-05-13 12:39:25 +05:30
parent 6ca70ee4f0
commit efeb255d10

View File

@ -803,6 +803,7 @@ public:
continue;
}
ifs >> pid;
ifs.close();
// If the rbd-nbd is re-attached the pid may store garbage
// here. We are sure this is the case when it is negative or
@ -907,6 +908,7 @@ private:
c.devpath = cfg->devpath;
}
c.cookie = get_cookie(cfg->devpath);
*cfg = c;
return 0;
}
@ -1935,6 +1937,7 @@ static int do_list_mapped_devices(const std::string &format, bool pretty_format)
tbl.define_column("image", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("snap", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("device", TextTable::LEFT, TextTable::LEFT);
tbl.define_column("cookie", TextTable::LEFT, TextTable::LEFT);
}
Config cfg;
@ -1948,6 +1951,7 @@ static int do_list_mapped_devices(const std::string &format, bool pretty_format)
f->dump_string("image", cfg.imgname);
f->dump_string("snap", cfg.snapname);
f->dump_string("device", cfg.devpath);
f->dump_string("cookie", cfg.cookie);
f->close_section();
} else {
should_print = true;
@ -1955,7 +1959,7 @@ static int do_list_mapped_devices(const std::string &format, bool pretty_format)
cfg.snapname = "-";
}
tbl << cfg.pid << cfg.poolname << cfg.nsname << cfg.imgname
<< cfg.snapname << cfg.devpath << TextTable::endrow;
<< cfg.snapname << cfg.devpath << cfg.cookie << TextTable::endrow;
}
}