summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGui Hecheng <guihecheng@cmss.chinamobile.com>2017-04-14 11:28:19 +0200
committerGui Hecheng <guihecheng@cmss.chinamobile.com>2017-04-14 11:53:04 +0200
commita32add15b8ec7866c1d33a34a2b309b19270c0ba (patch)
tree9a273cf351d2712baf1988e7f7bd44cb62e467de
parentRevert "rgw_file.h: fix potential data race condition" (diff)
downloadceph-a32add15b8ec7866c1d33a34a2b309b19270c0ba.tar.xz
ceph-a32add15b8ec7866c1d33a34a2b309b19270c0ba.zip
rgw_file: add locks to fix potential race
Signed-off-by: Gui Hecheng <guihecheng@cmss.chinamobile.com>
-rw-r--r--src/rgw/rgw_file.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc
index eb24db6d95a..297c2561a89 100644
--- a/src/rgw/rgw_file.cc
+++ b/src/rgw/rgw_file.cc
@@ -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:
{