Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 185470
b: refs/heads/master
c: 7512487
h: refs/heads/master
v: v3
  • Loading branch information
Ryusuke Konishi committed Feb 13, 2010
1 parent bf19088 commit 38cf4b5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e902ec9906e844f4613fa6190c6fa65f162dc86e
refs/heads/master: 7512487e6d6459e4c3f9c7cedc53050a6c30e387
60 changes: 43 additions & 17 deletions trunk/fs/nilfs2/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/capability.h> /* capable() */
#include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
#include <linux/vmalloc.h>
#include <linux/mount.h> /* mnt_want_write(), mnt_drop_write() */
#include <linux/nilfs2_fs.h>
#include "nilfs.h"
#include "segment.h"
Expand Down Expand Up @@ -107,20 +108,28 @@ static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

ret = mnt_want_write(filp->f_path.mnt);
if (ret)
return ret;

ret = -EFAULT;
if (copy_from_user(&cpmode, argp, sizeof(cpmode)))
return -EFAULT;
goto out;

mutex_lock(&nilfs->ns_mount_mutex);

nilfs_transaction_begin(inode->i_sb, &ti, 0);
ret = nilfs_cpfile_change_cpmode(
cpfile, cpmode.cm_cno, cpmode.cm_mode);
if (unlikely(ret < 0)) {
if (unlikely(ret < 0))
nilfs_transaction_abort(inode->i_sb);
mutex_unlock(&nilfs->ns_mount_mutex);
return ret;
}
nilfs_transaction_commit(inode->i_sb); /* never fails */
else
nilfs_transaction_commit(inode->i_sb); /* never fails */

mutex_unlock(&nilfs->ns_mount_mutex);
out:
mnt_drop_write(filp->f_path.mnt);
return ret;
}

Expand All @@ -135,16 +144,23 @@ nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

ret = mnt_want_write(filp->f_path.mnt);
if (ret)
return ret;

ret = -EFAULT;
if (copy_from_user(&cno, argp, sizeof(cno)))
return -EFAULT;
goto out;

nilfs_transaction_begin(inode->i_sb, &ti, 0);
ret = nilfs_cpfile_delete_checkpoint(cpfile, cno);
if (unlikely(ret < 0)) {
if (unlikely(ret < 0))
nilfs_transaction_abort(inode->i_sb);
return ret;
}
nilfs_transaction_commit(inode->i_sb); /* never fails */
else
nilfs_transaction_commit(inode->i_sb); /* never fails */
out:
mnt_drop_write(filp->f_path.mnt);
return ret;
}

Expand Down Expand Up @@ -496,22 +512,30 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
if (!capable(CAP_SYS_ADMIN))
return -EPERM;

ret = mnt_want_write(filp->f_path.mnt);
if (ret)
return ret;

ret = -EFAULT;
if (copy_from_user(argv, argp, sizeof(argv)))
return -EFAULT;
goto out;

ret = -EINVAL;
nsegs = argv[4].v_nmembs;
if (argv[4].v_size != argsz[4])
return -EINVAL;
goto out;

/*
* argv[4] points to segment numbers this ioctl cleans. We
* use kmalloc() for its buffer because memory used for the
* segment numbers is enough small.
*/
kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base,
nsegs * sizeof(__u64));
if (IS_ERR(kbufs[4]))
return PTR_ERR(kbufs[4]);

if (IS_ERR(kbufs[4])) {
ret = PTR_ERR(kbufs[4]);
goto out;
}
nilfs = NILFS_SB(inode->i_sb)->s_nilfs;

for (n = 0; n < 4; n++) {
Expand Down Expand Up @@ -563,10 +587,12 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
nilfs_remove_all_gcinode(nilfs);
clear_nilfs_gc_running(nilfs);

out_free:
out_free:
while (--n >= 0)
vfree(kbufs[n]);
kfree(kbufs[4]);
out:
mnt_drop_write(filp->f_path.mnt);
return ret;
}

Expand Down

0 comments on commit 38cf4b5

Please sign in to comment.