tout << relpath << std::endl;
tout << mode << std::endl;
filepath path = mkpath(relpath);
- return _chmod(path, mode);
+ return _chmod(path, mode, true);
}
-int Client::_chmod(const filepath &path, mode_t mode, int uid, int gid)
+static int symop(int op, bool follow)
+{
+ if (follow)
+ return op & CEPH_MDS_OP_FOLLOW_LINK;
+ else
+ return op & ~CEPH_MDS_OP_FOLLOW_LINK;
+}
+
+int Client::_chmod(const filepath &path, mode_t mode, bool followsym, int uid, int gid)
{
dout(3) << "_chmod(" << path << ", 0" << oct << mode << dec << ")" << dendl;
- MClientRequest *req = new MClientRequest(CEPH_MDS_OP_CHMOD, messenger->get_myinst());
+ MClientRequest *req = new MClientRequest(symop(CEPH_MDS_OP_CHMOD, followsym),
+ messenger->get_myinst());
req->set_filepath(path);
req->head.args.chmod.mode = mode;
tout << uid << std::endl;
tout << gid << std::endl;
filepath path = mkpath(relpath);
- return _chown(path, uid, gid);
+ return _chown(path, uid, gid, true);
}
-int Client::_chown(const filepath &path, uid_t uid, gid_t gid, int cuid, int cgid)
+int Client::_chown(const filepath &path, uid_t uid, gid_t gid, bool followsym, int cuid, int cgid)
{
dout(3) << "_chown(" << path << ", " << uid << ", " << gid << ")" << dendl;
- MClientRequest *req = new MClientRequest(CEPH_MDS_OP_CHOWN, messenger->get_myinst());
+ MClientRequest *req = new MClientRequest(symop(CEPH_MDS_OP_CHOWN, followsym),
+ messenger->get_myinst());
req->set_filepath(path);
req->head.args.chown.uid = uid;
req->head.args.chown.gid = gid;
tout << buf->modtime << std::endl;
tout << buf->actime << std::endl;
filepath path = mkpath(relpath);
- return _utimes(path, utime_t(buf->modtime,0), utime_t(buf->actime,0));
+ return _utimes(path, utime_t(buf->modtime,0), utime_t(buf->actime,0), true);
}
-int Client::_utimes(const filepath &path, utime_t mtime, utime_t atime, int uid, int gid)
+int Client::_utimes(const filepath &path, utime_t mtime, utime_t atime, bool followsym,
+ int uid, int gid)
{
dout(3) << "_utimes(" << path << ", " << mtime << ", " << atime << ")" << dendl;
return 0;
}
- MClientRequest *req = new MClientRequest(CEPH_MDS_OP_UTIME, messenger->get_myinst());
+ MClientRequest *req = new MClientRequest(symop(CEPH_MDS_OP_UTIME, followsym),
+ messenger->get_myinst());
req->set_filepath(path);
mtime.encode_timeval(&req->head.args.utime.mtime);
atime.encode_timeval(&req->head.args.utime.atime);
tout << relpath << std::endl;
tout << length << std::endl;
filepath path = mkpath(relpath);
- return _truncate(path, length);
+ return _truncate(path, length, true);
}
-int Client::_truncate(const filepath &path, off_t length, int uid, int gid)
+int Client::_truncate(const filepath &path, off_t length, bool followsym, int uid, int gid)
{
- MClientRequest *req = new MClientRequest(CEPH_MDS_OP_TRUNCATE, messenger->get_myinst());
+ MClientRequest *req = new MClientRequest(symop(CEPH_MDS_OP_TRUNCATE, followsym),
+ messenger->get_myinst());
req->set_filepath(path);
req->head.args.truncate.length = length;
int Client::_ftruncate(Fh *fh, off_t length)
{
- MClientRequest *req = new MClientRequest(CEPH_MDS_OP_TRUNCATE, messenger->get_myinst());
filepath path(fh->inode->inode.ino);
- req->set_filepath(path);
- req->head.args.truncate.length = length;
-
- MClientReply *reply = make_request(req, -1, -1);
- int res = reply->get_result();
- delete reply;
-
- dout(3) << "ftruncate(\"" << fh << "\", " << length << ") = " << res << dendl;
- return res;
+ return _truncate(path, length, false);
}
return r;
}
-
-
int Client::fstat(int fd, struct stat *stbuf)
{
Mutex::Locker lock(client_lock);
assert(fd_map.count(fd));
Fh *f = fd_map[fd];
- int r = _fstat(f, stbuf);
+ filepath path(f->inode->ino());
+ int r = _lstat(path, stbuf);
dout(3) << "fstat(" << fd << ", " << stbuf << ") = " << r << dendl;
return r;
}
-int Client::_fstat(Fh *f, struct stat *stbuf)
-{
- Inode *in = 0;
- filepath fpath(f->inode->ino());
- int res = _do_lstat(fpath, CEPH_STAT_MASK_INODE_ALL, &in);
- if (res == 0) {
- assert(in);
- fill_stat(in, stbuf);
- dout(10) << "stat sez size = " << in->inode.size << " mode = 0" << oct << stbuf->st_mode << dec << " ino = " << stbuf->st_ino << dendl;
- }
-
- trim_cache();
- dout(3) << "fstat(\"" << f << "\", " << stbuf << ") = " << res << dendl;
- return res;
-}
-
// not written yet, but i want to link!
int r = 0;
if ((mask & FUSE_SET_ATTR_MODE) &&
- ((r = _chmod(path.c_str(), attr->st_mode, uid, gid)) < 0)) return r;
+ ((r = _chmod(path.c_str(), attr->st_mode, false, uid, gid)) < 0)) return r;
if ((mask & FUSE_SET_ATTR_UID) && (mask & FUSE_SET_ATTR_GID) &&
- ((r = _chown(path.c_str(), attr->st_uid, attr->st_gid, uid, gid)) < 0)) return r;
+ ((r = _chown(path.c_str(), attr->st_uid, attr->st_gid, false, uid, gid)) < 0)) return r;
//if ((mask & FUSE_SET_ATTR_GID) &&
//(r = client->_chgrp(path.c_str(), attr->st_gid) < 0)) return r;
if ((mask & FUSE_SET_ATTR_SIZE) &&
- ((r = _truncate(path.c_str(), attr->st_size, uid, gid)) < 0)) return r;
+ ((r = _truncate(path.c_str(), attr->st_size, false, uid, gid)) < 0)) return r;
if ((mask & FUSE_SET_ATTR_MTIME) && (mask & FUSE_SET_ATTR_ATIME)) {
- if ((r = _utimes(path.c_str(), utime_t(attr->st_mtime,0), utime_t(attr->st_atime,0), uid, gid)) < 0) return r;
+ if ((r = _utimes(path.c_str(), utime_t(attr->st_mtime,0), utime_t(attr->st_atime,0), false, uid, gid)) < 0) return r;
} else if (mask & FUSE_SET_ATTR_MTIME) {
- if ((r = _utimes(path.c_str(), utime_t(attr->st_mtime,0), utime_t(), uid, gid)) < 0) return r;
+ if ((r = _utimes(path.c_str(), utime_t(attr->st_mtime,0), utime_t(), false, uid, gid)) < 0) return r;
} else if (mask & FUSE_SET_ATTR_ATIME) {
- if ((r = _utimes(path.c_str(), utime_t(), utime_t(attr->st_atime,0), uid, gid)) < 0) return r;
+ if ((r = _utimes(path.c_str(), utime_t(), utime_t(attr->st_atime,0), false, uid, gid)) < 0) return r;
}
assert(r == 0);
int _readlink(const filepath &path, char *buf, off_t size, int uid=-1, int gid=-1);
int _symlink(const filepath &path, const char *target, int uid=-1, int gid=-1);
int _lstat(const filepath &path, struct stat *stbuf, int uid=-1, int gid=-1);
- int _chmod(const filepath &path, mode_t mode, int uid=-1, int gid=-1);
- int _chown(const filepath &path, uid_t uid, gid_t gid, int cuid=-1, int cgid=-1);
- int _utimes(const filepath &path, utime_t mtime, utime_t atime, int uid=-1, int gid=-1);
+ int _chmod(const filepath &path, mode_t mode, bool followsym, int uid=-1, int gid=-1);
+ int _chown(const filepath &path, uid_t uid, gid_t gid, bool followsym, int cuid=-1, int cgid=-1);
+ int _utimes(const filepath &path, utime_t mtime, utime_t atime, bool followsym, int uid=-1, int gid=-1);
int _mknod(const filepath &path, mode_t mode, dev_t rdev, int uid=-1, int gid=-1);
int _open(const filepath &path, int flags, mode_t mode, Fh **fhp, int uid=-1, int gid=-1);
int _release(Fh *fh);
int _read(Fh *fh, off_t offset, off_t size, bufferlist *bl);
int _write(Fh *fh, off_t offset, off_t size, const char *buf);
int _flush(Fh *fh);
- int _truncate(const filepath &path, off_t length, int uid=-1, int gid=-1);
+ int _truncate(const filepath &path, off_t length, bool followsym, int uid=-1, int gid=-1);
int _ftruncate(Fh *fh, off_t length);
int _fsync(Fh *fh, bool syncdataonly);
- int _fstat(Fh *fh, struct stat *stbuf);
int _statfs(struct statvfs *stbuf);