Wire up the userspace interface for write stream management via three new fcntls. F_GET_MAX_WRITE_STREAMS: Returns the number of available streams. F_SET_WRITE_STREAM: Assign a specific stream value to the file. F_GET_WRITE_STREAM: Query what stream value is set on the file. Application should query the available streams by calling F_GET_MAX_WRITE_STREAMS first. If returned value is N, valid stream values for the file are 0 to N. Stream value 0 implies that no stream is set on the file. Setting a larger value than available streams is rejected. Signed-off-by: Kanchan Joshi --- fs/fcntl.c | 33 +++++++++++++++++++++++++++++++++ include/uapi/linux/fcntl.h | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index f93dbca08435..c982f0506a3f 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -441,6 +441,30 @@ static int f_owner_sig(struct file *filp, int signum, bool setsig) return ret; } +static long fcntl_get_max_write_streams(struct file *filp) +{ + if (filp->f_op->get_max_write_streams) + return filp->f_op->get_max_write_streams(filp); + + return -EOPNOTSUPP; +} + +static long fcntl_set_write_stream(struct file *filp, unsigned long arg) +{ + if (filp->f_op->set_write_stream) + return filp->f_op->set_write_stream(filp, arg); + + return -EOPNOTSUPP; +} + +static long fcntl_get_write_stream(struct file *filp) +{ + if (filp->f_op->get_write_stream) + return filp->f_op->get_write_stream(filp); + + return -EOPNOTSUPP; +} + static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, struct file *filp) { @@ -563,6 +587,15 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, return -EFAULT; err = fcntl_setdeleg(fd, filp, &deleg); break; + case F_GET_MAX_WRITE_STREAMS: + err = fcntl_get_max_write_streams(filp); + break; + case F_SET_WRITE_STREAM: + err = fcntl_set_write_stream(filp, arg); + break; + case F_GET_WRITE_STREAM: + err = fcntl_get_write_stream(filp); + break; default: break; } diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index aadfbf6e0cb3..4b75470fc07a 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -190,4 +190,8 @@ struct delegation { #define AT_EXECVE_CHECK 0x10000 /* Only perform a check if execution would be allowed. */ +/* write stream management */ +#define F_GET_MAX_WRITE_STREAMS (F_LINUX_SPECIFIC_BASE + 17) +#define F_GET_WRITE_STREAM (F_LINUX_SPECIFIC_BASE + 18) +#define F_SET_WRITE_STREAM (F_LINUX_SPECIFIC_BASE + 19) #endif /* _UAPI_LINUX_FCNTL_H */ -- 2.25.1