Commit c36fca86 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French
Browse files

cifsd: add the check to work file lock and rename behaviors like Windows...


cifsd: add the check to work file lock and rename behaviors like Windows unless POSIX extensions are negotiated

This patch add the check to work file lock and rename behaviors
like Windows if POSIX extensions are not negotiated.

Signed-off-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 20ea7fd2
Loading
Loading
Loading
Loading
+56 −45
Original line number Diff line number Diff line
@@ -370,7 +370,6 @@ int ksmbd_vfs_read(struct ksmbd_work *work,
	char *rbuf, *name;
	struct inode *inode;
	char namebuf[NAME_MAX];
	int ret;

	rbuf = work->aux_payload_buf;
	filp = fp->filp;
@@ -391,12 +390,16 @@ int ksmbd_vfs_read(struct ksmbd_work *work,
	if (ksmbd_stream_fd(fp))
		return ksmbd_vfs_stream_read(fp, rbuf, pos, count);

	if (!work->tcon->posix_extensions) {
		int ret;

		ret = check_lock_range(filp, *pos, *pos + count - 1,
				READ);
		if (ret) {
			ksmbd_err("unable to read due to lock\n");
			return -EAGAIN;
		}
	}

	nbytes = kernel_read(filp, rbuf, count, pos);
	if (nbytes < 0) {
@@ -504,12 +507,14 @@ int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp,
		goto out;
	}

	if (!work->tcon->posix_extensions) {
		err = check_lock_range(filp, *pos, *pos + count - 1, WRITE);
		if (err) {
			ksmbd_err("unable to write due to lock\n");
			err = -EAGAIN;
			goto out;
		}
	}

	/* Do we need to break any of a levelII oplock? */
	smb_break_all_levII_oplock(work, fp, 1);
@@ -706,6 +711,7 @@ static int __ksmbd_vfs_rename(struct ksmbd_work *work,
	struct dentry *dst_dent;
	int err;

	if (!work->tcon->posix_extensions) {
		spin_lock(&src_dent->d_lock);
		list_for_each_entry(dst_dent, &src_dent->d_subdirs, d_child) {
			struct ksmbd_file *child_fp;
@@ -721,6 +727,7 @@ static int __ksmbd_vfs_rename(struct ksmbd_work *work,
			}
		}
		spin_unlock(&src_dent->d_lock);
	}

	if (d_really_is_negative(src_dent_parent))
		return -ENOENT;
@@ -820,7 +827,6 @@ int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
{
	struct path path;
	int err = 0;
	struct inode *inode;

	if (name) {
		err = kern_path(name, 0, &path);
@@ -842,7 +848,9 @@ int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
		/* Do we need to break any of a levelII oplock? */
		smb_break_all_levII_oplock(work, fp, 1);

		inode = file_inode(filp);
		if (!work->tcon->posix_extensions) {
			struct inode *inode = file_inode(filp);

			if (size < inode->i_size) {
				err = check_lock_range(filp, size,
						inode->i_size - 1, WRITE);
@@ -855,6 +863,7 @@ int ksmbd_vfs_truncate(struct ksmbd_work *work, const char *name,
				ksmbd_err("failed due to lock\n");
				return -EAGAIN;
			}
		}

		err = vfs_truncate(&filp->f_path, size);
		if (err)
@@ -1860,6 +1869,7 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,

	smb_break_all_levII_oplock(work, dst_fp, 1);

	if (!work->tcon->posix_extensions) {
		for (i = 0; i < chunk_count; i++) {
			src_off = le64_to_cpu(chunks[i].SourceOffset);
			dst_off = le64_to_cpu(chunks[i].TargetOffset);
@@ -1872,6 +1882,7 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
						dst_off + len - 1, WRITE))
				return -EAGAIN;
		}
	}

	src_file_size = i_size_read(file_inode(src_fp->filp));