From 186a86f342625a9dce53fe537f8237c6099d5c54 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 1 Oct 2009 06:58:46 +0000 Subject: Global: Introduce setattr and fsetattr fops Signed-off-by: Anand V. Avati BUG: 146 (Add setattr FOP) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=146 --- xlators/features/filter/src/filter.c | 220 ++++++----------------------- xlators/features/path-convertor/src/path.c | 94 ++++-------- 2 files changed, 68 insertions(+), 246 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/filter/src/filter.c b/xlators/features/filter/src/filter.c index c9cd8dbfa6b..67395655771 100644 --- a/xlators/features/filter/src/filter.c +++ b/xlators/features/filter/src/filter.c @@ -262,25 +262,28 @@ filter_stat (call_frame_t *frame, } static int32_t -filter_chmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +filter_setattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *preop, + struct stat *postop) { if (op_ret >= 0) { - update_stat (buf, this->private); + update_stat (preop, this->private); + update_stat (postop, this->private); } - STACK_UNWIND (frame, op_ret, op_errno, buf); + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } int32_t -filter_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +filter_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { int32_t ret = 0; ret = update_frame (frame, loc->inode, this->private); @@ -291,147 +294,65 @@ filter_chmod (call_frame_t *frame, case GF_FILTER_MAP_BOTH: if (loc->inode->st_mode & S_IWOTH) break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); + gf_log (this->name, GF_LOG_DEBUG, + "%s: returning permission denied", loc->path); + STACK_UNWIND (frame, -1, EPERM, NULL, NULL, NULL); return 0; - + case GF_FILTER_FILTER_UID: case GF_FILTER_FILTER_GID: case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); + STACK_UNWIND (frame, -1, EROFS, NULL, NULL); return 0; default: break; } STACK_WIND (frame, - filter_chmod_cbk, + filter_setattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, + FIRST_CHILD(this)->fops->setattr, loc, - mode); + stbuf, valid); return 0; } - static int32_t -filter_fchmod_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) +filter_fsetattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *preop, + struct stat *postop) { if (op_ret >= 0) { - update_stat (buf, this->private); + update_stat (preop, this->private); + update_stat (postop, this->private); } STACK_UNWIND (frame, op_ret, op_errno, - buf); + preop, postop); return 0; } -int32_t -filter_fchmod (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - mode_t mode) +int32_t +filter_fsetattr (call_frame_t *frame, + xlator_t *this, + fd_t *fd, + struct stat *stbuf, + int32_t valid) { STACK_WIND (frame, - filter_fchmod_cbk, + filter_fsetattr_cbk, FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchmod, + FIRST_CHILD(this)->fops->fsetattr, fd, - mode); - return 0; -} - -static int32_t -filter_chown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -filter_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) -{ - int32_t ret = 0; - ret = update_frame (frame, loc->inode, this->private); - switch (ret) { - case GF_FILTER_MAP_UID: - if (loc->inode->st_mode & S_IWGRP) - break; - case GF_FILTER_MAP_BOTH: - if (loc->inode->st_mode & S_IWOTH) - break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); - return 0; - - case GF_FILTER_FILTER_UID: - case GF_FILTER_FILTER_GID: - case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); - return 0; - default: - break; - } - - STACK_WIND (frame, - filter_chown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + stbuf, valid); return 0; } -static int32_t -filter_fchown_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - -int32_t -filter_fchown (call_frame_t *frame, - xlator_t *this, - fd_t *fd, - uid_t uid, - gid_t gid) -{ - STACK_WIND (frame, - filter_fchown_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->fchown, - fd, - uid, - gid); - return 0; -} static int32_t filter_truncate_cbk (call_frame_t *frame, @@ -513,56 +434,6 @@ filter_ftruncate (call_frame_t *frame, return 0; } -int32_t -filter_utimens_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct stat *buf) -{ - if (op_ret >= 0) { - update_stat (buf, this->private); - } - STACK_UNWIND (frame, op_ret, op_errno, buf); - return 0; -} - - -int32_t -filter_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - int32_t ret = 0; - ret = update_frame (frame, loc->inode, this->private); - switch (ret) { - case GF_FILTER_MAP_UID: - if (loc->inode->st_mode & S_IWGRP) - break; - case GF_FILTER_MAP_BOTH: - if (loc->inode->st_mode & S_IWOTH) - break; - gf_log (this->name, GF_LOG_DEBUG, "%s: returning permission denied", loc->path); - STACK_UNWIND (frame, -1, EPERM, NULL); - return 0; - - case GF_FILTER_FILTER_UID: - case GF_FILTER_FILTER_GID: - case GF_FILTER_RO_FS: - STACK_UNWIND (frame, -1, EROFS, NULL); - return 0; - } - - STACK_WIND (frame, - filter_utimens_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - return 0; -} static int32_t filter_readlink_cbk (call_frame_t *frame, @@ -1715,8 +1586,6 @@ struct xlator_fops fops = { .lookup = filter_lookup, .stat = filter_stat, .fstat = filter_fstat, - .chmod = filter_chmod, - .fchmod = filter_fchmod, .readlink = filter_readlink, .mknod = filter_mknod, .mkdir = filter_mkdir, @@ -1725,8 +1594,6 @@ struct xlator_fops fops = { .symlink = filter_symlink, .rename = filter_rename, .link = filter_link, - .chown = filter_chown, - .fchown = filter_fchown, .truncate = filter_truncate, .ftruncate = filter_ftruncate, .create = filter_create, @@ -1737,7 +1604,8 @@ struct xlator_fops fops = { .getxattr = filter_getxattr, .removexattr = filter_removexattr, .opendir = filter_opendir, - .utimens = filter_utimens, + .setattr = filter_setattr, + .fsetattr = filter_fsetattr, }; struct xlator_mops mops = { diff --git a/xlators/features/path-convertor/src/path.c b/xlators/features/path-convertor/src/path.c index 8badef38cd6..b53286104aa 100644 --- a/xlators/features/path-convertor/src/path.c +++ b/xlators/features/path-convertor/src/path.c @@ -618,65 +618,49 @@ path_link (call_frame_t *frame, } int32_t -path_chmod (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - mode_t mode) +path_setattr_cbk (call_frame_t *frame, + void *cookie, + xlator_t *this, + int32_t op_ret, + int32_t op_errno, + struct stat *preop, + struct stat *postop) { - char *loc_path = (char *)loc->path; - char *tmp_path = NULL; - - if (!(tmp_path = path_this_to_that (this, loc->path))) { - STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); - return 0; - } - loc->path = tmp_path; - - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chmod, - loc, - mode); - - loc->path = loc_path; - if (tmp_path != loc_path) - FREE (tmp_path); - + STACK_UNWIND (frame, op_ret, op_errno, preop, postop); return 0; } -int32_t -path_chown (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - uid_t uid, - gid_t gid) +int32_t +path_setattr (call_frame_t *frame, + xlator_t *this, + loc_t *loc, + struct stat *stbuf, + int32_t valid) { char *loc_path = (char *)loc->path; char *tmp_path = NULL; - + if (!(tmp_path = path_this_to_that (this, loc->path))) { STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); return 0; } loc->path = tmp_path; - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->chown, - loc, - uid, - gid); + STACK_WIND (frame, + path_setattr_cbk, + FIRST_CHILD(this), + FIRST_CHILD(this)->fops->setattr, + loc, + stbuf, valid); - loc->path = loc_path; + loc->path = loc_path; if (tmp_path != loc_path) FREE (tmp_path); return 0; } + int32_t path_truncate (call_frame_t *frame, xlator_t *this, @@ -706,34 +690,6 @@ path_truncate (call_frame_t *frame, return 0; } -int32_t -path_utimens (call_frame_t *frame, - xlator_t *this, - loc_t *loc, - struct timespec tv[2]) -{ - char *loc_path = (char *)loc->path; - char *tmp_path = NULL; - - if (!(tmp_path = path_this_to_that (this, loc->path))) { - STACK_UNWIND (frame, -1, ENOENT, NULL, NULL); - return 0; - } - loc->path = tmp_path; - - STACK_WIND (frame, - path_common_buf_cbk, - FIRST_CHILD(this), - FIRST_CHILD(this)->fops->utimens, - loc, - tv); - - loc->path = loc_path; - if (tmp_path != loc_path) - FREE (tmp_path); - - return 0; -} int32_t path_open (call_frame_t *frame, @@ -1173,10 +1129,7 @@ struct xlator_fops fops = { .symlink = path_symlink, .rename = path_rename, .link = path_link, - .chmod = path_chmod, - .chown = path_chown, .truncate = path_truncate, - .utimens = path_utimens, .open = path_open, .setxattr = path_setxattr, .getxattr = path_getxattr, @@ -1189,6 +1142,7 @@ struct xlator_fops fops = { .xattrop = path_xattrop, .entrylk = path_entrylk, .inodelk = path_inodelk, + .setattr = path_setattr, }; -- cgit