diff options
author | Sage Weil <sage@newdream.net> | 2013-02-26 17:11:21 -0800 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2013-02-26 17:11:21 -0800 |
commit | 1da4087e07690620120682a4965bbcdec5f4b334 (patch) | |
tree | 30332447ab6fe04819268b851fe0e2d08c159ef8 | |
parent | 3768050f8fcb7d7a020c920cd34284be8f888488 (diff) | |
parent | 1d8e1195aaa1ebdb64c6df7f72a8c8dc2460ed10 (diff) | |
download | ceph-1da4087e07690620120682a4965bbcdec5f4b334.tar.gz |
Merge pull request #78 from Elbandi/master
Some fixes and functions for libcephfs and client
Reviewed-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | src/client/Client.cc | 79 | ||||
-rw-r--r-- | src/client/Client.h | 9 | ||||
-rw-r--r-- | src/include/cephfs/libcephfs.h | 12 | ||||
-rw-r--r-- | src/libcephfs.cc | 6 |
4 files changed, 85 insertions, 21 deletions
diff --git a/src/client/Client.cc b/src/client/Client.cc index 8e341498c61..d5ff08ba55d 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4300,6 +4300,7 @@ int Client::setattr(const char *relpath, struct stat *attr, int mask) { Mutex::Locker lock(client_lock); tout(cct) << "setattr" << std::endl; + tout(cct) << relpath << std::endl; tout(cct) << mask << std::endl; filepath path(relpath); @@ -4310,6 +4311,19 @@ int Client::setattr(const char *relpath, struct stat *attr, int mask) return _setattr(in, attr, mask); } +int Client::fsetattr(int fd, struct stat *attr, int mask) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "fsetattr" << std::endl; + tout(cct) << fd << std::endl; + tout(cct) << mask << std::endl; + + Fh *f = get_filehandle(fd); + if (!f) + return -EBADF; + return _setattr(f->inode, attr, mask); +} + int Client::stat(const char *relpath, struct stat *stbuf, frag_info_t *dirstat, int mask) { @@ -4432,7 +4446,24 @@ int Client::fchmod(int fd, mode_t mode) return _setattr(f->inode, &attr, CEPH_SETATTR_MODE); } -int Client::chown(const char *relpath, uid_t uid, gid_t gid) +int Client::lchmod(const char *relpath, mode_t mode) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "lchmod" << std::endl; + tout(cct) << relpath << std::endl; + tout(cct) << mode << std::endl; + filepath path(relpath); + Inode *in; + // don't follow symlinks + int r = path_walk(path, &in, false); + if (r < 0) + return r; + struct stat attr; + attr.st_mode = mode; + return _setattr(in, &attr, CEPH_SETATTR_MODE); +} + +int Client::chown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "chown" << std::endl; @@ -4447,28 +4478,35 @@ int Client::chown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } -int Client::fchown(int fd, uid_t uid, gid_t gid) +int Client::fchown(int fd, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "fchown" << std::endl; tout(cct) << fd << std::endl; tout(cct) << uid << std::endl; tout(cct) << gid << std::endl; - assert(fd_map.count(fd)); - Fh *f = fd_map[fd]; + Fh *f = get_filehandle(fd); + if (!f) + return -EBADF; struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(f->inode, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(f->inode, &attr, mask); } -int Client::lchown(const char *relpath, uid_t uid, gid_t gid) +int Client::lchown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); - tout(cct) << "chown" << std::endl; + tout(cct) << "lchown" << std::endl; tout(cct) << relpath << std::endl; tout(cct) << uid << std::endl; tout(cct) << gid << std::endl; @@ -4481,7 +4519,10 @@ int Client::lchown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } int Client::utime(const char *relpath, struct utimbuf *buf) @@ -4504,6 +4545,26 @@ int Client::utime(const char *relpath, struct utimbuf *buf) return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME); } +int Client::lutime(const char *relpath, struct utimbuf *buf) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "lutime" << std::endl; + tout(cct) << relpath << std::endl; + tout(cct) << buf->modtime << std::endl; + tout(cct) << buf->actime << std::endl; + filepath path(relpath); + Inode *in; + // don't follow symlinks + int r = path_walk(path, &in, false); + if (r < 0) + return r; + struct stat attr; + attr.st_mtim.tv_sec = buf->modtime; + attr.st_mtim.tv_nsec = 0; + attr.st_atim.tv_sec = buf->actime; + attr.st_atim.tv_nsec = 0; + return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME); +} int Client::opendir(const char *relpath, dir_result_t **dirpp) { diff --git a/src/client/Client.h b/src/client/Client.h index 3fcdf481ad1..8846e3f9ad7 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -620,12 +620,15 @@ public: int lstatlite(const char *path, struct statlite *buf); int setattr(const char *relpath, struct stat *attr, int mask); + int fsetattr(int fd, struct stat *attr, int mask); int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); - int chown(const char *path, uid_t uid, gid_t gid); - int fchown(int fd, uid_t uid, gid_t gid); - int lchown(const char *path, uid_t uid, gid_t gid); + int lchmod(const char *path, mode_t mode); + int chown(const char *path, int uid, int gid); + int fchown(int fd, int uid, int gid); + int lchown(const char *path, int uid, int gid); int utime(const char *path, struct utimbuf *buf); + int lutime(const char *path, struct utimbuf *buf); int truncate(const char *path, loff_t size); // file ops diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 7b04cce4270..abfd25cfd7e 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -530,7 +530,7 @@ int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change the ownership of a file from an open file descriptor. @@ -541,7 +541,7 @@ int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_ * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); +int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid); /** * Change the ownership of a file/directory, don't follow symlinks. @@ -552,7 +552,7 @@ int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_lchown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change file/directory last access and modification times. @@ -610,9 +610,9 @@ int ceph_open(struct ceph_mount_info *cmount, const char *path, int flags, mode_ * @param flags a set of option masks that control how the file is created/opened. * @param mode the permissions to place on the file if the file does not exist and O_CREAT * is specified in the flags. - * @param stripe_unit the stripe unit size (option, -1 for default) - * @param stripe_count the stripe count (optional, -1 for default) - * @param object_size the object size (optional, -1 for default) + * @param stripe_unit the stripe unit size (option, 0 for default) + * @param stripe_count the stripe count (optional, 0 for default) + * @param object_size the object size (optional, 0 for default) * @param data_pool name of target data pool name (optional, NULL or empty string for default) * @returns a non-negative file descriptor number on success or a negative error code on failure. */ diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 75937586cb0..d2fe0dac861 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -574,21 +574,21 @@ extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode) return cmount->get_client()->fchmod(fd, mode); } extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->chown(path, uid, gid); } extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->fchown(fd, uid, gid); } extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; |