aufs4.13 loopback patch diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 10707c3..af32e47 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -547,7 +547,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq) } struct switch_request { - struct file *file; + struct file *file, *virt_file; struct completion wait; }; @@ -573,6 +573,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) mapping = file->f_mapping; mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); lo->lo_backing_file = file; + lo->lo_backing_virt_file = p->virt_file; lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ? mapping->host->i_bdev->bd_block_size : PAGE_SIZE; lo->old_gfp_mask = mapping_gfp_mask(mapping); @@ -585,11 +586,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p) * First it needs to flush existing IO, it does this by sending a magic * BIO down the pipe. The completion of this BIO does the actual switch. */ -static int loop_switch(struct loop_device *lo, struct file *file) +static int loop_switch(struct loop_device *lo, struct file *file, + struct file *virt_file) { struct switch_request w; w.file = file; + w.virt_file = virt_file; /* freeze queue and wait for completion of scheduled requests */ blk_mq_freeze_queue(lo->lo_queue); @@ -611,7 +614,16 @@ static int loop_flush(struct loop_device *lo) /* loop not yet configured, no running thread, nothing to flush */ if (lo->lo_state != Lo_bound) return 0; - return loop_switch(lo, NULL); + return loop_switch(lo, NULL, NULL); +} + +static struct file *loop_real_file(struct file *file) +{ + struct file *f = NULL; + + if (file->f_path.dentry->d_sb->s_op->real_loop) + f = file->f_path.dentry->d_sb->s_op->real_loop(file); + return f; } static void loop_reread_partitions(struct loop_device *lo, @@ -648,6 +660,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, unsigned int arg) { struct file *file, *old_file; + struct file *f, *virt_file = NULL, *old_virt_file; struct inode *inode; int error; @@ -664,9 +677,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, file = fget(arg); if (!file) goto out; + f = loop_real_file(file); + if (f) { + virt_file = file; + file = f; + get_file(file); + } inode = file->f_mapping->host; old_file = lo->lo_backing_file; + old_virt_file = lo->lo_backing_virt_file; error = -EINVAL; @@ -678,17 +698,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, goto out_putf; /* and ... switch */ - error = loop_switch(lo, file); + error = loop_switch(lo, file, virt_file); if (error) goto out_putf; fput(old_file); + if (old_virt_file) + fput(old_virt_file); if (lo->lo_flags & LO_FLAGS_PARTSCAN) loop_reread_partitions(lo, bdev); return 0; out_putf: fput(file); + if (virt_file) + fput(virt_file); out: return error; } @@ -882,7 +906,7 @@ static int loop_prepare_queue(struct loop_device *lo) static int loop_set_fd(struct loop_device *lo, fmode_t mode, struct block_device *bdev, unsigned int arg) { - struct file *file, *f; + struct file *file, *f, *virt_file = NULL; struct inode *inode; struct address_space *mapping; unsigned lo_blocksize; @@ -897,6 +921,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, file = fget(arg); if (!file) goto out; + f = loop_real_file(file); + if (f) { + virt_file = file; + file = f; + get_file(file); + } error = -EBUSY; if (lo->lo_state != Lo_unbound) @@ -949,6 +979,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, lo->lo_device = bdev; lo->lo_flags = lo_flags; lo->lo_backing_file = file; + lo->lo_backing_virt_file = virt_file; lo->transfer = NULL; lo->ioctl = NULL; lo->lo_sizelimit = 0; @@ -981,6 +1012,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, out_putf: fput(file); + if (virt_file) + fput(virt_file); out: /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); @@ -1027,6 +1060,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, static int loop_clr_fd(struct loop_device *lo) { struct file *filp = lo->lo_backing_file; + struct file *virt_filp = lo->lo_backing_virt_file; gfp_t gfp = lo->old_gfp_mask; struct block_device *bdev = lo->lo_device; @@ -1058,6 +1092,7 @@ static int loop_clr_fd(struct loop_device *lo) spin_lock_irq(&lo->lo_lock); lo->lo_state = Lo_rundown; lo->lo_backing_file = NULL; + lo->lo_backing_virt_file = NULL; spin_unlock_irq(&lo->lo_lock); loop_release_xfer(lo); @@ -1102,6 +1137,8 @@ static int loop_clr_fd(struct loop_device *lo) * bd_mutex which is usually taken before lo_ctl_mutex. */ fput(filp); + if (virt_filp) + fput(virt_filp); return 0; } diff --git a/drivers/block/loop.h b/drivers/block/loop.h index fecd3f9..6b3a7c9 100644 --- a/drivers/block/loop.h +++ b/drivers/block/loop.h @@ -46,7 +46,7 @@ struct loop_device { int (*ioctl)(struct loop_device *, int cmd, unsigned long arg); - struct file * lo_backing_file; + struct file * lo_backing_file, *lo_backing_virt_file; struct block_device *lo_device; unsigned lo_blocksize; void *key_data; diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c index 8aff060..e853272 100644 --- a/fs/aufs/f_op.c +++ b/fs/aufs/f_op.c @@ -357,7 +357,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) if (IS_ERR(h_file)) goto out; - if (au_test_loopback_kthread()) { + if (0 && au_test_loopback_kthread()) { au_warn_loopback(h_file->f_path.dentry->d_sb); if (file->f_mapping != h_file->f_mapping) { file->f_mapping = h_file->f_mapping; diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c index e35f015..b37f1ae 100644 --- a/fs/aufs/loop.c +++ b/fs/aufs/loop.c @@ -132,3 +132,19 @@ void au_loopback_fin(void) symbol_put(loop_backing_file); kfree(au_warn_loopback_array); } + +/* ---------------------------------------------------------------------- */ + +/* support the loopback block device insude aufs */ + +struct file *aufs_real_loop(struct file *file) +{ + struct file *f; + + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); + fi_read_lock(file); + f = au_hf_top(file); + fi_read_unlock(file); + AuDebugOn(!f); + return f; +} diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h index e2df495..36e5052 100644 --- a/fs/aufs/loop.h +++ b/fs/aufs/loop.h @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb); int au_loopback_init(void); void au_loopback_fin(void); + +struct file *aufs_real_loop(struct file *file); #else +AuStub(struct file *, loop_backing_file, return NULL) + AuStubInt0(au_test_loopback_overlap, struct super_block *sb, struct dentry *h_adding) AuStubInt0(au_test_loopback_kthread, void) @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) AuStubInt0(au_loopback_init, void) AuStubVoid(au_loopback_fin, void) + +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) #endif /* BLK_DEV_LOOP */ #endif /* __KERNEL__ */ diff --git a/fs/aufs/super.c b/fs/aufs/super.c index 3c300125..128d790 100644 --- a/fs/aufs/super.c +++ b/fs/aufs/super.c @@ -838,7 +838,10 @@ static const struct super_operations aufs_sop = { .statfs = aufs_statfs, .put_super = aufs_put_super, .sync_fs = aufs_sync_fs, - .remount_fs = aufs_remount_fs + .remount_fs = aufs_remount_fs, +#ifdef CONFIG_AUFS_BDEV_LOOP + .real_loop = aufs_real_loop +#endif }; /* ---------------------------------------------------------------------- */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 9b21bb5..f7124fa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1814,6 +1814,10 @@ struct super_operations { struct shrink_control *); long (*free_cached_objects)(struct super_block *, struct shrink_control *); +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) + /* and aufs */ + struct file *(*real_loop)(struct file *); +#endif }; /*