]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/newstore: pass flags to _{open,create}_fid
authorSage Weil <sage@redhat.com>
Fri, 10 Apr 2015 23:35:40 +0000 (16:35 -0700)
committerSage Weil <sage@redhat.com>
Tue, 1 Sep 2015 17:39:37 +0000 (13:39 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/newstore/NewStore.cc
src/os/newstore/NewStore.h

index 925a6ec72e821f41c1613b585b4c6d0f2f7bd4a5..81dd130b2920f7915edad75f0199519bc9a153ac 100644 (file)
@@ -1254,7 +1254,7 @@ int NewStore::_do_read(
        if (fd >= 0) {
          VOID_TEMP_FAILURE_RETRY(::close(fd));
        }
-       fd = _open_fid(cur_fid);
+       fd = _open_fid(cur_fid, O_RDONLY);
        if (fd < 0) {
          r = fd;
          goto out;
@@ -1852,10 +1852,10 @@ int NewStore::_recover_next_fid()
   return 0;
 }
 
-int NewStore::_open_fid(fid_t fid)
+int NewStore::_open_fid(fid_t fid, unsigned flags)
 {
   if (fid.handle.length() && g_conf->newstore_open_by_handle) {
-    int fd = fs->open_handle(path_fd, fid.handle, O_RDWR);
+    int fd = fs->open_handle(path_fd, fid.handle, flags);
     if (fd >= 0) {
       dout(30) << __func__ << " " << fid << " = " << fd
               << " (open by handle)" << dendl;
@@ -1868,7 +1868,7 @@ int NewStore::_open_fid(fid_t fid)
 
   char fn[32];
   snprintf(fn, sizeof(fn), "%u/%u", fid.fset, fid.fno);
-  int fd = ::openat(frag_fd, fn, O_RDWR);
+  int fd = ::openat(frag_fd, fn, flags);
   if (fd < 0) {
     int r = -errno;
     derr << __func__ << " on " << fid << ": " << cpp_strerror(r) << dendl;
@@ -1878,7 +1878,7 @@ int NewStore::_open_fid(fid_t fid)
   return fd;
 }
 
-int NewStore::_create_fid(TransContext *txc, fid_t *fid)
+int NewStore::_create_fid(TransContext *txc, fid_t *fid, unsigned flags)
 {
   {
     Mutex::Locker l(fid_lock);
@@ -1932,7 +1932,7 @@ int NewStore::_create_fid(TransContext *txc, fid_t *fid)
   dout(10) << __func__ << " " << fid_last << dendl;
   char s[32];
   snprintf(s, sizeof(s), "%u", fid->fno);
-  int fd = ::openat(fset_fd, s, O_RDWR|O_CREAT, 0644);
+  int fd = ::openat(fset_fd, s, flags | O_CREAT, 0644);
   if (fd < 0) {
     int r = -errno;
     derr << __func__ << " cannot create " << path << "/fragments/"
@@ -2277,7 +2277,7 @@ int NewStore::_do_wal_transaction(wal_transaction_t& wt)
       {
        dout(20) << __func__ << " write " << p->fid << " "
                 << p->offset << "~" << p->length << dendl;
-       int fd = _open_fid(p->fid);
+       int fd = _open_fid(p->fid, O_RDWR);
        if (fd < 0)
          return fd;
        int r = ::lseek64(fd, p->offset, SEEK_SET);
@@ -2295,7 +2295,7 @@ int NewStore::_do_wal_transaction(wal_transaction_t& wt)
       {
        dout(20) << __func__ << " zero " << p->fid << " "
                 << p->offset << "~" << p->length << dendl;
-       int fd = _open_fid(p->fid);
+       int fd = _open_fid(p->fid, O_RDWR);
        if (fd < 0)
          return fd;
        int r = ::lseek64(fd, p->offset, SEEK_SET);
@@ -2318,7 +2318,7 @@ int NewStore::_do_wal_transaction(wal_transaction_t& wt)
       {
        dout(20) << __func__ << " truncate " << p->fid << " "
                 << p->offset << dendl;
-       int fd = _open_fid(p->fid);
+       int fd = _open_fid(p->fid, O_RDWR);
        if (fd < 0)
          return fd;
        int r = ::ftruncate(fd, p->offset);
@@ -2922,7 +2922,7 @@ int NewStore::_do_write_all_overlays(TransContext *txc,
     fragment_t &f = o->onode.data_map[0];
     f.offset = 0;
     f.length = o->onode.size;
-    int fd = _create_fid(txc, &f.fid);
+    int fd = _create_fid(txc, &f.fid, O_RDWR);
     if (fd < 0) {
       return fd;
     }
@@ -3027,7 +3027,7 @@ int NewStore::_do_write(TransContext *txc,
       fragment_t &f = o->onode.data_map[0];
       f.offset = 0;
       f.length = MAX(offset + length, o->onode.size);
-      fd = _create_fid(txc, &f.fid);
+      fd = _create_fid(txc, &f.fid, O_RDWR);
       if (fd < 0) {
        r = fd;
        goto out;
@@ -3039,7 +3039,7 @@ int NewStore::_do_write(TransContext *txc,
       // append (possibly with gap)
       assert(o->onode.data_map.size() == 1);
       fragment_t &f = o->onode.data_map.rbegin()->second;
-      fd = _open_fid(f.fid);
+      fd = _open_fid(f.fid, O_RDWR);
       if (fd < 0) {
        r = fd;
        goto out;
@@ -3079,7 +3079,7 @@ int NewStore::_do_write(TransContext *txc,
 
     f.length = length;
     o->onode.size = length;
-    fd = _create_fid(txc, &f.fid);
+    fd = _create_fid(txc, &f.fid, O_RDWR);
     if (fd < 0) {
       r = fd;
       goto out;
@@ -3132,7 +3132,7 @@ int NewStore::_do_write(TransContext *txc,
 
 int NewStore::_clean_fid_tail(TransContext *txc, const fragment_t& f)
 {
-  int fd = _open_fid(f.fid);
+  int fd = _open_fid(f.fid, O_RDWR);
   if (fd < 0) {
     return fd;
   }
@@ -3216,7 +3216,7 @@ int NewStore::_zero(TransContext *txc,
 
     if (offset >= o->onode.size) {
       // after tail
-      int fd = _open_fid(f.fid);
+      int fd = _open_fid(f.fid, O_RDWR);
       if (fd < 0) {
        r = fd;
        goto out;
index b8f83f4357f4f60b8715c779350aca164405fc39..381044da1f46a9dd83efc8c47c23b62a9560a216 100644 (file)
@@ -417,8 +417,8 @@ private:
   void _reap_collections();
 
   int _recover_next_fid();
-  int _create_fid(TransContext *txc, fid_t *fid);
-  int _open_fid(fid_t fid);
+  int _create_fid(TransContext *txc, fid_t *fid, unsigned flags);
+  int _open_fid(fid_t fid, unsigned flags);
   int _remove_fid(fid_t fid);
 
   int _recover_next_nid();