now no need to reboot
This commit is contained in:
parent
ac32a0a607
commit
dd5a0e207c
65
statsfs.c
65
statsfs.c
@ -10,6 +10,7 @@
|
|||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/printk.h>
|
#include <linux/printk.h>
|
||||||
|
#include <linux/uio.h> /* для iov_iter_count() */
|
||||||
|
|
||||||
#define LIBFS_MAGIC 0xA0B0C0D0
|
#define LIBFS_MAGIC 0xA0B0C0D0
|
||||||
#define LIBFS_BOOKS_MODE 01777
|
#define LIBFS_BOOKS_MODE 01777
|
||||||
@ -39,9 +40,26 @@ static int libfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
|
|||||||
static int libfs_link(struct dentry *old_dentry, struct inode *dir,
|
static int libfs_link(struct dentry *old_dentry, struct inode *dir,
|
||||||
struct dentry *new_dentry);
|
struct dentry *new_dentry);
|
||||||
|
|
||||||
|
/* Обёртки с логированием */
|
||||||
|
static ssize_t libfs_read_iter(struct kiocb *iocb, struct iov_iter *iter)
|
||||||
|
{
|
||||||
|
struct inode *inode = file_inode(iocb->ki_filp);
|
||||||
|
pr_info("statsfs: READ ino#%lu pos=%lld len=%zu\n",
|
||||||
|
inode->i_ino, iocb->ki_pos, iov_iter_count(iter));
|
||||||
|
return generic_file_read_iter(iocb, iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t libfs_write_iter(struct kiocb *iocb, struct iov_iter *iter)
|
||||||
|
{
|
||||||
|
struct inode *inode = file_inode(iocb->ki_filp);
|
||||||
|
pr_info("statsfs: WRITE ino#%lu pos=%lld len=%zu\n",
|
||||||
|
inode->i_ino, iocb->ki_pos, iov_iter_count(iter));
|
||||||
|
return generic_file_write_iter(iocb, iter);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct file_operations libfs_file_ops = {
|
static const struct file_operations libfs_file_ops = {
|
||||||
.read_iter = generic_file_read_iter,
|
.read_iter = libfs_read_iter,
|
||||||
.write_iter = generic_file_write_iter,
|
.write_iter = libfs_write_iter,
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,8 +76,8 @@ static const struct inode_operations libfs_dir_iops = {
|
|||||||
.rmdir = libfs_rmdir,
|
.rmdir = libfs_rmdir,
|
||||||
.rename = libfs_rename,
|
.rename = libfs_rename,
|
||||||
.link = libfs_link,
|
.link = libfs_link,
|
||||||
.mknod = NULL, /* запрещаем */
|
.mknod = NULL,
|
||||||
.symlink = NULL, /* запрещаем */
|
.symlink = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct super_operations statsfs_sops = {
|
static const struct super_operations statsfs_sops = {
|
||||||
@ -71,14 +89,13 @@ static const struct super_operations statsfs_sops = {
|
|||||||
static struct inode *libfs_get_inode(struct super_block *sb, umode_t mode)
|
static struct inode *libfs_get_inode(struct super_block *sb, umode_t mode)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
||||||
pr_info("statsfs: libfs_get_inode(sb=%p, mode=%o)\n", sb, mode);
|
pr_info("statsfs: libfs_get_inode(sb=%p, mode=%o)\n", sb, mode);
|
||||||
|
|
||||||
inode = new_inode(sb);
|
inode = new_inode(sb);
|
||||||
if (!inode) {
|
if (!inode) {
|
||||||
pr_err("statsfs: new_inode failed for mode %o\n", mode);
|
pr_err("statsfs: new_inode failed for mode %o\n", mode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode->i_ino = get_next_ino();
|
inode->i_ino = get_next_ino();
|
||||||
inode->i_sb = sb;
|
inode->i_sb = sb;
|
||||||
inode->i_mode = mode;
|
inode->i_mode = mode;
|
||||||
@ -90,7 +107,6 @@ static struct inode *libfs_get_inode(struct super_block *sb, umode_t mode)
|
|||||||
} else {
|
} else {
|
||||||
inode->i_op = &libfs_file_iops;
|
inode->i_op = &libfs_file_iops;
|
||||||
inode->i_fop = &libfs_file_ops;
|
inode->i_fop = &libfs_file_ops;
|
||||||
|
|
||||||
inode->i_private = kzalloc(sizeof(struct hlist_head), GFP_KERNEL);
|
inode->i_private = kzalloc(sizeof(struct hlist_head), GFP_KERNEL);
|
||||||
if (!inode->i_private) {
|
if (!inode->i_private) {
|
||||||
pr_err("statsfs: kzalloc for inode #%lu failed\n", inode->i_ino);
|
pr_err("statsfs: kzalloc for inode #%lu failed\n", inode->i_ino);
|
||||||
@ -98,9 +114,9 @@ static struct inode *libfs_get_inode(struct super_block *sb, umode_t mode)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INIT_HLIST_HEAD((struct hlist_head *)inode->i_private);
|
INIT_HLIST_HEAD((struct hlist_head *)inode->i_private);
|
||||||
pr_info("statsfs: created file inode #%lu with private list\n", inode->i_ino);
|
pr_info("statsfs: created file inode #%lu with private list\n",
|
||||||
|
inode->i_ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,18 +134,17 @@ static void cleanup_links(struct inode *victim)
|
|||||||
|
|
||||||
hlist_for_each_entry_safe(le, tmp, list, node) {
|
hlist_for_each_entry_safe(le, tmp, list, node) {
|
||||||
struct dentry *link = le->link;
|
struct dentry *link = le->link;
|
||||||
struct dentry *pd;
|
|
||||||
struct inode *parent;
|
|
||||||
|
|
||||||
if (!link || d_unlinked(link)) {
|
if (!link || d_unlinked(link)) {
|
||||||
pr_info("statsfs: link already gone, freeing entry\n");
|
pr_info("statsfs: link gone, freeing entry\n");
|
||||||
hlist_del(&le->node);
|
hlist_del(&le->node);
|
||||||
dput(link);
|
dput(link);
|
||||||
kfree(le);
|
kfree(le);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pd = dget_parent(link);
|
{
|
||||||
|
struct dentry *pd = dget_parent(link);
|
||||||
|
struct inode *parent;
|
||||||
if (pd) {
|
if (pd) {
|
||||||
parent = d_inode(pd);
|
parent = d_inode(pd);
|
||||||
if (WARN_ON(!parent))
|
if (WARN_ON(!parent))
|
||||||
@ -141,7 +156,7 @@ static void cleanup_links(struct inode *victim)
|
|||||||
link, parent->i_ino);
|
link, parent->i_ino);
|
||||||
dput(pd);
|
dput(pd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
skip_unlink:
|
skip_unlink:
|
||||||
hlist_del(&le->node);
|
hlist_del(&le->node);
|
||||||
dput(link);
|
dput(link);
|
||||||
@ -162,7 +177,6 @@ static int libfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
|||||||
struct dentry *dentry, umode_t mode, bool excl)
|
struct dentry *dentry, umode_t mode, bool excl)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
||||||
pr_info("statsfs: CREATE %pd in dir inode #%lu mode=%o\n",
|
pr_info("statsfs: CREATE %pd in dir inode #%lu mode=%o\n",
|
||||||
dentry, dir->i_ino, mode);
|
dentry, dir->i_ino, mode);
|
||||||
if (dir != books_inode)
|
if (dir != books_inode)
|
||||||
@ -175,7 +189,8 @@ static int libfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
|||||||
inode->i_uid = current_fsuid();
|
inode->i_uid = current_fsuid();
|
||||||
inode->i_gid = current_fsgid();
|
inode->i_gid = current_fsgid();
|
||||||
d_add(dentry, inode);
|
d_add(dentry, inode);
|
||||||
pr_info("statsfs: added file %pd as inode #%lu\n", dentry, inode->i_ino);
|
pr_info("statsfs: added file %pd as inode #%lu\n",
|
||||||
|
dentry, inode->i_ino);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,16 +198,14 @@ static int libfs_unlink(struct inode *dir, struct dentry *dentry)
|
|||||||
{
|
{
|
||||||
struct inode *victim = d_inode(dentry);
|
struct inode *victim = d_inode(dentry);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
pr_info("statsfs: UNLINK %pd from dir inode #%lu\n",
|
pr_info("statsfs: UNLINK %pd from dir inode #%lu\n",
|
||||||
dentry, dir->i_ino);
|
dentry, dir->i_ino);
|
||||||
if (dir == libfs_sb->s_root->d_inode && is_protected(dentry))
|
if (dir == libfs_sb->s_root->d_inode && is_protected(dentry))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
err = simple_unlink(dir, dentry);
|
err = simple_unlink(dir, dentry);
|
||||||
if (!err && dir == books_inode) {
|
if (!err && dir == books_inode)
|
||||||
cleanup_links(victim);
|
cleanup_links(victim);
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +213,6 @@ static int libfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
|||||||
struct dentry *dentry, umode_t mode)
|
struct dentry *dentry, umode_t mode)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
||||||
pr_info("statsfs: MKDIR %pd in dir inode #%lu\n",
|
pr_info("statsfs: MKDIR %pd in dir inode #%lu\n",
|
||||||
dentry, dir->i_ino);
|
dentry, dir->i_ino);
|
||||||
if (dir == libfs_sb->s_root->d_inode || dir == books_inode)
|
if (dir == libfs_sb->s_root->d_inode || dir == books_inode)
|
||||||
@ -215,7 +227,8 @@ static int libfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
|||||||
inode->i_uid = current_fsuid();
|
inode->i_uid = current_fsuid();
|
||||||
d_add(dentry, inode);
|
d_add(dentry, inode);
|
||||||
inc_nlink(dir);
|
inc_nlink(dir);
|
||||||
pr_info("statsfs: created subdir %pd as inode #%lu\n", dentry, inode->i_ino);
|
pr_info("statsfs: created subdir %pd as inode #%lu\n",
|
||||||
|
dentry, inode->i_ino);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +247,7 @@ static int libfs_rename(struct mnt_idmap *idmap, struct inode *odir,
|
|||||||
struct dentry *odent, struct inode *ndir,
|
struct dentry *odent, struct inode *ndir,
|
||||||
struct dentry *ndent, unsigned int flags)
|
struct dentry *ndent, unsigned int flags)
|
||||||
{
|
{
|
||||||
pr_info("statsfs: RENAME %pd (ino#%lu) -> %pd (ino#%lu)\n",
|
pr_info("statsfs: RENAME %pd(ino#%lu) -> %pd(ino#%lu)\n",
|
||||||
odent, odir->i_ino, ndent, ndir->i_ino);
|
odent, odir->i_ino, ndent, ndir->i_ino);
|
||||||
if ((odir == libfs_sb->s_root->d_inode || ndir == libfs_sb->s_root->d_inode) &&
|
if ((odir == libfs_sb->s_root->d_inode || ndir == libfs_sb->s_root->d_inode) &&
|
||||||
(is_protected(odent) || is_protected(ndent)))
|
(is_protected(odent) || is_protected(ndent)))
|
||||||
@ -250,7 +263,6 @@ static int libfs_link(struct dentry *old_dentry, struct inode *dir,
|
|||||||
struct inode *t = d_inode(old_dentry);
|
struct inode *t = d_inode(old_dentry);
|
||||||
struct link_entry *le;
|
struct link_entry *le;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
pr_info("statsfs: LINK %pd -> %pd in dir inode #%lu\n",
|
pr_info("statsfs: LINK %pd -> %pd in dir inode #%lu\n",
|
||||||
old_dentry, new_dentry, dir->i_ino);
|
old_dentry, new_dentry, dir->i_ino);
|
||||||
if (!S_ISREG(t->i_mode))
|
if (!S_ISREG(t->i_mode))
|
||||||
@ -276,7 +288,6 @@ static int libfs_link(struct dentry *old_dentry, struct inode *dir,
|
|||||||
static int libfs_fill_super(struct super_block *sb, void *data, int silent)
|
static int libfs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
{
|
{
|
||||||
struct inode *root;
|
struct inode *root;
|
||||||
|
|
||||||
pr_info("statsfs: fill_super\n");
|
pr_info("statsfs: fill_super\n");
|
||||||
libfs_sb = sb;
|
libfs_sb = sb;
|
||||||
sb->s_magic = LIBFS_MAGIC;
|
sb->s_magic = LIBFS_MAGIC;
|
||||||
@ -312,7 +323,7 @@ static struct dentry *libfs_mount(struct file_system_type *fs,
|
|||||||
|
|
||||||
static void libfs_evict_inode(struct inode *inode)
|
static void libfs_evict_inode(struct inode *inode)
|
||||||
{
|
{
|
||||||
pr_info("statsfs: evict_inode inode #%lu\n", inode->i_ino);
|
pr_info("statsfs: evict_inode ino#%lu\n", inode->i_ino);
|
||||||
truncate_inode_pages_final(&inode->i_data);
|
truncate_inode_pages_final(&inode->i_data);
|
||||||
cleanup_links(inode);
|
cleanup_links(inode);
|
||||||
clear_inode(inode);
|
clear_inode(inode);
|
||||||
@ -320,7 +331,7 @@ static void libfs_evict_inode(struct inode *inode)
|
|||||||
|
|
||||||
static struct file_system_type libfs_type = {
|
static struct file_system_type libfs_type = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.name = "libfs",
|
.name = "statsfs",
|
||||||
.mount = libfs_mount,
|
.mount = libfs_mount,
|
||||||
.kill_sb = kill_litter_super,
|
.kill_sb = kill_litter_super,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user