Skip to content

Commit

Permalink
fs/ntfs3: Implement super_operations::shutdown
Browse files Browse the repository at this point in the history
[ Upstream commit 6c3684e ]

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
aalexandrovich authored and gregkh committed Mar 1, 2024
1 parent 7e0aff0 commit f73f939
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
18 changes: 18 additions & 0 deletions fs/ntfs3/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ static int ntfs_file_mmap(struct file *file, struct vm_area_struct *vma)
bool rw = vma->vm_flags & VM_WRITE;
int err;

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (is_encrypted(ni)) {
ntfs_inode_warn(inode, "mmap encrypted not supported");
return -EOPNOTSUPP;
Expand Down Expand Up @@ -677,6 +680,9 @@ int ntfs3_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
umode_t mode = inode->i_mode;
int err;

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

err = setattr_prepare(idmap, dentry, attr);
if (err)
goto out;
Expand Down Expand Up @@ -732,6 +738,9 @@ static ssize_t ntfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
struct inode *inode = file->f_mapping->host;
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (is_encrypted(ni)) {
ntfs_inode_warn(inode, "encrypted i/o not supported");
return -EOPNOTSUPP;
Expand Down Expand Up @@ -766,6 +775,9 @@ static ssize_t ntfs_file_splice_read(struct file *in, loff_t *ppos,
struct inode *inode = in->f_mapping->host;
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (is_encrypted(ni)) {
ntfs_inode_warn(inode, "encrypted i/o not supported");
return -EOPNOTSUPP;
Expand Down Expand Up @@ -1058,6 +1070,9 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
int err;
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (is_encrypted(ni)) {
ntfs_inode_warn(inode, "encrypted i/o not supported");
return -EOPNOTSUPP;
Expand Down Expand Up @@ -1118,6 +1133,9 @@ int ntfs_file_open(struct inode *inode, struct file *file)
{
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (unlikely((is_compressed(ni) || is_encrypted(ni)) &&
(file->f_flags & O_DIRECT))) {
return -EOPNOTSUPP;
Expand Down
3 changes: 3 additions & 0 deletions fs/ntfs3/frecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,9 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
if (is_bad_inode(inode) || sb_rdonly(sb))
return 0;

if (unlikely(ntfs3_forced_shutdown(sb)))
return -EIO;

if (!ni_trylock(ni)) {
/* 'ni' is under modification, skip for now. */
mark_inode_dirty_sync(inode);
Expand Down
21 changes: 19 additions & 2 deletions fs/ntfs3/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,13 @@ static int ntfs_resident_writepage(struct folio *folio,
struct writeback_control *wbc, void *data)
{
struct address_space *mapping = data;
struct ntfs_inode *ni = ntfs_i(mapping->host);
struct inode *inode = mapping->host;
struct ntfs_inode *ni = ntfs_i(inode);
int ret;

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

ni_lock(ni);
ret = attr_data_write_resident(ni, &folio->page);
ni_unlock(ni);
Expand All @@ -867,7 +871,12 @@ static int ntfs_resident_writepage(struct folio *folio,
static int ntfs_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
if (is_resident(ntfs_i(mapping->host)))
struct inode *inode = mapping->host;

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

if (is_resident(ntfs_i(inode)))
return write_cache_pages(mapping, wbc, ntfs_resident_writepage,
mapping);
return mpage_writepages(mapping, wbc, ntfs_get_block);
Expand All @@ -887,6 +896,9 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping,
struct inode *inode = mapping->host;
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

*pagep = NULL;
if (is_resident(ni)) {
struct page *page =
Expand Down Expand Up @@ -1303,6 +1315,11 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
goto out1;
}

if (unlikely(ntfs3_forced_shutdown(sb))) {
err = -EIO;
goto out2;
}

/* Mark rw ntfs as dirty. it will be cleared at umount. */
ntfs_set_state(sbi, NTFS_DIRTY_DIRTY);

Expand Down
12 changes: 12 additions & 0 deletions fs/ntfs3/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ static int ntfs_unlink(struct inode *dir, struct dentry *dentry)
struct ntfs_inode *ni = ntfs_i(dir);
int err;

if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
return -EIO;

ni_lock_dir(ni);

err = ntfs_unlink_inode(dir, dentry);
Expand All @@ -199,6 +202,9 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
u32 size = strlen(symname);
struct inode *inode;

if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
return -EIO;

inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
symname, size, NULL);

Expand Down Expand Up @@ -227,6 +233,9 @@ static int ntfs_rmdir(struct inode *dir, struct dentry *dentry)
struct ntfs_inode *ni = ntfs_i(dir);
int err;

if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
return -EIO;

ni_lock_dir(ni);

err = ntfs_unlink_inode(dir, dentry);
Expand Down Expand Up @@ -264,6 +273,9 @@ static int ntfs_rename(struct mnt_idmap *idmap, struct inode *dir,
1024);
static_assert(PATH_MAX >= 4 * 1024);

if (unlikely(ntfs3_forced_shutdown(sb)))
return -EIO;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

Expand Down
9 changes: 8 additions & 1 deletion fs/ntfs3/ntfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ enum utf16_endian;

/* sbi->flags */
#define NTFS_FLAGS_NODISCARD 0x00000001
/* ntfs in shutdown state. */
#define NTFS_FLAGS_SHUTDOWN 0x00000002
/* Set when LogFile is replaying. */
#define NTFS_FLAGS_LOG_REPLAYING 0x00000008
/* Set when we changed first MFT's which copy must be updated in $MftMirr. */
Expand Down Expand Up @@ -226,7 +228,7 @@ struct ntfs_sb_info {
u64 maxbytes; // Maximum size for normal files.
u64 maxbytes_sparse; // Maximum size for sparse file.

u32 flags; // See NTFS_FLAGS_XXX.
unsigned long flags; // See NTFS_FLAGS_

CLST zone_max; // Maximum MFT zone length in clusters
CLST bad_clusters; // The count of marked bad clusters.
Expand Down Expand Up @@ -999,6 +1001,11 @@ static inline struct ntfs_sb_info *ntfs_sb(struct super_block *sb)
return sb->s_fs_info;
}

static inline bool ntfs3_forced_shutdown(struct super_block *sb)
{
return test_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags);
}

/*
* ntfs_up_cluster - Align up on cluster boundary.
*/
Expand Down
12 changes: 12 additions & 0 deletions fs/ntfs3/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)
return 0;
}

/*
* ntfs_shutdown - super_operations::shutdown
*/
static void ntfs_shutdown(struct super_block *sb)
{
set_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags);
}

/*
* ntfs_sync_fs - super_operations::sync_fs
*/
Expand All @@ -724,6 +732,9 @@ static int ntfs_sync_fs(struct super_block *sb, int wait)
struct ntfs_inode *ni;
struct inode *inode;

if (unlikely(ntfs3_forced_shutdown(sb)))
return -EIO;

ni = sbi->security.ni;
if (ni) {
inode = &ni->vfs_inode;
Expand Down Expand Up @@ -763,6 +774,7 @@ static const struct super_operations ntfs_sops = {
.put_super = ntfs_put_super,
.statfs = ntfs_statfs,
.show_options = ntfs_show_options,
.shutdown = ntfs_shutdown,
.sync_fs = ntfs_sync_fs,
.write_inode = ntfs3_write_inode,
};
Expand Down
3 changes: 3 additions & 0 deletions fs/ntfs3/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
int err;
struct ntfs_inode *ni = ntfs_i(inode);

if (unlikely(ntfs3_forced_shutdown(inode->i_sb)))
return -EIO;

/* Dispatch request. */
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
/* system.dos_attrib */
Expand Down

0 comments on commit f73f939

Please sign in to comment.