]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_file: add locks to fix potential race 14553/head
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Fri, 14 Apr 2017 09:28:19 +0000 (17:28 +0800)
committerGui Hecheng <guihecheng@cmss.chinamobile.com>
Fri, 14 Apr 2017 09:53:04 +0000 (17:53 +0800)
Signed-off-by: Gui Hecheng <guihecheng@cmss.chinamobile.com>
src/rgw/rgw_file.cc

index eb24db6d95a6ff686653209ebe51629aeac09327..297c2561a8930f690c6661942b6620e3326992f4 100644 (file)
@@ -80,6 +80,7 @@ namespace rgw {
                      RGWFileHandle::FLAG_BUCKET);
       if (get<0>(fhr)) {
        RGWFileHandle* rgw_fh = get<0>(fhr);
+       lock_guard guard(rgw_fh->mtx);
        rgw_fh->set_times(req.get_ctime());
        /* restore attributes */
        auto ux_key = req.get_attr(RGW_ATTR_UNIX_KEY1);
@@ -127,6 +128,7 @@ namespace rgw {
          fhr = lookup_fh(parent, path, RGWFileHandle::FLAG_CREATE);
          if (get<0>(fhr)) {
            RGWFileHandle* rgw_fh = get<0>(fhr);
+           lock_guard guard(rgw_fh->mtx);
            rgw_fh->set_size(req.get_size());
            rgw_fh->set_times(req.get_mtime());
            /* restore attributes */
@@ -153,6 +155,7 @@ namespace rgw {
          fhr = lookup_fh(parent, path, RGWFileHandle::FLAG_DIRECTORY);
          if (get<0>(fhr)) {
            RGWFileHandle* rgw_fh = get<0>(fhr);
+           lock_guard guard(rgw_fh->mtx);
            rgw_fh->set_size(req.get_size());
            rgw_fh->set_times(req.get_mtime());
            /* restore attributes */
@@ -195,6 +198,7 @@ namespace rgw {
            if (get<0>(fhr)) {
              /* for now use the parent object's mtime */
              RGWFileHandle* rgw_fh = get<0>(fhr);
+             lock_guard guard(rgw_fh->mtx);
              rgw_fh->set_mtime(parent->get_mtime());
            }
          }
@@ -225,6 +229,7 @@ namespace rgw {
     int rc = rgwlib.get_fe()->execute_req(&req);
     if ((rc == 0) &&
        (req.get_ret() == 0)) {
+      lock_guard(rgw_fh->mtx);
       rgw_fh->set_atime(real_clock::to_timespec(real_clock::now()));
       *bytes_read = req.nread;
     }
@@ -587,7 +592,8 @@ namespace rgw {
     if ((rc == 0) &&
        (rc2 == 0)) {
       /* XXX atomicity */
-      LookupFHResult fhr = lookup_fh(parent, name, RGWFileHandle::FLAG_CREATE);
+      LookupFHResult fhr = lookup_fh(parent, name, RGWFileHandle::FLAG_CREATE |
+                                                   RGWFileHandle::FLAG_LOCK);
       RGWFileHandle* rgw_fh = get<0>(fhr);
       if (rgw_fh) {
        if (get<1>(fhr) & RGWFileHandle::FLAG_CREATE) {
@@ -595,7 +601,6 @@ namespace rgw {
          real_time t = real_clock::now();
          rgw_fh->create_stat(st, mask);
          rgw_fh->set_times(t);
-         rgw_fh->open_for_create(); // XXX needed?
 
          parent->set_mtime(real_clock::to_timespec(t));
          parent->set_ctime(real_clock::to_timespec(t));
@@ -603,6 +608,7 @@ namespace rgw {
         if (st)
           (void) rgw_fh->stat(st);
        get<0>(mkr) = rgw_fh;
+       rgw_fh->mtx.unlock();
       } else
        rc = -EIO;
     }
@@ -634,6 +640,8 @@ namespace rgw {
     int rc, rc2;
     buffer::list ux_key, ux_attrs;
 
+    lock_guard guard(rgw_fh->mtx);
+
     switch(rgw_fh->fh.fh_type) {
     case RGW_FS_TYPE_FILE:
     {