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;
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;
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;
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);
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/"
{
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);
{
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);
{
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);
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;
}
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;
// 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;
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;
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;
}
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;