Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion fs/fuse/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ static ssize_t fuse_conn_congestion_threshold_write(struct file *file,
return ret;
}

static ssize_t fuse_conn_inode_count_read(struct file *file, char __user *buf,
size_t len, loff_t *ppos)
{
struct fuse_conn *fc;
unsigned long count;
char tmp[32];
size_t size;

if (*ppos)
return 0;

fc = fuse_ctl_file_conn_get(file);
if (!fc)
return 0;

count = atomic64_read(&fc->num_inodes);
fuse_conn_put(fc);

size = sprintf(tmp, "%lu\n", count);
return simple_read_from_buffer(buf, len, ppos, tmp, size);
}

static const struct file_operations fuse_ctl_abort_ops = {
.open = nonseekable_open,
.write = fuse_conn_abort_write,
Expand All @@ -210,6 +232,12 @@ static const struct file_operations fuse_conn_congestion_threshold_ops = {
.llseek = no_llseek,
};

static const struct file_operations fuse_conn_inode_count_ops = {
.open = nonseekable_open,
.read = fuse_conn_inode_count_read,
.llseek = no_llseek,
};

static struct dentry *fuse_ctl_add_dentry(struct dentry *parent,
struct fuse_conn *fc,
const char *name,
Expand Down Expand Up @@ -278,7 +306,9 @@ int fuse_ctl_add_conn(struct fuse_conn *fc)
1, NULL, &fuse_conn_max_background_ops) ||
!fuse_ctl_add_dentry(parent, fc, "congestion_threshold",
S_IFREG | 0600, 1, NULL,
&fuse_conn_congestion_threshold_ops))
&fuse_conn_congestion_threshold_ops) ||
!fuse_ctl_add_dentry(parent, fc, "inode_count", S_IFREG | 0400, 1,
NULL, &fuse_conn_inode_count_ops))
goto err;

return 0;
Expand Down
4 changes: 3 additions & 1 deletion fs/fuse/fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define FUSE_NAME_MAX (PATH_MAX - 1)

/** Number of dentries for each connection in the control filesystem */
#define FUSE_CTL_NUM_DENTRIES 5
#define FUSE_CTL_NUM_DENTRIES 6

/** Maximum of max_pages received in init_out */
extern unsigned int fuse_max_pages_limit;
Expand Down Expand Up @@ -899,6 +899,8 @@ struct fuse_conn {
/** Version counter for evict inode */
atomic64_t evict_ctr;

atomic64_t num_inodes;

/* maximum file name length */
u32 name_max;

Expand Down
3 changes: 3 additions & 0 deletions fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ static void fuse_evict_inode(struct inode *inode)
*/
if (inode->i_nlink > 0)
atomic64_inc(&fc->evict_ctr);
atomic64_dec(&fc->num_inodes);
Comment thread
hbirth marked this conversation as resolved.
Outdated
}
if (S_ISREG(inode->i_mode) && !fuse_is_bad(inode)) {
WARN_ON(!list_empty(&fi->write_files));
Expand Down Expand Up @@ -504,6 +505,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
inode->i_generation = generation;
fuse_init_inode(inode, attr, fc);
unlock_new_inode(inode);
atomic64_inc(&fc->num_inodes);
} else if (fuse_stale_inode(inode, generation, attr)) {
/* nodeid was reused, any I/O on the old inode should fail */
fuse_make_bad(inode);
Expand Down Expand Up @@ -1036,6 +1038,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_mount *fm,

atomic64_set(&fc->attr_version, 1);
atomic64_set(&fc->evict_ctr, 1);
atomic64_set(&fc->num_inodes, 0);
Comment thread
hbirth marked this conversation as resolved.
Outdated
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
fc->user_ns = get_user_ns(user_ns);
Expand Down
3 changes: 0 additions & 3 deletions include/uapi/linux/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,6 @@ struct fuse_init_in {
#define FUSE_COMPAT_INIT_OUT_SIZE 8
#define FUSE_COMPAT_22_INIT_OUT_SIZE 24

/*
* align_page_order: Number of pages for optimal IO, or a multiple of that
*/
struct fuse_init_out {
uint32_t major;
uint32_t minor;
Expand Down