monitor exclusive lock when rbd client died abruptly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
   When the client writes to rbd image, it'll hold the "exclusive lock".
   If the client dies abruptly without releaseing the "exclusive lock",
   how the other client know that they could write to the rbd image?

   I write below program. If the first process/client died abrutply
   (built with -DKILL_DEAD, send kill signal), the second
   process/client(build without -DKILL_DEAD) could still write to the
   rbd image. However, there's an abvious "time delay" that the second
   client could write to the rbd image.

   Is there's a mechanism to watch/monitor that the "exclusive lock" is
   released after the client, which hold it, died abruptly?

   Progam:
  1 #include <rbd/librbd.hpp>
  2 #include <rados/librados.hpp>
  3 
  4 #include <cstring>
  5 #include <iostream>
  6 #include <string>
  7 
  8 void err_msg(int ret, const std::string &msg = "") {
  9     std::cerr << "[error] msg:" << msg << " strerror: "
 10               << strerror(-ret) <<  std::endl;
 11 }
 12 void err_exit(int ret, const std::string &msg = "") {
 13     err_msg(ret, msg);
 14     exit(EXIT_FAILURE);
 15 }
 16 
 17 int main(int argc, char* argv[]) {
 18     int ret = 0;
 19     librados::Rados rados;
 20 
 21     ret = rados.init("admin");
 22     if (ret < 0)
 23         err_exit(ret,"failed to initialize rados");
 24     ret = rados.conf_read_file("ceph.conf");
 25     if (ret < 0)
 26         err_exit(ret, "failed to parse ceph.conf");
 27 
 28     ret = rados.connect();
 29     if (ret < 0)
 30         err_exit(ret, "failed to connect to rados cluster");
 31 
 32     librados::IoCtx io_ctx;
 33     std::string pool_name = "rbd";
 34     ret = rados.ioctx_create(pool_name.c_str(), io_ctx);
 35     if (ret < 0) {
 36         rados.shutdown();
 37         err_exit(ret, "failed to create ioctx");
 38     }
 39 
 40     // rbd
 41     librbd::RBD rbd;
 42 
 43     librbd::Image image;
 44     std::string image_name = "fio_test";
 45     ret = rbd.open(io_ctx, image, image_name.c_str());
 46     if (ret < 0) {
 47         io_ctx.close();
 48         rados.shutdown();
 49         err_exit(ret, "failed to open rbd image");
 50     } else {
 51         std::cout << "open image succeeded" << std::endl;
 52     }
 53 
 54     ceph::bufferlist bw;
 55     bw.append(std::string("changcheng"));
 56     image.write(0, bw.length(), bw);
 57 
 58     ceph::bufferlist br;
 59     int read = image.read(0, bw.length(), br);
 60     br.append(std::string(4, '\0'));
 61     std::cout << br.c_str() << std::endl;
 62 
 63 #if defined(KILL_DEAD)
 64     while(1);
 65 #endif
 66 
 67 done:
 68     image.close();
 69     io_ctx.close();
 70     rados.shutdown();
 71     exit(EXIT_SUCCESS);
 72 }

B.R.
Changcheng
_______________________________________________
Dev mailing list -- dev@xxxxxxx
To unsubscribe send an email to dev-leave@xxxxxxx



[Index of Archives]     [CEPH Users]     [Ceph Devel]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux