From: Li Wang Date: Wed, 1 Nov 2017 06:31:10 +0000 (+0000) Subject: rbd-nbd: not abort in listing mapped nbd devices X-Git-Tag: v12.2.3~124^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=210b826ff06fd145f730e2b5303e6472d82fd8e5;p=ceph.git rbd-nbd: not abort in listing mapped nbd devices In some container scenarios, the file '/sys/block/nbd0/pid' in the container records the host pid of the process which opened the device, therefore the file '/proc/pid/cmdline' corresponding to the pid in the container does not exist, in that case, 'rbd-nbd list-mapped' will cause the following assertion failure, this patch fixes it. src/tools/rbd_nbd/rbd-nbd.cc: In function 'int get_mapped_info(int, Config*)' /src/tools/rbd_nbd/rbd-nbd.cc: 834: FAILED assert(ifs.is_open()) ceph version 13.0.0-1632-gf9cfe84 (f9cfe843a1c749d145b6c3b81a0519cc6536eb28) mimic (dev) 1: (ceph::__ceph_assert_fail(char const*, char const*, int, char const*)+0x102) [0x7fc6b1054ba2] 2: (()+0x15c58) [0x560cd4697c58] 3: (main()+0x9) [0x560cd46937f9] 4: (__libc_start_main()+0xf0) [0x7fc6b003f830] 5: (_start()+0x29) [0x560cd46938f9] NOTE: a copy of the executable, or `objdump -rdS ` is needed to interpret this. Aborted (core dumped) Fixes: http://tracker.ceph.com/issues/22011 Signed-off-by: Li Wang (cherry picked from commit 07d5b81b57f17696f4f693225fcb5a1f7060e9d9) --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index bf7477f4d394..16c94ea785ec 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -838,7 +838,8 @@ static int get_mapped_info(int pid, Config *cfg) std::vector args; ifs.open(path.c_str(), std::ifstream::in); - assert (ifs.is_open()); + if (!ifs.is_open()) + return -1; ifs >> cmdline; for (unsigned i = 0; i < cmdline.size(); i++) {