24 #include <linux/wait.h>
25 #include <linux/slab.h>
26 #include <linux/capability.h>
41 static int nilfs_ioctl_wrap_copy(
struct the_nilfs *nilfs,
45 void *,
size_t,
size_t))
49 size_t maxmembs, total,
n;
69 n = (argv->
v_nmembs - i < maxmembs) ?
102 static int nilfs_ioctl_getflags(
struct inode *
inode,
void __user *
argp)
106 return put_user(flags, (
int __user *)argp);
109 static int nilfs_ioctl_setflags(
struct inode *inode,
struct file *filp,
113 unsigned int flags, oldflags;
119 if (
get_user(flags, (
int __user *)argp))
126 flags = nilfs_mask_flags(inode->
i_mode, flags);
130 oldflags = NILFS_I(inode)->i_flags;
161 static int nilfs_ioctl_getversion(
struct inode *inode,
void __user *argp)
166 static int nilfs_ioctl_change_cpmode(
struct inode *inode,
struct file *filp,
167 unsigned int cmd,
void __user *argp)
189 nilfs->
ns_cpfile, cpmode.cm_cno, cpmode.cm_mode);
202 nilfs_ioctl_delete_checkpoint(
struct inode *inode,
struct file *filp,
203 unsigned int cmd,
void __user *argp)
233 nilfs_ioctl_do_get_cpinfo(
struct the_nilfs *nilfs,
__u64 *posp,
int flags,
234 void *buf,
size_t size,
size_t nmembs)
245 static int nilfs_ioctl_get_cpstat(
struct inode *inode,
struct file *filp,
246 unsigned int cmd,
void __user *argp)
264 nilfs_ioctl_do_get_suinfo(
struct the_nilfs *nilfs,
__u64 *posp,
int flags,
265 void *buf,
size_t size,
size_t nmembs)
276 static int nilfs_ioctl_get_sustat(
struct inode *inode,
struct file *filp,
277 unsigned int cmd,
void __user *argp)
295 nilfs_ioctl_do_get_vinfo(
struct the_nilfs *nilfs,
__u64 *posp,
int flags,
296 void *buf,
size_t size,
size_t nmembs)
307 nilfs_ioctl_do_get_bdescs(
struct the_nilfs *nilfs,
__u64 *posp,
int flags,
308 void *buf,
size_t size,
size_t nmembs)
315 for (i = 0; i < nmembs; i++) {
332 static int nilfs_ioctl_get_bdescs(
struct inode *inode,
struct file *filp,
333 unsigned int cmd,
void __user *argp)
345 ret = nilfs_ioctl_wrap_copy(nilfs, &argv,
_IOC_DIR(cmd),
346 nilfs_ioctl_do_get_bdescs);
355 static int nilfs_ioctl_move_inode_block(
struct inode *inode,
359 struct buffer_head *bh;
373 "%s: invalid virtual block address (%s): "
374 "ino=%llu, cno=%llu, offset=%llu, "
375 "blocknr=%llu, vblocknr=%llu\n",
376 __func__, vdesc->
vd_flags ?
"node" :
"data",
377 (
unsigned long long)vdesc->
vd_ino,
378 (
unsigned long long)vdesc->
vd_cno,
384 if (
unlikely(!list_empty(&bh->b_assoc_buffers))) {
386 "cno=%llu, offset=%llu, blocknr=%llu, vblocknr=%llu\n",
387 __func__, vdesc->
vd_flags ?
"node" :
"data",
388 (
unsigned long long)vdesc->
vd_ino,
389 (
unsigned long long)vdesc->
vd_cno,
407 struct buffer_head *bh, *
n;
413 for (i = 0, vdesc = buf; i < nmembs; ) {
418 ret = PTR_ERR(inode);
421 if (list_empty(&NILFS_I(inode)->i_dirty)) {
428 list_add(&NILFS_I(inode)->i_dirty,
433 ret = nilfs_ioctl_move_inode_block(inode, vdesc,
440 }
while (++i < nmembs &&
452 list_del_init(&bh->b_assoc_buffers);
459 list_del_init(&bh->b_assoc_buffers);
465 static int nilfs_ioctl_delete_checkpoints(
struct the_nilfs *nilfs,
473 for (i = 0; i < nmembs; i++) {
482 static int nilfs_ioctl_free_vblocknrs(
struct the_nilfs *nilfs,
490 return (ret < 0) ? ret : nmembs;
493 static int nilfs_ioctl_mark_blocks_dirty(
struct the_nilfs *nilfs,
501 for (i = 0; i < nmembs; i++) {
540 ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], kbufs[1]);
546 msg =
"cannot delete checkpoints";
549 ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], kbufs[2]);
555 msg =
"cannot delete virtual blocks from DAT file";
558 ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], kbufs[3]);
563 msg =
"cannot mark copying blocks dirty";
569 printk(
KERN_ERR "NILFS: GC failed during preparation: %s: err=%d\n",
574 static int nilfs_ioctl_clean_segments(
struct inode *inode,
struct file *filp,
575 unsigned int cmd,
void __user *argp)
578 static const size_t argsz[5] = {
604 if (argv[4].v_size != argsz[4])
614 kbufs[4] =
memdup_user((
void __user *)(
unsigned long)argv[4].v_base,
615 nsegs *
sizeof(
__u64));
616 if (IS_ERR(kbufs[4])) {
617 ret = PTR_ERR(kbufs[4]);
620 nilfs = inode->
i_sb->s_fs_info;
622 for (n = 0; n < 4; n++) {
624 if (argv[n].v_size != argsz[n])
630 if (argv[n].v_nmembs >=
UINT_MAX / argv[n].v_size)
663 ret = nilfs_ioctl_move_blocks(inode->
i_sb, &argv[0], kbufs[0]);
666 "cannot read source blocks: err=%d\n", ret);
671 clear_nilfs_gc_running(nilfs);
682 static int nilfs_ioctl_sync(
struct inode *inode,
struct file *filp,
683 unsigned int cmd,
void __user *argp)
693 nilfs = inode->
i_sb->s_fs_info;
710 static int nilfs_ioctl_resize(
struct inode *inode,
struct file *filp,
735 static int nilfs_ioctl_set_alloc_range(
struct inode *inode,
void __user *argp)
739 __u64 minseg, maxseg;
740 unsigned long segbytes;
751 if (range[1] > i_size_read(inode->
i_sb->s_bdev->bd_inode))
756 minseg = range[0] + segbytes - 1;
767 static int nilfs_ioctl_get_info(
struct inode *inode,
struct file *filp,
768 unsigned int cmd,
void __user *argp,
772 void *,
size_t,
size_t))
785 ret = nilfs_ioctl_wrap_copy(nilfs, &argv,
_IOC_DIR(cmd), dofunc);
796 struct inode *inode = filp->f_dentry->d_inode;
801 return nilfs_ioctl_getflags(inode, argp);
803 return nilfs_ioctl_setflags(inode, filp, argp);
805 return nilfs_ioctl_getversion(inode, argp);
807 return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp);
809 return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp);
811 return nilfs_ioctl_get_info(inode, filp, cmd, argp,
813 nilfs_ioctl_do_get_cpinfo);
815 return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp);
817 return nilfs_ioctl_get_info(inode, filp, cmd, argp,
819 nilfs_ioctl_do_get_suinfo);
821 return nilfs_ioctl_get_sustat(inode, filp, cmd, argp);
823 return nilfs_ioctl_get_info(inode, filp, cmd, argp,
825 nilfs_ioctl_do_get_vinfo);
827 return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp);
829 return nilfs_ioctl_clean_segments(inode, filp, cmd, argp);
831 return nilfs_ioctl_sync(inode, filp, cmd, argp);
833 return nilfs_ioctl_resize(inode, filp, argp);
835 return nilfs_ioctl_set_alloc_range(inode, argp);
870 return nilfs_ioctl(filp, cmd, (
unsigned long)compat_ptr(arg));