os/newstore: pass flags to _{open,create}_fid

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2015-04-10 16:35:40 -07:00
parent 48f639beec
commit 5539a75efb
2 changed files with 17 additions and 17 deletions

View File

@ -1254,7 +1254,7 @@ int NewStore::_do_read(
if (fd >= 0) { if (fd >= 0) {
VOID_TEMP_FAILURE_RETRY(::close(fd)); VOID_TEMP_FAILURE_RETRY(::close(fd));
} }
fd = _open_fid(cur_fid); fd = _open_fid(cur_fid, O_RDONLY);
if (fd < 0) { if (fd < 0) {
r = fd; r = fd;
goto out; goto out;
@ -1852,10 +1852,10 @@ int NewStore::_recover_next_fid()
return 0; 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) { 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) { if (fd >= 0) {
dout(30) << __func__ << " " << fid << " = " << fd dout(30) << __func__ << " " << fid << " = " << fd
<< " (open by handle)" << dendl; << " (open by handle)" << dendl;
@ -1868,7 +1868,7 @@ int NewStore::_open_fid(fid_t fid)
char fn[32]; char fn[32];
snprintf(fn, sizeof(fn), "%u/%u", fid.fset, fid.fno); 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) { if (fd < 0) {
int r = -errno; int r = -errno;
derr << __func__ << " on " << fid << ": " << cpp_strerror(r) << dendl; derr << __func__ << " on " << fid << ": " << cpp_strerror(r) << dendl;
@ -1878,7 +1878,7 @@ int NewStore::_open_fid(fid_t fid)
return fd; 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); Mutex::Locker l(fid_lock);
@ -1932,7 +1932,7 @@ int NewStore::_create_fid(TransContext *txc, fid_t *fid)
dout(10) << __func__ << " " << fid_last << dendl; dout(10) << __func__ << " " << fid_last << dendl;
char s[32]; char s[32];
snprintf(s, sizeof(s), "%u", fid->fno); 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) { if (fd < 0) {
int r = -errno; int r = -errno;
derr << __func__ << " cannot create " << path << "/fragments/" 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 << " " dout(20) << __func__ << " write " << p->fid << " "
<< p->offset << "~" << p->length << dendl; << p->offset << "~" << p->length << dendl;
int fd = _open_fid(p->fid); int fd = _open_fid(p->fid, O_RDWR);
if (fd < 0) if (fd < 0)
return fd; return fd;
int r = ::lseek64(fd, p->offset, SEEK_SET); 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 << " " dout(20) << __func__ << " zero " << p->fid << " "
<< p->offset << "~" << p->length << dendl; << p->offset << "~" << p->length << dendl;
int fd = _open_fid(p->fid); int fd = _open_fid(p->fid, O_RDWR);
if (fd < 0) if (fd < 0)
return fd; return fd;
int r = ::lseek64(fd, p->offset, SEEK_SET); 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 << " " dout(20) << __func__ << " truncate " << p->fid << " "
<< p->offset << dendl; << p->offset << dendl;
int fd = _open_fid(p->fid); int fd = _open_fid(p->fid, O_RDWR);
if (fd < 0) if (fd < 0)
return fd; return fd;
int r = ::ftruncate(fd, p->offset); 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]; fragment_t &f = o->onode.data_map[0];
f.offset = 0; f.offset = 0;
f.length = o->onode.size; f.length = o->onode.size;
int fd = _create_fid(txc, &f.fid); int fd = _create_fid(txc, &f.fid, O_RDWR);
if (fd < 0) { if (fd < 0) {
return fd; return fd;
} }
@ -3027,7 +3027,7 @@ int NewStore::_do_write(TransContext *txc,
fragment_t &f = o->onode.data_map[0]; fragment_t &f = o->onode.data_map[0];
f.offset = 0; f.offset = 0;
f.length = MAX(offset + length, o->onode.size); 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) { if (fd < 0) {
r = fd; r = fd;
goto out; goto out;
@ -3039,7 +3039,7 @@ int NewStore::_do_write(TransContext *txc,
// append (possibly with gap) // append (possibly with gap)
assert(o->onode.data_map.size() == 1); assert(o->onode.data_map.size() == 1);
fragment_t &f = o->onode.data_map.rbegin()->second; fragment_t &f = o->onode.data_map.rbegin()->second;
fd = _open_fid(f.fid); fd = _open_fid(f.fid, O_RDWR);
if (fd < 0) { if (fd < 0) {
r = fd; r = fd;
goto out; goto out;
@ -3079,7 +3079,7 @@ int NewStore::_do_write(TransContext *txc,
f.length = length; f.length = length;
o->onode.size = length; o->onode.size = length;
fd = _create_fid(txc, &f.fid); fd = _create_fid(txc, &f.fid, O_RDWR);
if (fd < 0) { if (fd < 0) {
r = fd; r = fd;
goto out; goto out;
@ -3132,7 +3132,7 @@ int NewStore::_do_write(TransContext *txc,
int NewStore::_clean_fid_tail(TransContext *txc, const fragment_t& f) 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) { if (fd < 0) {
return fd; return fd;
} }
@ -3216,7 +3216,7 @@ int NewStore::_zero(TransContext *txc,
if (offset >= o->onode.size) { if (offset >= o->onode.size) {
// after tail // after tail
int fd = _open_fid(f.fid); int fd = _open_fid(f.fid, O_RDWR);
if (fd < 0) { if (fd < 0) {
r = fd; r = fd;
goto out; goto out;

View File

@ -417,8 +417,8 @@ private:
void _reap_collections(); void _reap_collections();
int _recover_next_fid(); int _recover_next_fid();
int _create_fid(TransContext *txc, fid_t *fid); int _create_fid(TransContext *txc, fid_t *fid, unsigned flags);
int _open_fid(fid_t fid); int _open_fid(fid_t fid, unsigned flags);
int _remove_fid(fid_t fid); int _remove_fid(fid_t fid);
int _recover_next_nid(); int _recover_next_nid();