Skip to content

Commit a3d3659

Browse files
Kanchan Joshikawasaki
authored andcommitted
fs: add set and query write stream
Add two new fcntls: F_GET_WRITE_STREAM - to query the write-stream on inode F_SET_WRITE_STREAM - to set the write-stream on inode Application should query the available streams by calling F_GET_MAX_WRITE_STREAMS first. If returned value is N, applications can choose any value from 1 to N while setting the stream. Setting the value 0 is not flagged as an error as that implies no stream. But setting a larger value than available streams is rejected. Signed-off-by: Kanchan Joshi <[email protected]>
1 parent 3e360ab commit a3d3659

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

fs/fcntl.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,33 @@ static long fcntl_get_max_write_streams(struct file *file)
422422
return vfs_user_write_streams(inode);
423423
}
424424

425+
static long fcntl_get_write_stream(struct file *file)
426+
{
427+
struct inode *inode = file_inode(file);
428+
429+
if (S_ISBLK(inode->i_mode))
430+
inode = file->f_mapping->host;
431+
432+
return inode->i_write_stream;
433+
}
434+
435+
static long fcntl_set_write_stream(struct file *file, unsigned long arg)
436+
{
437+
struct inode *inode = file_inode(file);
438+
439+
if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
440+
return -EPERM;
441+
442+
if (S_ISBLK(inode->i_mode))
443+
inode = file->f_mapping->host;
444+
445+
if (arg > vfs_user_write_streams(inode))
446+
return -EINVAL;
447+
448+
WRITE_ONCE(inode->i_write_stream, arg);
449+
return 0;
450+
}
451+
425452
/* Is the file descriptor a dup of the file? */
426453
static long f_dupfd_query(int fd, struct file *filp)
427454
{
@@ -583,6 +610,12 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
583610
case F_GET_MAX_WRITE_STREAMS:
584611
err = fcntl_get_max_write_streams(filp);
585612
break;
613+
case F_GET_WRITE_STREAM:
614+
err = fcntl_get_write_stream(filp);
615+
break;
616+
case F_SET_WRITE_STREAM:
617+
err = fcntl_set_write_stream(filp, arg);
618+
break;
586619
default:
587620
break;
588621
}

include/uapi/linux/fcntl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
* Query available write streams
6666
*/
6767
#define F_GET_MAX_WRITE_STREAMS (F_LINUX_SPECIFIC_BASE + 15)
68+
#define F_GET_WRITE_STREAM (F_LINUX_SPECIFIC_BASE + 16)
69+
#define F_SET_WRITE_STREAM (F_LINUX_SPECIFIC_BASE + 17)
6870

6971
/*
7072
* Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be

0 commit comments

Comments
 (0)