rbd: don't return 0 on unmap if RBD_DEV_FLAG_REMOVING is set
authorIlya Dryomov <idryomov@gmail.com>
Tue, 8 Jan 2019 18:47:38 +0000 (19:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Jan 2019 21:12:32 +0000 (22:12 +0100)
commitf710ce8ad2f8e4167769b595f60b6ec92f6d7029
tree030703d6bf22638989210e4556711dbd5cb45282
parent57cd3fad7644a22f7b0fab8e3e5670c3424852fb
rbd: don't return 0 on unmap if RBD_DEV_FLAG_REMOVING is set

commit 85f5a4d666fd9be73856ed16bb36c5af5b406b29 upstream.

There is a window between when RBD_DEV_FLAG_REMOVING is set and when
the device is removed from rbd_dev_list.  During this window, we set
"already" and return 0.

Returning 0 from write(2) can confuse userspace tools because
0 indicates that nothing was written.  In particular, "rbd unmap"
will retry the write multiple times a second:

  10:28:05.463299 write(4, "0", 1)        = 0
  10:28:05.463509 write(4, "0", 1)        = 0
  10:28:05.463720 write(4, "0", 1)        = 0
  10:28:05.463942 write(4, "0", 1)        = 0
  10:28:05.464155 write(4, "0", 1)        = 0

Cc: stable@vger.kernel.org
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Tested-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/rbd.c