summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/storage/posix/src')
-rw-r--r--xlators/storage/posix/src/posix-entry-ops.c12
-rw-r--r--xlators/storage/posix/src/posix-handle.h4
-rw-r--r--xlators/storage/posix/src/posix-helpers.c42
-rw-r--r--xlators/storage/posix/src/posix-inode-fd-ops.c9
4 files changed, 67 insertions, 0 deletions
diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c
index 4d7ed5be7c8..41d8c873b4c 100644
--- a/xlators/storage/posix/src/posix-entry-ops.c
+++ b/xlators/storage/posix/src/posix-entry-ops.c
@@ -180,6 +180,7 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
int32_t nlink_samepgfid = 0;
struct posix_private *priv = NULL;
posix_inode_ctx_t *ctx = NULL;
+ int ret = 0;
VALIDATE_OR_GOTO (frame, out);
VALIDATE_OR_GOTO (this, out);
@@ -248,6 +249,17 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
if (xdata && (op_ret == 0)) {
xattr = posix_xattr_fill (this, real_path, loc, NULL, -1, xdata,
&buf);
+
+ if (dict_get (xdata, GF_CLEAN_WRITE_PROTECTION)) {
+ ret = sys_lremovexattr (real_path,
+ GF_PROTECT_FROM_EXTERNAL_WRITES);
+ if (ret == -1 && (errno != ENODATA && errno != ENOATTR))
+ gf_msg (this->name, GF_LOG_ERROR,
+ P_MSG_XATTR_NOT_REMOVED, errno,
+ "removexattr failed. key %s path %s",
+ GF_PROTECT_FROM_EXTERNAL_WRITES,
+ loc->path);
+ }
}
if (priv->update_pgfid_nlinks) {
diff --git a/xlators/storage/posix/src/posix-handle.h b/xlators/storage/posix/src/posix-handle.h
index 97186f91e64..8a07cf2b57d 100644
--- a/xlators/storage/posix/src/posix-handle.h
+++ b/xlators/storage/posix/src/posix-handle.h
@@ -186,4 +186,8 @@ int
posix_create_link_if_gfid_exists (xlator_t *this, uuid_t gfid,
char *real_path, inode_table_t *itable);
+int
+posix_check_internal_writes (xlator_t *this, fd_t *fd, int sysfd,
+ dict_t *xdata);
+
#endif /* !_POSIX_HANDLE_H */
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 90afced604c..56c9b4afe94 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -2739,3 +2739,45 @@ posix_override_umask (mode_t mode, mode_t mode_bit)
gf_msg_debug ("posix", 0, "The value of mode is %u", mode);
return mode;
}
+
+int
+posix_check_internal_writes (xlator_t *this, fd_t *fd, int sysfd,
+ dict_t *xdata)
+{
+ int ret = 0;
+ size_t xattrsize = 0;
+ data_t *val = NULL;
+
+ LOCK (&fd->inode->lock);
+ {
+ val = dict_get (xdata, GF_PROTECT_FROM_EXTERNAL_WRITES);
+ if (val) {
+ ret = sys_fsetxattr (sysfd,
+ GF_PROTECT_FROM_EXTERNAL_WRITES,
+ val->data, val->len, 0);
+ if (ret == -1) {
+ gf_msg (this->name, GF_LOG_ERROR,
+ P_MSG_XATTR_FAILED,
+ errno, "setxattr failed key %s",
+ GF_PROTECT_FROM_EXTERNAL_WRITES);
+ }
+
+ goto out;
+ }
+
+ if (dict_get (xdata, GF_AVOID_OVERWRITE)) {
+ xattrsize = sys_fgetxattr (sysfd,
+ GF_PROTECT_FROM_EXTERNAL_WRITES,
+ NULL, 0);
+ if ((xattrsize == -1) && ((errno == ENOATTR) ||
+ (errno == ENODATA))) {
+ ret = 0;
+ } else {
+ ret = -1;
+ }
+ }
+ }
+out:
+ UNLOCK (&fd->inode->lock);
+ return ret;
+}
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
index c90bc6c438a..812cf792874 100644
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
@@ -1579,6 +1579,15 @@ posix_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
_fd = pfd->fd;
+ ret = posix_check_internal_writes (this, fd, _fd, xdata);
+ if (ret < 0) {
+ gf_msg (this->name, GF_LOG_ERROR, 0, 0,
+ "possible overwrite from internal client, fd=%p", fd);
+ op_ret = -1;
+ op_errno = EBUSY;
+ goto out;
+ }
+
if (xdata) {
if (dict_get (xdata, GLUSTERFS_WRITE_IS_APPEND))
write_append = _gf_true;