Skip to content

Commit

Permalink
btrfs: add support for processing pending changes
Browse files Browse the repository at this point in the history
There are some actions that modify global filesystem state but cannot be
performed at the time of request, but later at the transaction commit
time when the filesystem is in a known state.

For example enabling new incompat features on-the-fly or issuing
transaction commit from unsafe contexts (sysfs handlers).

Signed-off-by: David Sterba <dsterba@suse.cz>
  • Loading branch information
David Sterba committed Nov 12, 2014
1 parent 206c5f6 commit 572d9ab
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
45 changes: 45 additions & 0 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,11 @@ struct btrfs_fs_info {
*/
u64 last_trans_log_full_commit;
unsigned long mount_opt;
/*
* Track requests for actions that need to be done during transaction
* commit (like for some mount options).
*/
unsigned long pending_changes;
unsigned long compress_type:4;
int commit_interval;
/*
Expand Down Expand Up @@ -2103,6 +2108,7 @@ struct btrfs_ioctl_defrag_range_args {
#define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
#define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
BTRFS_MOUNT_##opt)

#define btrfs_set_and_info(root, opt, fmt, args...) \
{ \
if (!btrfs_test_opt(root, opt)) \
Expand All @@ -2117,6 +2123,45 @@ struct btrfs_ioctl_defrag_range_args {
btrfs_clear_opt(root->fs_info->mount_opt, opt); \
}

/*
* Requests for changes that need to be done during transaction commit.
*
* Internal mount options that are used for special handling of the real
* mount options (eg. cannot be set during remount and have to be set during
* transaction commit)
*/

#define btrfs_test_pending(info, opt) \
test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_set_pending(info, opt) \
set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_clear_pending(info, opt) \
clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)

/*
* Helpers for setting pending mount option changes.
*
* Expects corresponding macros
* BTRFS_PENDING_SET_ and CLEAR_ + short mount option name
*/
#define btrfs_set_pending_and_info(info, opt, fmt, args...) \
do { \
if (!btrfs_raw_test_opt((info)->mount_opt, opt)) { \
btrfs_info((info), fmt, ##args); \
btrfs_set_pending((info), SET_##opt); \
btrfs_clear_pending((info), CLEAR_##opt); \
} \
} while(0)

#define btrfs_clear_pending_and_info(info, opt, fmt, args...) \
do { \
if (btrfs_raw_test_opt((info)->mount_opt, opt)) { \
btrfs_info((info), fmt, ##args); \
btrfs_set_pending((info), CLEAR_##opt); \
btrfs_clear_pending((info), SET_##opt); \
} \
} while(0)

/*
* Inode flags
*/
Expand Down
6 changes: 6 additions & 0 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,12 @@ int open_ctree(struct super_block *sb,
if (btrfs_test_opt(tree_root, CHANGE_INODE_CACHE))
btrfs_set_opt(tree_root->fs_info->mount_opt, INODE_MAP_CACHE);

/*
* Mount does not set all options immediatelly, we can do it now and do
* not have to wait for transaction commit
*/
btrfs_apply_pending_changes(fs_info);

#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
ret = btrfsic_mount(tree_root, fs_devices,
Expand Down
16 changes: 16 additions & 0 deletions fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
else
btrfs_clear_opt(root->fs_info->mount_opt, INODE_MAP_CACHE);

btrfs_apply_pending_changes(root->fs_info);

/* commit_fs_roots gets rid of all the tree log roots, it is now
* safe to free the root of tree log roots
*/
Expand Down Expand Up @@ -2019,3 +2021,17 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root)

return (ret < 0) ? 0 : 1;
}

void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info)
{
unsigned long prev;
unsigned long bit;

prev = cmpxchg(&fs_info->pending_changes, 0, 0);
if (!prev)
return;

if (prev)
btrfs_warn(fs_info,
"unknown pending changes left 0x%lx, ignoring", prev);
}
2 changes: 2 additions & 0 deletions fs/btrfs/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,6 @@ int btrfs_wait_marked_extents(struct btrfs_root *root,
int btrfs_transaction_blocked(struct btrfs_fs_info *info);
int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
void btrfs_put_transaction(struct btrfs_transaction *transaction);
void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info);

#endif

0 comments on commit 572d9ab

Please sign in to comment.