···168168 notreelog169169 Enable/disable the tree logging used for fsync and O_SYNC writes.170170171171- recovery172172- Enable autorecovery attempts if a bad tree root is found at mount time.173173- Currently this scans a list of several previous tree roots and tries to171171+ nologreplay172172+ Disable the log tree replay at mount time to prevent filesystem173173+ from getting modified.174174+ Must be used with 'ro' mount option.175175+ A filesystem mounted with this option cannot transition to a176176+ read-write mount via remount,rw - the filesystem must be unmounted177177+ and mounted back again if read-write access is desired.178178+179179+ usebackuproot180180+ Enable attempts to use backup tree roots if a bad tree root is found at181181+ mount time.182182+ Currently this scans a list of 4 previous tree roots and tries to174183 use the first readable.184184+ And since the mount option doesn't affect any behavior after mount,185185+ it won't be shown in mount info.186186+ Prior to 4.6, this was done by 'recovery' option that has been187187+ deprecated, but will work.175188176189 rescan_uuid_tree177190 Force check and rebuild procedure of the UUID tree. This should not
···311311312312struct tree_mod_elem {313313 struct rb_node node;314314- u64 index; /* shifted logical */314314+ u64 logical;315315 u64 seq;316316 enum mod_log_op op;317317···435435436436/*437437 * key order of the log:438438- * index -> sequence438438+ * node/leaf start address -> sequence439439 *440440- * the index is the shifted logical of the *new* root node for root replace441441- * operations, or the shifted logical of the affected block for all other442442- * operations.440440+ * The 'start address' is the logical address of the *new* root node441441+ * for root replace operations, or the logical address of the affected442442+ * block for all other operations.443443 *444444 * Note: must be called with write lock (tree_mod_log_write_lock).445445 */···460460 while (*new) {461461 cur = container_of(*new, struct tree_mod_elem, node);462462 parent = *new;463463- if (cur->index < tm->index)463463+ if (cur->logical < tm->logical)464464 new = &((*new)->rb_left);465465- else if (cur->index > tm->index)465465+ else if (cur->logical > tm->logical)466466 new = &((*new)->rb_right);467467 else if (cur->seq < tm->seq)468468 new = &((*new)->rb_left);···523523 if (!tm)524524 return NULL;525525526526- tm->index = eb->start >> PAGE_CACHE_SHIFT;526526+ tm->logical = eb->start;527527 if (op != MOD_LOG_KEY_ADD) {528528 btrfs_node_key(eb, &tm->key, slot);529529 tm->blockptr = btrfs_node_blockptr(eb, slot);···588588 goto free_tms;589589 }590590591591- tm->index = eb->start >> PAGE_CACHE_SHIFT;591591+ tm->logical = eb->start;592592 tm->slot = src_slot;593593 tm->move.dst_slot = dst_slot;594594 tm->move.nr_items = nr_items;···699699 goto free_tms;700700 }701701702702- tm->index = new_root->start >> PAGE_CACHE_SHIFT;702702+ tm->logical = new_root->start;703703 tm->old_root.logical = old_root->start;704704 tm->old_root.level = btrfs_header_level(old_root);705705 tm->generation = btrfs_header_generation(old_root);···739739 struct rb_node *node;740740 struct tree_mod_elem *cur = NULL;741741 struct tree_mod_elem *found = NULL;742742- u64 index = start >> PAGE_CACHE_SHIFT;743742744743 tree_mod_log_read_lock(fs_info);745744 tm_root = &fs_info->tree_mod_log;746745 node = tm_root->rb_node;747746 while (node) {748747 cur = container_of(node, struct tree_mod_elem, node);749749- if (cur->index < index) {748748+ if (cur->logical < start) {750749 node = node->rb_left;751751- } else if (cur->index > index) {750750+ } else if (cur->logical > start) {752751 node = node->rb_right;753752 } else if (cur->seq < min_seq) {754753 node = node->rb_left;···12291230 return NULL;1230123112311232 /*12321232- * the very last operation that's logged for a root is the replacement12331233- * operation (if it is replaced at all). this has the index of the *new*12341234- * root, making it the very first operation that's logged for this root.12331233+ * the very last operation that's logged for a root is the12341234+ * replacement operation (if it is replaced at all). this has12351235+ * the logical address of the *new* root, making it the very12361236+ * first operation that's logged for this root.12351237 */12361238 while (1) {12371239 tm = tree_mod_log_search_oldest(fs_info, root_logical,···13361336 if (!next)13371337 break;13381338 tm = container_of(next, struct tree_mod_elem, node);13391339- if (tm->index != first_tm->index)13391339+ if (tm->logical != first_tm->logical)13401340 break;13411341 }13421342 tree_mod_log_read_unlock(fs_info);···53615361 goto out;53625362 }5363536353645364- tmp_buf = kmalloc(left_root->nodesize, GFP_NOFS);53645364+ tmp_buf = kmalloc(left_root->nodesize, GFP_KERNEL);53655365 if (!tmp_buf) {53665366 ret = -ENOMEM;53675367 goto out;
+56-13
fs/btrfs/ctree.h
···100100/* tracks free space in block groups. */101101#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL102102103103+/* device stats in the device tree */104104+#define BTRFS_DEV_STATS_OBJECTID 0ULL105105+103106/* for storing balance parameters in the root tree */104107#define BTRFS_BALANCE_OBJECTID -4ULL105108···10051002 pid_t lock_owner;10061003 atomic_t nesting_level;10071004 struct mutex lock_finishing_cancel_unmount;10081008- struct mutex lock_management_lock;10091009- struct mutex lock;10051005+ rwlock_t lock;10061006+ atomic_t read_locks;10071007+ atomic_t blocking_readers;10081008+ wait_queue_head_t read_lock_wq;1010100910111010 struct btrfs_scrub_progress scrub_progress;10121011};···18271822 spinlock_t reada_lock;18281823 struct radix_tree_root reada_tree;1829182418251825+ /* readahead works cnt */18261826+ atomic_t reada_works_cnt;18271827+18301828 /* Extent buffer radix tree */18311829 spinlock_t buffer_lock;18321830 struct radix_tree_root buffer_radix;···21932185 */21942186#define BTRFS_QGROUP_RELATION_KEY 2462195218721882188+/*21892189+ * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY.21902190+ */21962191#define BTRFS_BALANCE_ITEM_KEY 2482197219221982193/*21992199- * Persistantly stores the io stats in the device tree.22002200- * One key for all stats, (0, BTRFS_DEV_STATS_KEY, devid).21942194+ * The key type for tree items that are stored persistently, but do not need to21952195+ * exist for extended period of time. The items can exist in any tree.21962196+ *21972197+ * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]21982198+ *21992199+ * Existing items:22002200+ *22012201+ * - balance status item22022202+ * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)22012203 */22022202-#define BTRFS_DEV_STATS_KEY 24922042204+#define BTRFS_TEMPORARY_ITEM_KEY 24822052205+22062206+/*22072207+ * Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY22082208+ */22092209+#define BTRFS_DEV_STATS_KEY 24922102210+22112211+/*22122212+ * The key type for tree items that are stored persistently and usually exist22132213+ * for a long period, eg. filesystem lifetime. The item kinds can be status22142214+ * information, stats or preference values. The item can exist in any tree.22152215+ *22162216+ * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]22172217+ *22182218+ * Existing items:22192219+ *22202220+ * - device statistics, store IO stats in the device tree, one key for all22212221+ * stats22222222+ * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)22232223+ */22242224+#define BTRFS_PERSISTENT_ITEM_KEY 2492203222522042226/*22052227 * Persistantly stores the device replace state in the device tree.···22792241#define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15)22802242#define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16)22812243#define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17)22822282-#define BTRFS_MOUNT_RECOVERY (1 << 18)22442244+#define BTRFS_MOUNT_USEBACKUPROOT (1 << 18)22832245#define BTRFS_MOUNT_SKIP_BALANCE (1 << 19)22842246#define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20)22852247#define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)···22882250#define BTRFS_MOUNT_FRAGMENT_DATA (1 << 24)22892251#define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25)22902252#define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)22532253+#define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)2291225422922255#define BTRFS_DEFAULT_COMMIT_INTERVAL (30)22932293-#define BTRFS_DEFAULT_MAX_INLINE (8192)22562256+#define BTRFS_DEFAULT_MAX_INLINE (2048)2294225722952258#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)22962259#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)···23912352 char *kaddr;23922353 unsigned long offset;23932354};23552355+23562356+#define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \23572357+ ((bytes) >> (fs_info)->sb->s_blocksize_bits)2394235823952359static inline void btrfs_init_map_token (struct btrfs_map_token *token)23962360{···34903448static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,34913449 unsigned num_items)34923450{34933493- return (root->nodesize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *34943494- 2 * num_items;34513451+ return root->nodesize * BTRFS_MAX_LEVEL * 2 * num_items;34953452}3496345334973454/*···40684027 struct btrfs_root *root,40694028 struct inode *dir, u64 objectid,40704029 const char *name, int name_len);40714071-int btrfs_truncate_page(struct inode *inode, loff_t from, loff_t len,40304030+int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,40724031 int front);40734032int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,40744033 struct btrfs_root *root,···4130408941314090/* ioctl.c */41324091long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);40924092+int btrfs_ioctl_get_supported_features(void __user *arg);41334093void btrfs_update_iflags(struct inode *inode);41344094void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);41354095int btrfs_is_empty_uuid(u8 *uuid);···41934151ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);4194415241954153/* super.c */41964196-int btrfs_parse_options(struct btrfs_root *root, char *options);41544154+int btrfs_parse_options(struct btrfs_root *root, char *options,41554155+ unsigned long new_flags);41974156int btrfs_sync_fs(struct super_block *sb, int wait);4198415741994158#ifdef CONFIG_PRINTK···45684525 struct btrfs_key *start, struct btrfs_key *end);45694526int btrfs_reada_wait(void *handle);45704527void btrfs_reada_detach(void *handle);45714571-int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,45724572- u64 start, int err);45284528+int btree_readahead_hook(struct btrfs_fs_info *fs_info,45294529+ struct extent_buffer *eb, u64 start, int err);4573453045744531static inline int is_fstree(u64 rootid)45754532{
+1-2
fs/btrfs/delayed-inode.c
···43434444void btrfs_delayed_inode_exit(void)4545{4646- if (delayed_node_cache)4747- kmem_cache_destroy(delayed_node_cache);4646+ kmem_cache_destroy(delayed_node_cache);4847}49485049static inline void btrfs_init_delayed_node(
+4-8
fs/btrfs/delayed-ref.c
···929929930930void btrfs_delayed_ref_exit(void)931931{932932- if (btrfs_delayed_ref_head_cachep)933933- kmem_cache_destroy(btrfs_delayed_ref_head_cachep);934934- if (btrfs_delayed_tree_ref_cachep)935935- kmem_cache_destroy(btrfs_delayed_tree_ref_cachep);936936- if (btrfs_delayed_data_ref_cachep)937937- kmem_cache_destroy(btrfs_delayed_data_ref_cachep);938938- if (btrfs_delayed_extent_op_cachep)939939- kmem_cache_destroy(btrfs_delayed_extent_op_cachep);932932+ kmem_cache_destroy(btrfs_delayed_ref_head_cachep);933933+ kmem_cache_destroy(btrfs_delayed_tree_ref_cachep);934934+ kmem_cache_destroy(btrfs_delayed_data_ref_cachep);935935+ kmem_cache_destroy(btrfs_delayed_extent_op_cachep);940936}941937942938int btrfs_delayed_ref_init(void)
+72-62
fs/btrfs/dev-replace.c
···202202 struct btrfs_dev_replace_item *ptr;203203 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;204204205205- btrfs_dev_replace_lock(dev_replace);205205+ btrfs_dev_replace_lock(dev_replace, 0);206206 if (!dev_replace->is_valid ||207207 !dev_replace->item_needs_writeback) {208208- btrfs_dev_replace_unlock(dev_replace);208208+ btrfs_dev_replace_unlock(dev_replace, 0);209209 return 0;210210 }211211- btrfs_dev_replace_unlock(dev_replace);211211+ btrfs_dev_replace_unlock(dev_replace, 0);212212213213 key.objectid = 0;214214 key.type = BTRFS_DEV_REPLACE_KEY;···264264 ptr = btrfs_item_ptr(eb, path->slots[0],265265 struct btrfs_dev_replace_item);266266267267- btrfs_dev_replace_lock(dev_replace);267267+ btrfs_dev_replace_lock(dev_replace, 1);268268 if (dev_replace->srcdev)269269 btrfs_set_dev_replace_src_devid(eb, ptr,270270 dev_replace->srcdev->devid);···287287 btrfs_set_dev_replace_cursor_right(eb, ptr,288288 dev_replace->cursor_right);289289 dev_replace->item_needs_writeback = 0;290290- btrfs_dev_replace_unlock(dev_replace);290290+ btrfs_dev_replace_unlock(dev_replace, 1);291291292292 btrfs_mark_buffer_dirty(eb);293293···356356 return PTR_ERR(trans);357357 }358358359359- btrfs_dev_replace_lock(dev_replace);359359+ btrfs_dev_replace_lock(dev_replace, 1);360360 switch (dev_replace->replace_state) {361361 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:362362 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:···395395 dev_replace->is_valid = 1;396396 dev_replace->item_needs_writeback = 1;397397 args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;398398- btrfs_dev_replace_unlock(dev_replace);398398+ btrfs_dev_replace_unlock(dev_replace, 1);399399400400 ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);401401 if (ret)···407407 trans = btrfs_start_transaction(root, 0);408408 if (IS_ERR(trans)) {409409 ret = PTR_ERR(trans);410410- btrfs_dev_replace_lock(dev_replace);410410+ btrfs_dev_replace_lock(dev_replace, 1);411411 goto leave;412412 }413413···433433leave:434434 dev_replace->srcdev = NULL;435435 dev_replace->tgtdev = NULL;436436- btrfs_dev_replace_unlock(dev_replace);436436+ btrfs_dev_replace_unlock(dev_replace, 1);437437 btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);438438 return ret;439439}···471471 /* don't allow cancel or unmount to disturb the finishing procedure */472472 mutex_lock(&dev_replace->lock_finishing_cancel_unmount);473473474474- btrfs_dev_replace_lock(dev_replace);474474+ btrfs_dev_replace_lock(dev_replace, 0);475475 /* was the operation canceled, or is it finished? */476476 if (dev_replace->replace_state !=477477 BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED) {478478- btrfs_dev_replace_unlock(dev_replace);478478+ btrfs_dev_replace_unlock(dev_replace, 0);479479 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);480480 return 0;481481 }482482483483 tgt_device = dev_replace->tgtdev;484484 src_device = dev_replace->srcdev;485485- btrfs_dev_replace_unlock(dev_replace);485485+ btrfs_dev_replace_unlock(dev_replace, 0);486486487487 /*488488 * flush all outstanding I/O and inode extent mappings before the···507507 /* keep away write_all_supers() during the finishing procedure */508508 mutex_lock(&root->fs_info->fs_devices->device_list_mutex);509509 mutex_lock(&root->fs_info->chunk_mutex);510510- btrfs_dev_replace_lock(dev_replace);510510+ btrfs_dev_replace_lock(dev_replace, 1);511511 dev_replace->replace_state =512512 scrub_ret ? BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED513513 : BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED;···528528 rcu_str_deref(src_device->name),529529 src_device->devid,530530 rcu_str_deref(tgt_device->name), scrub_ret);531531- btrfs_dev_replace_unlock(dev_replace);531531+ btrfs_dev_replace_unlock(dev_replace, 1);532532 mutex_unlock(&root->fs_info->chunk_mutex);533533 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);534534 mutex_unlock(&uuid_mutex);···565565 list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list);566566 fs_info->fs_devices->rw_devices++;567567568568- btrfs_dev_replace_unlock(dev_replace);568568+ btrfs_dev_replace_unlock(dev_replace, 1);569569570570 btrfs_rm_dev_replace_blocked(fs_info);571571···649649 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;650650 struct btrfs_device *srcdev;651651652652- btrfs_dev_replace_lock(dev_replace);652652+ btrfs_dev_replace_lock(dev_replace, 0);653653 /* even if !dev_replace_is_valid, the values are good enough for654654 * the replace_status ioctl */655655 args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;···675675 div_u64(btrfs_device_get_total_bytes(srcdev), 1000));676676 break;677677 }678678- btrfs_dev_replace_unlock(dev_replace);678678+ btrfs_dev_replace_unlock(dev_replace, 0);679679}680680681681int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info,···698698 return -EROFS;699699700700 mutex_lock(&dev_replace->lock_finishing_cancel_unmount);701701- btrfs_dev_replace_lock(dev_replace);701701+ btrfs_dev_replace_lock(dev_replace, 1);702702 switch (dev_replace->replace_state) {703703 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:704704 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:705705 case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED:706706 result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED;707707- btrfs_dev_replace_unlock(dev_replace);707707+ btrfs_dev_replace_unlock(dev_replace, 1);708708 goto leave;709709 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:710710 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:···717717 dev_replace->replace_state = BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED;718718 dev_replace->time_stopped = get_seconds();719719 dev_replace->item_needs_writeback = 1;720720- btrfs_dev_replace_unlock(dev_replace);720720+ btrfs_dev_replace_unlock(dev_replace, 1);721721 btrfs_scrub_cancel(fs_info);722722723723 trans = btrfs_start_transaction(root, 0);···740740 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;741741742742 mutex_lock(&dev_replace->lock_finishing_cancel_unmount);743743- btrfs_dev_replace_lock(dev_replace);743743+ btrfs_dev_replace_lock(dev_replace, 1);744744 switch (dev_replace->replace_state) {745745 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:746746 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:···756756 break;757757 }758758759759- btrfs_dev_replace_unlock(dev_replace);759759+ btrfs_dev_replace_unlock(dev_replace, 1);760760 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);761761}762762···766766 struct task_struct *task;767767 struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;768768769769- btrfs_dev_replace_lock(dev_replace);769769+ btrfs_dev_replace_lock(dev_replace, 1);770770 switch (dev_replace->replace_state) {771771 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:772772 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:773773 case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED:774774- btrfs_dev_replace_unlock(dev_replace);774774+ btrfs_dev_replace_unlock(dev_replace, 1);775775 return 0;776776 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:777777 break;···784784 btrfs_info(fs_info, "cannot continue dev_replace, tgtdev is missing");785785 btrfs_info(fs_info,786786 "you may cancel the operation after 'mount -o degraded'");787787- btrfs_dev_replace_unlock(dev_replace);787787+ btrfs_dev_replace_unlock(dev_replace, 1);788788 return 0;789789 }790790- btrfs_dev_replace_unlock(dev_replace);790790+ btrfs_dev_replace_unlock(dev_replace, 1);791791792792 WARN_ON(atomic_xchg(793793 &fs_info->mutually_exclusive_operation_running, 1));···802802 struct btrfs_ioctl_dev_replace_args *status_args;803803 u64 progress;804804805805- status_args = kzalloc(sizeof(*status_args), GFP_NOFS);805805+ status_args = kzalloc(sizeof(*status_args), GFP_KERNEL);806806 if (status_args) {807807 btrfs_dev_replace_status(fs_info, status_args);808808 progress = status_args->status.progress_1000;···865865 return 1;866866}867867868868-void btrfs_dev_replace_lock(struct btrfs_dev_replace *dev_replace)868868+void btrfs_dev_replace_lock(struct btrfs_dev_replace *dev_replace, int rw)869869{870870- /* the beginning is just an optimization for the typical case */871871- if (atomic_read(&dev_replace->nesting_level) == 0) {872872-acquire_lock:873873- /* this is not a nested case where the same thread874874- * is trying to acqurire the same lock twice */875875- mutex_lock(&dev_replace->lock);876876- mutex_lock(&dev_replace->lock_management_lock);877877- dev_replace->lock_owner = current->pid;878878- atomic_inc(&dev_replace->nesting_level);879879- mutex_unlock(&dev_replace->lock_management_lock);880880- return;870870+ if (rw == 1) {871871+ /* write */872872+again:873873+ wait_event(dev_replace->read_lock_wq,874874+ atomic_read(&dev_replace->blocking_readers) == 0);875875+ write_lock(&dev_replace->lock);876876+ if (atomic_read(&dev_replace->blocking_readers)) {877877+ write_unlock(&dev_replace->lock);878878+ goto again;879879+ }880880+ } else {881881+ read_lock(&dev_replace->lock);882882+ atomic_inc(&dev_replace->read_locks);881883 }882882-883883- mutex_lock(&dev_replace->lock_management_lock);884884- if (atomic_read(&dev_replace->nesting_level) > 0 &&885885- dev_replace->lock_owner == current->pid) {886886- WARN_ON(!mutex_is_locked(&dev_replace->lock));887887- atomic_inc(&dev_replace->nesting_level);888888- mutex_unlock(&dev_replace->lock_management_lock);889889- return;890890- }891891-892892- mutex_unlock(&dev_replace->lock_management_lock);893893- goto acquire_lock;894884}895885896896-void btrfs_dev_replace_unlock(struct btrfs_dev_replace *dev_replace)886886+void btrfs_dev_replace_unlock(struct btrfs_dev_replace *dev_replace, int rw)897887{898898- WARN_ON(!mutex_is_locked(&dev_replace->lock));899899- mutex_lock(&dev_replace->lock_management_lock);900900- WARN_ON(atomic_read(&dev_replace->nesting_level) < 1);901901- WARN_ON(dev_replace->lock_owner != current->pid);902902- atomic_dec(&dev_replace->nesting_level);903903- if (atomic_read(&dev_replace->nesting_level) == 0) {904904- dev_replace->lock_owner = 0;905905- mutex_unlock(&dev_replace->lock_management_lock);906906- mutex_unlock(&dev_replace->lock);888888+ if (rw == 1) {889889+ /* write */890890+ ASSERT(atomic_read(&dev_replace->blocking_readers) == 0);891891+ write_unlock(&dev_replace->lock);907892 } else {908908- mutex_unlock(&dev_replace->lock_management_lock);893893+ ASSERT(atomic_read(&dev_replace->read_locks) > 0);894894+ atomic_dec(&dev_replace->read_locks);895895+ read_unlock(&dev_replace->lock);909896 }897897+}898898+899899+/* inc blocking cnt and release read lock */900900+void btrfs_dev_replace_set_lock_blocking(901901+ struct btrfs_dev_replace *dev_replace)902902+{903903+ /* only set blocking for read lock */904904+ ASSERT(atomic_read(&dev_replace->read_locks) > 0);905905+ atomic_inc(&dev_replace->blocking_readers);906906+ read_unlock(&dev_replace->lock);907907+}908908+909909+/* acquire read lock and dec blocking cnt */910910+void btrfs_dev_replace_clear_lock_blocking(911911+ struct btrfs_dev_replace *dev_replace)912912+{913913+ /* only set blocking for read lock */914914+ ASSERT(atomic_read(&dev_replace->read_locks) > 0);915915+ ASSERT(atomic_read(&dev_replace->blocking_readers) > 0);916916+ read_lock(&dev_replace->lock);917917+ if (atomic_dec_and_test(&dev_replace->blocking_readers) &&918918+ waitqueue_active(&dev_replace->read_lock_wq))919919+ wake_up(&dev_replace->read_lock_wq);910920}911921912922void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info)
···461461 struct btrfs_fs_info *fs_info = dev->dev_root->fs_info;462462 int ret;463463464464- sctx = kzalloc(sizeof(*sctx), GFP_NOFS);464464+ sctx = kzalloc(sizeof(*sctx), GFP_KERNEL);465465 if (!sctx)466466 goto nomem;467467 atomic_set(&sctx->refs, 1);···472472 for (i = 0; i < SCRUB_BIOS_PER_SCTX; ++i) {473473 struct scrub_bio *sbio;474474475475- sbio = kzalloc(sizeof(*sbio), GFP_NOFS);475475+ sbio = kzalloc(sizeof(*sbio), GFP_KERNEL);476476 if (!sbio)477477 goto nomem;478478 sctx->bios[i] = sbio;···16541654again:16551655 if (!wr_ctx->wr_curr_bio) {16561656 wr_ctx->wr_curr_bio = kzalloc(sizeof(*wr_ctx->wr_curr_bio),16571657- GFP_NOFS);16571657+ GFP_KERNEL);16581658 if (!wr_ctx->wr_curr_bio) {16591659 mutex_unlock(&wr_ctx->wr_lock);16601660 return -ENOMEM;···16711671 sbio->dev = wr_ctx->tgtdev;16721672 bio = sbio->bio;16731673 if (!bio) {16741674- bio = btrfs_io_bio_alloc(GFP_NOFS, wr_ctx->pages_per_wr_bio);16741674+ bio = btrfs_io_bio_alloc(GFP_KERNEL,16751675+ wr_ctx->pages_per_wr_bio);16751676 if (!bio) {16761677 mutex_unlock(&wr_ctx->wr_lock);16771678 return -ENOMEM;···20772076 sbio->dev = spage->dev;20782077 bio = sbio->bio;20792078 if (!bio) {20802080- bio = btrfs_io_bio_alloc(GFP_NOFS, sctx->pages_per_rd_bio);20792079+ bio = btrfs_io_bio_alloc(GFP_KERNEL,20802080+ sctx->pages_per_rd_bio);20812081 if (!bio)20822082 return -ENOMEM;20832083 sbio->bio = bio;···22432241 struct scrub_block *sblock;22442242 int index;2245224322462246- sblock = kzalloc(sizeof(*sblock), GFP_NOFS);22442244+ sblock = kzalloc(sizeof(*sblock), GFP_KERNEL);22472245 if (!sblock) {22482246 spin_lock(&sctx->stat_lock);22492247 sctx->stat.malloc_errors++;···22612259 struct scrub_page *spage;22622260 u64 l = min_t(u64, len, PAGE_SIZE);2263226122642264- spage = kzalloc(sizeof(*spage), GFP_NOFS);22622262+ spage = kzalloc(sizeof(*spage), GFP_KERNEL);22652263 if (!spage) {22662264leave_nomem:22672265 spin_lock(&sctx->stat_lock);···22882286 spage->have_csum = 0;22892287 }22902288 sblock->page_count++;22912291- spage->page = alloc_page(GFP_NOFS);22892289+ spage->page = alloc_page(GFP_KERNEL);22922290 if (!spage->page)22932291 goto leave_nomem;22942292 len -= l;···25432541 struct scrub_block *sblock;25442542 int index;2545254325462546- sblock = kzalloc(sizeof(*sblock), GFP_NOFS);25442544+ sblock = kzalloc(sizeof(*sblock), GFP_KERNEL);25472545 if (!sblock) {25482546 spin_lock(&sctx->stat_lock);25492547 sctx->stat.malloc_errors++;···25632561 struct scrub_page *spage;25642562 u64 l = min_t(u64, len, PAGE_SIZE);2565256325662566- spage = kzalloc(sizeof(*spage), GFP_NOFS);25642564+ spage = kzalloc(sizeof(*spage), GFP_KERNEL);25672565 if (!spage) {25682566leave_nomem:25692567 spin_lock(&sctx->stat_lock);···25932591 spage->have_csum = 0;25942592 }25952593 sblock->page_count++;25962596- spage->page = alloc_page(GFP_NOFS);25942594+ spage->page = alloc_page(GFP_KERNEL);25972595 if (!spage->page)25982596 goto leave_nomem;25992597 len -= l;···38593857 return -EIO;38603858 }3861385938623862- btrfs_dev_replace_lock(&fs_info->dev_replace);38603860+ btrfs_dev_replace_lock(&fs_info->dev_replace, 0);38633861 if (dev->scrub_device ||38643862 (!is_dev_replace &&38653863 btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))) {38663866- btrfs_dev_replace_unlock(&fs_info->dev_replace);38643864+ btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);38673865 mutex_unlock(&fs_info->scrub_lock);38683866 mutex_unlock(&fs_info->fs_devices->device_list_mutex);38693867 return -EINPROGRESS;38703868 }38713871- btrfs_dev_replace_unlock(&fs_info->dev_replace);38693869+ btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);3872387038733871 ret = scrub_workers_get(fs_info, is_dev_replace);38743872 if (ret) {
+18-18
fs/btrfs/send.c
···304304{305305 struct fs_path *p;306306307307- p = kmalloc(sizeof(*p), GFP_NOFS);307307+ p = kmalloc(sizeof(*p), GFP_KERNEL);308308 if (!p)309309 return NULL;310310 p->reversed = 0;···363363 * First time the inline_buf does not suffice364364 */365365 if (p->buf == p->inline_buf) {366366- tmp_buf = kmalloc(len, GFP_NOFS);366366+ tmp_buf = kmalloc(len, GFP_KERNEL);367367 if (tmp_buf)368368 memcpy(tmp_buf, p->buf, old_buf_len);369369 } else {370370- tmp_buf = krealloc(p->buf, len, GFP_NOFS);370370+ tmp_buf = krealloc(p->buf, len, GFP_KERNEL);371371 }372372 if (!tmp_buf)373373 return -ENOMEM;···995995 * values are small.996996 */997997 buf_len = PATH_MAX;998998- buf = kmalloc(buf_len, GFP_NOFS);998998+ buf = kmalloc(buf_len, GFP_KERNEL);999999 if (!buf) {10001000 ret = -ENOMEM;10011001 goto out;···10421042 buf = NULL;10431043 } else {10441044 char *tmp = krealloc(buf, buf_len,10451045- GFP_NOFS | __GFP_NOWARN);10451045+ GFP_KERNEL | __GFP_NOWARN);1046104610471047 if (!tmp)10481048 kfree(buf);···13031303 /* We only use this path under the commit sem */13041304 tmp_path->need_commit_sem = 0;1305130513061306- backref_ctx = kmalloc(sizeof(*backref_ctx), GFP_NOFS);13061306+ backref_ctx = kmalloc(sizeof(*backref_ctx), GFP_KERNEL);13071307 if (!backref_ctx) {13081308 ret = -ENOMEM;13091309 goto out;···19841984 nce_head = radix_tree_lookup(&sctx->name_cache,19851985 (unsigned long)nce->ino);19861986 if (!nce_head) {19871987- nce_head = kmalloc(sizeof(*nce_head), GFP_NOFS);19871987+ nce_head = kmalloc(sizeof(*nce_head), GFP_KERNEL);19881988 if (!nce_head) {19891989 kfree(nce);19901990 return -ENOMEM;···21792179 /*21802180 * Store the result of the lookup in the name cache.21812181 */21822182- nce = kmalloc(sizeof(*nce) + fs_path_len(dest) + 1, GFP_NOFS);21822182+ nce = kmalloc(sizeof(*nce) + fs_path_len(dest) + 1, GFP_KERNEL);21832183 if (!nce) {21842184 ret = -ENOMEM;21852185 goto out;···23152315 if (!path)23162316 return -ENOMEM;2317231723182318- name = kmalloc(BTRFS_PATH_NAME_MAX, GFP_NOFS);23182318+ name = kmalloc(BTRFS_PATH_NAME_MAX, GFP_KERNEL);23192319 if (!name) {23202320 btrfs_free_path(path);23212321 return -ENOMEM;···27302730{27312731 struct recorded_ref *ref;2732273227332733- ref = kmalloc(sizeof(*ref), GFP_NOFS);27332733+ ref = kmalloc(sizeof(*ref), GFP_KERNEL);27342734 if (!ref)27352735 return -ENOMEM;27362736···27552755{27562756 struct recorded_ref *new;2757275727582758- new = kmalloc(sizeof(*ref), GFP_NOFS);27582758+ new = kmalloc(sizeof(*ref), GFP_KERNEL);27592759 if (!new)27602760 return -ENOMEM;27612761···28182818 struct rb_node *parent = NULL;28192819 struct orphan_dir_info *entry, *odi;2820282028212821- odi = kmalloc(sizeof(*odi), GFP_NOFS);28212821+ odi = kmalloc(sizeof(*odi), GFP_KERNEL);28222822 if (!odi)28232823 return ERR_PTR(-ENOMEM);28242824 odi->ino = dir_ino;···29732973 struct rb_node *parent = NULL;29742974 struct waiting_dir_move *entry, *dm;2975297529762976- dm = kmalloc(sizeof(*dm), GFP_NOFS);29762976+ dm = kmalloc(sizeof(*dm), GFP_KERNEL);29772977 if (!dm)29782978 return -ENOMEM;29792979 dm->ino = ino;···30403040 int exists = 0;30413041 int ret;3042304230433043- pm = kmalloc(sizeof(*pm), GFP_NOFS);30433043+ pm = kmalloc(sizeof(*pm), GFP_KERNEL);30443044 if (!pm)30453045 return -ENOMEM;30463046 pm->parent_ino = parent_ino;···42804280 strncmp(name, ctx->name, name_len) == 0) {42814281 ctx->found_idx = num;42824282 ctx->found_data_len = data_len;42834283- ctx->found_data = kmemdup(data, data_len, GFP_NOFS);42834283+ ctx->found_data = kmemdup(data, data_len, GFP_KERNEL);42844284 if (!ctx->found_data)42854285 return -ENOMEM;42864286 return 1;···44814481 while (index <= last_index) {44824482 unsigned cur_len = min_t(unsigned, len,44834483 PAGE_CACHE_SIZE - pg_offset);44844484- page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);44844484+ page = find_or_create_page(inode->i_mapping, index, GFP_KERNEL);44854485 if (!page) {44864486 ret = -ENOMEM;44874487 break;···59895989 goto out;59905990 }5991599159925992- sctx = kzalloc(sizeof(struct send_ctx), GFP_NOFS);59925992+ sctx = kzalloc(sizeof(struct send_ctx), GFP_KERNEL);59935993 if (!sctx) {59945994 ret = -ENOMEM;59955995 goto out;···5997599759985998 INIT_LIST_HEAD(&sctx->new_refs);59995999 INIT_LIST_HEAD(&sctx->deleted_refs);60006000- INIT_RADIX_TREE(&sctx->name_cache, GFP_NOFS);60006000+ INIT_RADIX_TREE(&sctx->name_cache, GFP_KERNEL);60016001 INIT_LIST_HEAD(&sctx->name_cache_list);6002600260036003 sctx->flags = arg->flags;
+39-9
fs/btrfs/super.c
···303303 Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,304304 Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,305305 Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,306306- Opt_datasum, Opt_treelog, Opt_noinode_cache,306306+ Opt_datasum, Opt_treelog, Opt_noinode_cache, Opt_usebackuproot,307307+ Opt_nologreplay, Opt_norecovery,307308#ifdef CONFIG_BTRFS_DEBUG308309 Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all,309310#endif···336335 {Opt_noacl, "noacl"},337336 {Opt_notreelog, "notreelog"},338337 {Opt_treelog, "treelog"},338338+ {Opt_nologreplay, "nologreplay"},339339+ {Opt_norecovery, "norecovery"},339340 {Opt_flushoncommit, "flushoncommit"},340341 {Opt_noflushoncommit, "noflushoncommit"},341342 {Opt_ratio, "metadata_ratio=%d"},···355352 {Opt_inode_cache, "inode_cache"},356353 {Opt_noinode_cache, "noinode_cache"},357354 {Opt_no_space_cache, "nospace_cache"},358358- {Opt_recovery, "recovery"},355355+ {Opt_recovery, "recovery"}, /* deprecated */356356+ {Opt_usebackuproot, "usebackuproot"},359357 {Opt_skip_balance, "skip_balance"},360358 {Opt_check_integrity, "check_int"},361359 {Opt_check_integrity_including_extent_data, "check_int_data"},···377373 * reading in a new superblock is parsed here.378374 * XXX JDM: This needs to be cleaned up for remount.379375 */380380-int btrfs_parse_options(struct btrfs_root *root, char *options)376376+int btrfs_parse_options(struct btrfs_root *root, char *options,377377+ unsigned long new_flags)381378{382379 struct btrfs_fs_info *info = root->fs_info;383380 substring_t args[MAX_OPT_ARGS];···398393 else if (cache_gen)399394 btrfs_set_opt(info->mount_opt, SPACE_CACHE);400395396396+ /*397397+ * Even the options are empty, we still need to do extra check398398+ * against new flags399399+ */401400 if (!options)402402- goto out;401401+ goto check;403402404403 /*405404 * strsep changes the string, duplicate it because parse_options···615606 btrfs_clear_and_info(root, NOTREELOG,616607 "enabling tree log");617608 break;609609+ case Opt_norecovery:610610+ case Opt_nologreplay:611611+ btrfs_set_and_info(root, NOLOGREPLAY,612612+ "disabling log replay at mount time");613613+ break;618614 case Opt_flushoncommit:619615 btrfs_set_and_info(root, FLUSHONCOMMIT,620616 "turning on flush-on-commit");···710696 "disabling auto defrag");711697 break;712698 case Opt_recovery:713713- btrfs_info(root->fs_info, "enabling auto recovery");714714- btrfs_set_opt(info->mount_opt, RECOVERY);699699+ btrfs_warn(root->fs_info,700700+ "'recovery' is deprecated, use 'usebackuproot' instead");701701+ case Opt_usebackuproot:702702+ btrfs_info(root->fs_info,703703+ "trying to use backup root at mount time");704704+ btrfs_set_opt(info->mount_opt, USEBACKUPROOT);715705 break;716706 case Opt_skip_balance:717707 btrfs_set_opt(info->mount_opt, SKIP_BALANCE);···809791 default:810792 break;811793 }794794+ }795795+check:796796+ /*797797+ * Extra check for current option against current flag798798+ */799799+ if (btrfs_test_opt(root, NOLOGREPLAY) && !(new_flags & MS_RDONLY)) {800800+ btrfs_err(root->fs_info,801801+ "nologreplay must be used with ro mount option");802802+ ret = -EINVAL;812803 }813804out:814805 if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE) &&···12291202 seq_puts(seq, ",ssd");12301203 if (btrfs_test_opt(root, NOTREELOG))12311204 seq_puts(seq, ",notreelog");12051205+ if (btrfs_test_opt(root, NOLOGREPLAY))12061206+ seq_puts(seq, ",nologreplay");12321207 if (btrfs_test_opt(root, FLUSHONCOMMIT))12331208 seq_puts(seq, ",flushoncommit");12341209 if (btrfs_test_opt(root, DISCARD))···12571228 seq_puts(seq, ",inode_cache");12581229 if (btrfs_test_opt(root, SKIP_BALANCE))12591230 seq_puts(seq, ",skip_balance");12601260- if (btrfs_test_opt(root, RECOVERY))12611261- seq_puts(seq, ",recovery");12621231#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY12631232 if (btrfs_test_opt(root, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))12641233 seq_puts(seq, ",check_int_data");···17121685 }17131686 }1714168717151715- ret = btrfs_parse_options(root, data);16881688+ ret = btrfs_parse_options(root, data, *flags);17161689 if (ret) {17171690 ret = -EINVAL;17181691 goto restore;···21892162 if (ret)21902163 break;21912164 ret = !(fs_devices->num_devices == fs_devices->total_devices);21652165+ break;21662166+ case BTRFS_IOC_GET_SUPPORTED_FEATURES:21672167+ ret = btrfs_ioctl_get_supported_features((void __user*)arg);21922168 break;21932169 }21942170