Skip to content

Commit 6a01bea

Browse files
Kanchan Joshikawasaki
authored andcommitted
fs: add the interface to query user write streams
Add new fcntl F_GET_MAX_WRITE_STREAMS. This returns the numbers of streams that are available for userspace. And for that, use ->user_write_streams() callback when the involved filesystem provides it. In absence of such callback, use 'max_write_streams' queue limit of the underlying block device. Signed-off-by: Kanchan Joshi <[email protected]>
1 parent 1890116 commit 6a01bea

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

fs/fcntl.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/compat.h>
2828
#include <linux/mount.h>
2929
#include <linux/rw_hint.h>
30+
#include <linux/blkdev.h>
3031

3132
#include <linux/poll.h>
3233
#include <asm/siginfo.h>
@@ -394,6 +395,33 @@ static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
394395
return 0;
395396
}
396397

398+
static u8 vfs_user_write_streams(struct inode *inode)
399+
{
400+
struct super_block *sb;
401+
402+
if (S_ISBLK(inode->i_mode))
403+
return bdev_max_write_streams(I_BDEV(inode));
404+
405+
sb = inode->i_sb;
406+
/* If available, use per-mount/fs policy */
407+
if (sb->s_op && sb->s_op->user_write_streams)
408+
return sb->s_op->user_write_streams(sb);
409+
/* otherwise, fallback to queue limit */
410+
if (sb->s_bdev)
411+
return bdev_max_write_streams(sb->s_bdev);
412+
return 0;
413+
}
414+
415+
static long fcntl_get_max_write_streams(struct file *file)
416+
{
417+
struct inode *inode = file_inode(file);
418+
419+
if (S_ISBLK(inode->i_mode))
420+
inode = file->f_mapping->host;
421+
422+
return vfs_user_write_streams(inode);
423+
}
424+
397425
/* Is the file descriptor a dup of the file? */
398426
static long f_dupfd_query(int fd, struct file *filp)
399427
{
@@ -552,6 +580,9 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
552580
case F_SET_RW_HINT:
553581
err = fcntl_set_rw_hint(filp, cmd, arg);
554582
break;
583+
case F_GET_MAX_WRITE_STREAMS:
584+
err = fcntl_get_max_write_streams(filp);
585+
break;
555586
default:
556587
break;
557588
}

include/uapi/linux/fcntl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
#define F_GET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 13)
6262
#define F_SET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 14)
6363

64+
/*
65+
* Query available write streams
66+
*/
67+
#define F_GET_MAX_WRITE_STREAMS (F_LINUX_SPECIFIC_BASE + 15)
68+
6469
/*
6570
* Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be
6671
* used to clear any hints previously set.

0 commit comments

Comments
 (0)