Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ioctl.c - NILFS ioctl operations. |
| 3 | * |
| 4 | * Copyright (C) 2007, 2008 Nippon Telegraph and Telephone Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | * |
| 20 | * Written by Koji Sato <koji@osrg.net>. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/wait.h> |
| 25 | #include <linux/smp_lock.h> /* lock_kernel(), unlock_kernel() */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 27 | #include <linux/capability.h> /* capable() */ |
| 28 | #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */ |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 29 | #include <linux/vmalloc.h> |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 30 | #include <linux/mount.h> /* mnt_want_write(), mnt_drop_write() */ |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 31 | #include <linux/nilfs2_fs.h> |
| 32 | #include "nilfs.h" |
| 33 | #include "segment.h" |
| 34 | #include "bmap.h" |
| 35 | #include "cpfile.h" |
| 36 | #include "sufile.h" |
| 37 | #include "dat.h" |
| 38 | |
| 39 | |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 40 | static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, |
| 41 | struct nilfs_argv *argv, int dir, |
| 42 | ssize_t (*dofunc)(struct the_nilfs *, |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 43 | __u64 *, int, |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 44 | void *, size_t, size_t)) |
| 45 | { |
| 46 | void *buf; |
Ryusuke Konishi | dc498d0 | 2009-04-06 19:01:52 -0700 | [diff] [blame] | 47 | void __user *base = (void __user *)(unsigned long)argv->v_base; |
Ryusuke Konishi | 3358b4a | 2009-04-06 19:01:43 -0700 | [diff] [blame] | 48 | size_t maxmembs, total, n; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 49 | ssize_t nr; |
| 50 | int ret, i; |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 51 | __u64 pos, ppos; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 52 | |
| 53 | if (argv->v_nmembs == 0) |
| 54 | return 0; |
| 55 | |
Ryusuke Konishi | 3358b4a | 2009-04-06 19:01:43 -0700 | [diff] [blame] | 56 | if (argv->v_size > PAGE_SIZE) |
| 57 | return -EINVAL; |
| 58 | |
| 59 | buf = (void *)__get_free_pages(GFP_NOFS, 0); |
| 60 | if (unlikely(!buf)) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 61 | return -ENOMEM; |
Ryusuke Konishi | 3358b4a | 2009-04-06 19:01:43 -0700 | [diff] [blame] | 62 | maxmembs = PAGE_SIZE / argv->v_size; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 63 | |
| 64 | ret = 0; |
| 65 | total = 0; |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 66 | pos = argv->v_index; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 67 | for (i = 0; i < argv->v_nmembs; i += n) { |
| 68 | n = (argv->v_nmembs - i < maxmembs) ? |
| 69 | argv->v_nmembs - i : maxmembs; |
| 70 | if ((dir & _IOC_WRITE) && |
Ryusuke Konishi | dc498d0 | 2009-04-06 19:01:52 -0700 | [diff] [blame] | 71 | copy_from_user(buf, base + argv->v_size * i, |
| 72 | argv->v_size * n)) { |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 73 | ret = -EFAULT; |
| 74 | break; |
| 75 | } |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 76 | ppos = pos; |
Pekka Enberg | 8acfbf0 | 2009-04-06 19:01:49 -0700 | [diff] [blame] | 77 | nr = dofunc(nilfs, &pos, argv->v_flags, buf, argv->v_size, |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 78 | n); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 79 | if (nr < 0) { |
| 80 | ret = nr; |
| 81 | break; |
| 82 | } |
| 83 | if ((dir & _IOC_READ) && |
Ryusuke Konishi | dc498d0 | 2009-04-06 19:01:52 -0700 | [diff] [blame] | 84 | copy_to_user(base + argv->v_size * i, buf, |
| 85 | argv->v_size * nr)) { |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 86 | ret = -EFAULT; |
| 87 | break; |
| 88 | } |
| 89 | total += nr; |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 90 | if ((size_t)nr < n) |
| 91 | break; |
| 92 | if (pos == ppos) |
| 93 | pos += n; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 94 | } |
| 95 | argv->v_nmembs = total; |
| 96 | |
Ryusuke Konishi | 3358b4a | 2009-04-06 19:01:43 -0700 | [diff] [blame] | 97 | free_pages((unsigned long)buf, 0); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp, |
| 102 | unsigned int cmd, void __user *argp) |
| 103 | { |
Ryusuke Konishi | c1ea985 | 2009-11-12 00:13:32 +0900 | [diff] [blame] | 104 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
| 105 | struct inode *cpfile = nilfs->ns_cpfile; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 106 | struct nilfs_transaction_info ti; |
| 107 | struct nilfs_cpmode cpmode; |
| 108 | int ret; |
| 109 | |
| 110 | if (!capable(CAP_SYS_ADMIN)) |
| 111 | return -EPERM; |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 112 | |
| 113 | ret = mnt_want_write(filp->f_path.mnt); |
| 114 | if (ret) |
| 115 | return ret; |
| 116 | |
| 117 | ret = -EFAULT; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 118 | if (copy_from_user(&cpmode, argp, sizeof(cpmode))) |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 119 | goto out; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 120 | |
Ryusuke Konishi | c1ea985 | 2009-11-12 00:13:32 +0900 | [diff] [blame] | 121 | mutex_lock(&nilfs->ns_mount_mutex); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 122 | |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 123 | nilfs_transaction_begin(inode->i_sb, &ti, 0); |
| 124 | ret = nilfs_cpfile_change_cpmode( |
| 125 | cpfile, cpmode.cm_cno, cpmode.cm_mode); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 126 | if (unlikely(ret < 0)) |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 127 | nilfs_transaction_abort(inode->i_sb); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 128 | else |
| 129 | nilfs_transaction_commit(inode->i_sb); /* never fails */ |
| 130 | |
Ryusuke Konishi | c1ea985 | 2009-11-12 00:13:32 +0900 | [diff] [blame] | 131 | mutex_unlock(&nilfs->ns_mount_mutex); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 132 | out: |
| 133 | mnt_drop_write(filp->f_path.mnt); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | static int |
| 138 | nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp, |
| 139 | unsigned int cmd, void __user *argp) |
| 140 | { |
| 141 | struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile; |
| 142 | struct nilfs_transaction_info ti; |
| 143 | __u64 cno; |
| 144 | int ret; |
| 145 | |
| 146 | if (!capable(CAP_SYS_ADMIN)) |
| 147 | return -EPERM; |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 148 | |
| 149 | ret = mnt_want_write(filp->f_path.mnt); |
| 150 | if (ret) |
| 151 | return ret; |
| 152 | |
| 153 | ret = -EFAULT; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 154 | if (copy_from_user(&cno, argp, sizeof(cno))) |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 155 | goto out; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 156 | |
| 157 | nilfs_transaction_begin(inode->i_sb, &ti, 0); |
| 158 | ret = nilfs_cpfile_delete_checkpoint(cpfile, cno); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 159 | if (unlikely(ret < 0)) |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 160 | nilfs_transaction_abort(inode->i_sb); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 161 | else |
| 162 | nilfs_transaction_commit(inode->i_sb); /* never fails */ |
| 163 | out: |
| 164 | mnt_drop_write(filp->f_path.mnt); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | static ssize_t |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 169 | nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 170 | void *buf, size_t size, size_t nmembs) |
| 171 | { |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 172 | int ret; |
| 173 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 174 | down_read(&nilfs->ns_segctor_sem); |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 175 | ret = nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf, |
Ryusuke Konishi | 003ff18 | 2009-05-12 03:58:47 +0900 | [diff] [blame] | 176 | size, nmembs); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 177 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp, |
| 182 | unsigned int cmd, void __user *argp) |
| 183 | { |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 184 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 185 | struct nilfs_cpstat cpstat; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 186 | int ret; |
| 187 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 188 | down_read(&nilfs->ns_segctor_sem); |
| 189 | ret = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat); |
| 190 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 191 | if (ret < 0) |
| 192 | return ret; |
| 193 | |
| 194 | if (copy_to_user(argp, &cpstat, sizeof(cpstat))) |
| 195 | ret = -EFAULT; |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | static ssize_t |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 200 | nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 201 | void *buf, size_t size, size_t nmembs) |
| 202 | { |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 203 | int ret; |
| 204 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 205 | down_read(&nilfs->ns_segctor_sem); |
Ryusuke Konishi | 003ff18 | 2009-05-12 03:58:47 +0900 | [diff] [blame] | 206 | ret = nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, size, |
| 207 | nmembs); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 208 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp, |
| 213 | unsigned int cmd, void __user *argp) |
| 214 | { |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 215 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 216 | struct nilfs_sustat sustat; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 217 | int ret; |
| 218 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 219 | down_read(&nilfs->ns_segctor_sem); |
| 220 | ret = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat); |
| 221 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 222 | if (ret < 0) |
| 223 | return ret; |
| 224 | |
| 225 | if (copy_to_user(argp, &sustat, sizeof(sustat))) |
| 226 | ret = -EFAULT; |
| 227 | return ret; |
| 228 | } |
| 229 | |
| 230 | static ssize_t |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 231 | nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags, |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 232 | void *buf, size_t size, size_t nmembs) |
| 233 | { |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 234 | int ret; |
| 235 | |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 236 | down_read(&nilfs->ns_segctor_sem); |
Ryusuke Konishi | 003ff18 | 2009-05-12 03:58:47 +0900 | [diff] [blame] | 237 | ret = nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, size, nmembs); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 238 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | static ssize_t |
Ryusuke Konishi | b028fcf | 2009-04-06 19:01:47 -0700 | [diff] [blame] | 243 | nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags, |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 244 | void *buf, size_t size, size_t nmembs) |
| 245 | { |
| 246 | struct inode *dat = nilfs_dat_inode(nilfs); |
| 247 | struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap; |
| 248 | struct nilfs_bdesc *bdescs = buf; |
| 249 | int ret, i; |
| 250 | |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 251 | down_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 252 | for (i = 0; i < nmembs; i++) { |
| 253 | ret = nilfs_bmap_lookup_at_level(bmap, |
| 254 | bdescs[i].bd_offset, |
| 255 | bdescs[i].bd_level + 1, |
| 256 | &bdescs[i].bd_blocknr); |
| 257 | if (ret < 0) { |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 258 | if (ret != -ENOENT) { |
| 259 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 260 | return ret; |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 261 | } |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 262 | bdescs[i].bd_blocknr = 0; |
| 263 | } |
| 264 | } |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 265 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 266 | return nmembs; |
| 267 | } |
| 268 | |
| 269 | static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp, |
| 270 | unsigned int cmd, void __user *argp) |
| 271 | { |
| 272 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
| 273 | struct nilfs_argv argv; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 274 | int ret; |
| 275 | |
| 276 | if (copy_from_user(&argv, argp, sizeof(argv))) |
| 277 | return -EFAULT; |
| 278 | |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 279 | if (argv.v_size != sizeof(struct nilfs_bdesc)) |
| 280 | return -EINVAL; |
| 281 | |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 282 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), |
| 283 | nilfs_ioctl_do_get_bdescs); |
Ryusuke Konishi | 47420c7 | 2009-04-06 19:01:45 -0700 | [diff] [blame] | 284 | if (ret < 0) |
| 285 | return ret; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 286 | |
| 287 | if (copy_to_user(argp, &argv, sizeof(argv))) |
| 288 | ret = -EFAULT; |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | static int nilfs_ioctl_move_inode_block(struct inode *inode, |
| 293 | struct nilfs_vdesc *vdesc, |
| 294 | struct list_head *buffers) |
| 295 | { |
| 296 | struct buffer_head *bh; |
| 297 | int ret; |
| 298 | |
| 299 | if (vdesc->vd_flags == 0) |
| 300 | ret = nilfs_gccache_submit_read_data( |
| 301 | inode, vdesc->vd_offset, vdesc->vd_blocknr, |
| 302 | vdesc->vd_vblocknr, &bh); |
| 303 | else |
| 304 | ret = nilfs_gccache_submit_read_node( |
| 305 | inode, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh); |
| 306 | |
| 307 | if (unlikely(ret < 0)) { |
| 308 | if (ret == -ENOENT) |
| 309 | printk(KERN_CRIT |
| 310 | "%s: invalid virtual block address (%s): " |
| 311 | "ino=%llu, cno=%llu, offset=%llu, " |
| 312 | "blocknr=%llu, vblocknr=%llu\n", |
| 313 | __func__, vdesc->vd_flags ? "node" : "data", |
| 314 | (unsigned long long)vdesc->vd_ino, |
| 315 | (unsigned long long)vdesc->vd_cno, |
| 316 | (unsigned long long)vdesc->vd_offset, |
| 317 | (unsigned long long)vdesc->vd_blocknr, |
| 318 | (unsigned long long)vdesc->vd_vblocknr); |
| 319 | return ret; |
| 320 | } |
Ryusuke Konishi | 5399dd1 | 2009-11-07 18:45:16 +0900 | [diff] [blame] | 321 | if (unlikely(!list_empty(&bh->b_assoc_buffers))) { |
| 322 | printk(KERN_CRIT "%s: conflicting %s buffer: ino=%llu, " |
| 323 | "cno=%llu, offset=%llu, blocknr=%llu, vblocknr=%llu\n", |
| 324 | __func__, vdesc->vd_flags ? "node" : "data", |
| 325 | (unsigned long long)vdesc->vd_ino, |
| 326 | (unsigned long long)vdesc->vd_cno, |
| 327 | (unsigned long long)vdesc->vd_offset, |
| 328 | (unsigned long long)vdesc->vd_blocknr, |
| 329 | (unsigned long long)vdesc->vd_vblocknr); |
| 330 | brelse(bh); |
| 331 | return -EEXIST; |
| 332 | } |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 333 | list_add_tail(&bh->b_assoc_buffers, buffers); |
| 334 | return 0; |
| 335 | } |
| 336 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 337 | static int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs, |
| 338 | struct nilfs_argv *argv, void *buf) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 339 | { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 340 | size_t nmembs = argv->v_nmembs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 341 | struct inode *inode; |
| 342 | struct nilfs_vdesc *vdesc; |
| 343 | struct buffer_head *bh, *n; |
| 344 | LIST_HEAD(buffers); |
| 345 | ino_t ino; |
| 346 | __u64 cno; |
| 347 | int i, ret; |
| 348 | |
| 349 | for (i = 0, vdesc = buf; i < nmembs; ) { |
| 350 | ino = vdesc->vd_ino; |
| 351 | cno = vdesc->vd_cno; |
| 352 | inode = nilfs_gc_iget(nilfs, ino, cno); |
| 353 | if (unlikely(inode == NULL)) { |
| 354 | ret = -ENOMEM; |
| 355 | goto failed; |
| 356 | } |
| 357 | do { |
| 358 | ret = nilfs_ioctl_move_inode_block(inode, vdesc, |
| 359 | &buffers); |
| 360 | if (unlikely(ret < 0)) |
| 361 | goto failed; |
| 362 | vdesc++; |
| 363 | } while (++i < nmembs && |
| 364 | vdesc->vd_ino == ino && vdesc->vd_cno == cno); |
| 365 | } |
| 366 | |
| 367 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { |
| 368 | ret = nilfs_gccache_wait_and_mark_dirty(bh); |
| 369 | if (unlikely(ret < 0)) { |
Ryusuke Konishi | 5399dd1 | 2009-11-07 18:45:16 +0900 | [diff] [blame] | 370 | WARN_ON(ret == -EEXIST); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 371 | goto failed; |
| 372 | } |
| 373 | list_del_init(&bh->b_assoc_buffers); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 374 | brelse(bh); |
| 375 | } |
| 376 | return nmembs; |
| 377 | |
| 378 | failed: |
| 379 | list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) { |
| 380 | list_del_init(&bh->b_assoc_buffers); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 381 | brelse(bh); |
| 382 | } |
| 383 | return ret; |
| 384 | } |
| 385 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 386 | static int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs, |
| 387 | struct nilfs_argv *argv, void *buf) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 388 | { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 389 | size_t nmembs = argv->v_nmembs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 390 | struct inode *cpfile = nilfs->ns_cpfile; |
| 391 | struct nilfs_period *periods = buf; |
| 392 | int ret, i; |
| 393 | |
| 394 | for (i = 0; i < nmembs; i++) { |
| 395 | ret = nilfs_cpfile_delete_checkpoints( |
| 396 | cpfile, periods[i].p_start, periods[i].p_end); |
| 397 | if (ret < 0) |
| 398 | return ret; |
| 399 | } |
| 400 | return nmembs; |
| 401 | } |
| 402 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 403 | static int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs, |
| 404 | struct nilfs_argv *argv, void *buf) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 405 | { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 406 | size_t nmembs = argv->v_nmembs; |
| 407 | int ret; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 408 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 409 | ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 410 | |
| 411 | return (ret < 0) ? ret : nmembs; |
| 412 | } |
| 413 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 414 | static int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs, |
| 415 | struct nilfs_argv *argv, void *buf) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 416 | { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 417 | size_t nmembs = argv->v_nmembs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 418 | struct inode *dat = nilfs_dat_inode(nilfs); |
| 419 | struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap; |
| 420 | struct nilfs_bdesc *bdescs = buf; |
| 421 | int ret, i; |
| 422 | |
| 423 | for (i = 0; i < nmembs; i++) { |
| 424 | /* XXX: use macro or inline func to check liveness */ |
| 425 | ret = nilfs_bmap_lookup_at_level(bmap, |
| 426 | bdescs[i].bd_offset, |
| 427 | bdescs[i].bd_level + 1, |
| 428 | &bdescs[i].bd_blocknr); |
| 429 | if (ret < 0) { |
| 430 | if (ret != -ENOENT) |
| 431 | return ret; |
| 432 | bdescs[i].bd_blocknr = 0; |
| 433 | } |
| 434 | if (bdescs[i].bd_blocknr != bdescs[i].bd_oblocknr) |
| 435 | /* skip dead block */ |
| 436 | continue; |
| 437 | if (bdescs[i].bd_level == 0) { |
| 438 | ret = nilfs_mdt_mark_block_dirty(dat, |
| 439 | bdescs[i].bd_offset); |
| 440 | if (ret < 0) { |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 441 | WARN_ON(ret == -ENOENT); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 442 | return ret; |
| 443 | } |
| 444 | } else { |
| 445 | ret = nilfs_bmap_mark(bmap, bdescs[i].bd_offset, |
| 446 | bdescs[i].bd_level); |
| 447 | if (ret < 0) { |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 448 | WARN_ON(ret == -ENOENT); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return nmembs; |
| 454 | } |
| 455 | |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 456 | int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs, |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 457 | struct nilfs_argv *argv, void **kbufs) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 458 | { |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 459 | const char *msg; |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 460 | int ret; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 461 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 462 | ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], kbufs[1]); |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 463 | if (ret < 0) { |
| 464 | /* |
| 465 | * can safely abort because checkpoints can be removed |
| 466 | * independently. |
| 467 | */ |
| 468 | msg = "cannot delete checkpoints"; |
| 469 | goto failed; |
| 470 | } |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 471 | ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], kbufs[2]); |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 472 | if (ret < 0) { |
| 473 | /* |
| 474 | * can safely abort because DAT file is updated atomically |
| 475 | * using a copy-on-write technique. |
| 476 | */ |
| 477 | msg = "cannot delete virtual blocks from DAT file"; |
| 478 | goto failed; |
| 479 | } |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 480 | ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], kbufs[3]); |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 481 | if (ret < 0) { |
| 482 | /* |
| 483 | * can safely abort because the operation is nondestructive. |
| 484 | */ |
| 485 | msg = "cannot mark copying blocks dirty"; |
| 486 | goto failed; |
| 487 | } |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 488 | return 0; |
| 489 | |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 490 | failed: |
Ryusuke Konishi | 1f5abe7 | 2009-04-06 19:01:55 -0700 | [diff] [blame] | 491 | printk(KERN_ERR "NILFS: GC failed during preparation: %s: err=%d\n", |
| 492 | msg, ret); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 493 | return ret; |
| 494 | } |
| 495 | |
| 496 | static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, |
| 497 | unsigned int cmd, void __user *argp) |
| 498 | { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 499 | struct nilfs_argv argv[5]; |
Tobias Klauser | 33e189b | 2009-12-23 13:57:47 +0100 | [diff] [blame] | 500 | static const size_t argsz[5] = { |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 501 | sizeof(struct nilfs_vdesc), |
| 502 | sizeof(struct nilfs_period), |
| 503 | sizeof(__u64), |
| 504 | sizeof(struct nilfs_bdesc), |
| 505 | sizeof(__u64), |
| 506 | }; |
| 507 | void __user *base; |
| 508 | void *kbufs[5]; |
| 509 | struct the_nilfs *nilfs; |
| 510 | size_t len, nsegs; |
| 511 | int n, ret; |
| 512 | |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 513 | if (!capable(CAP_SYS_ADMIN)) |
| 514 | return -EPERM; |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 515 | |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 516 | ret = mnt_want_write(filp->f_path.mnt); |
| 517 | if (ret) |
| 518 | return ret; |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 519 | |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 520 | ret = -EFAULT; |
| 521 | if (copy_from_user(argv, argp, sizeof(argv))) |
| 522 | goto out; |
| 523 | |
| 524 | ret = -EINVAL; |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 525 | nsegs = argv[4].v_nmembs; |
| 526 | if (argv[4].v_size != argsz[4]) |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 527 | goto out; |
| 528 | |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 529 | /* |
| 530 | * argv[4] points to segment numbers this ioctl cleans. We |
| 531 | * use kmalloc() for its buffer because memory used for the |
| 532 | * segment numbers is enough small. |
| 533 | */ |
| 534 | kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base, |
| 535 | nsegs * sizeof(__u64)); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 536 | if (IS_ERR(kbufs[4])) { |
| 537 | ret = PTR_ERR(kbufs[4]); |
| 538 | goto out; |
| 539 | } |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 540 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
| 541 | |
| 542 | for (n = 0; n < 4; n++) { |
| 543 | ret = -EINVAL; |
| 544 | if (argv[n].v_size != argsz[n]) |
| 545 | goto out_free; |
| 546 | |
| 547 | if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment) |
| 548 | goto out_free; |
| 549 | |
| 550 | len = argv[n].v_size * argv[n].v_nmembs; |
| 551 | base = (void __user *)(unsigned long)argv[n].v_base; |
| 552 | if (len == 0) { |
| 553 | kbufs[n] = NULL; |
| 554 | continue; |
| 555 | } |
| 556 | |
| 557 | kbufs[n] = vmalloc(len); |
| 558 | if (!kbufs[n]) { |
| 559 | ret = -ENOMEM; |
| 560 | goto out_free; |
| 561 | } |
| 562 | if (copy_from_user(kbufs[n], base, len)) { |
| 563 | ret = -EFAULT; |
| 564 | vfree(kbufs[n]); |
| 565 | goto out_free; |
| 566 | } |
| 567 | } |
| 568 | |
Jiro SEKIBA | 1cf58fa | 2009-09-03 22:24:17 +0900 | [diff] [blame] | 569 | /* |
| 570 | * nilfs_ioctl_move_blocks() will call nilfs_gc_iget(), |
| 571 | * which will operates an inode list without blocking. |
| 572 | * To protect the list from concurrent operations, |
| 573 | * nilfs_ioctl_move_blocks should be atomic operation. |
| 574 | */ |
| 575 | if (test_and_set_bit(THE_NILFS_GC_RUNNING, &nilfs->ns_flags)) { |
| 576 | ret = -EBUSY; |
| 577 | goto out_free; |
| 578 | } |
| 579 | |
| 580 | ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], kbufs[0]); |
| 581 | if (ret < 0) |
| 582 | printk(KERN_ERR "NILFS: GC failed during preparation: " |
| 583 | "cannot read source blocks: err=%d\n", ret); |
| 584 | else |
| 585 | ret = nilfs_clean_segments(inode->i_sb, argv, kbufs); |
| 586 | |
Ryusuke Konishi | c083234 | 2009-11-08 12:09:24 +0900 | [diff] [blame] | 587 | if (ret < 0) |
| 588 | nilfs_remove_all_gcinode(nilfs); |
Jiro SEKIBA | 1cf58fa | 2009-09-03 22:24:17 +0900 | [diff] [blame] | 589 | clear_nilfs_gc_running(nilfs); |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 590 | |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 591 | out_free: |
Ryusuke Konishi | d5046853 | 2009-05-22 20:36:21 +0900 | [diff] [blame] | 592 | while (--n >= 0) |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 593 | vfree(kbufs[n]); |
| 594 | kfree(kbufs[4]); |
Ryusuke Konishi | 7512487 | 2010-01-26 13:59:40 +0900 | [diff] [blame] | 595 | out: |
| 596 | mnt_drop_write(filp->f_path.mnt); |
Ryusuke Konishi | 4f6b828 | 2009-05-10 22:41:43 +0900 | [diff] [blame] | 597 | return ret; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static int nilfs_ioctl_sync(struct inode *inode, struct file *filp, |
| 601 | unsigned int cmd, void __user *argp) |
| 602 | { |
| 603 | __u64 cno; |
| 604 | int ret; |
Jiro SEKIBA | 0d561f1 | 2010-02-20 19:47:49 +0900 | [diff] [blame] | 605 | struct the_nilfs *nilfs; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 606 | |
| 607 | ret = nilfs_construct_segment(inode->i_sb); |
| 608 | if (ret < 0) |
| 609 | return ret; |
| 610 | |
| 611 | if (argp != NULL) { |
Jiro SEKIBA | 0d561f1 | 2010-02-20 19:47:49 +0900 | [diff] [blame] | 612 | nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
| 613 | down_read(&nilfs->ns_segctor_sem); |
| 614 | cno = nilfs->ns_cno - 1; |
| 615 | up_read(&nilfs->ns_segctor_sem); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 616 | if (copy_to_user(argp, &cno, sizeof(cno))) |
| 617 | return -EFAULT; |
| 618 | } |
| 619 | return 0; |
| 620 | } |
| 621 | |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 622 | static int nilfs_ioctl_get_info(struct inode *inode, struct file *filp, |
| 623 | unsigned int cmd, void __user *argp, |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 624 | size_t membsz, |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 625 | ssize_t (*dofunc)(struct the_nilfs *, |
| 626 | __u64 *, int, |
| 627 | void *, size_t, size_t)) |
| 628 | |
| 629 | { |
| 630 | struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs; |
| 631 | struct nilfs_argv argv; |
| 632 | int ret; |
| 633 | |
| 634 | if (copy_from_user(&argv, argp, sizeof(argv))) |
| 635 | return -EFAULT; |
| 636 | |
Ryusuke Konishi | 003ff18 | 2009-05-12 03:58:47 +0900 | [diff] [blame] | 637 | if (argv.v_size < membsz) |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 638 | return -EINVAL; |
| 639 | |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 640 | ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), dofunc); |
| 641 | if (ret < 0) |
| 642 | return ret; |
| 643 | |
| 644 | if (copy_to_user(argp, &argv, sizeof(argv))) |
| 645 | ret = -EFAULT; |
| 646 | return ret; |
| 647 | } |
| 648 | |
Ryusuke Konishi | 7a94619 | 2009-04-06 19:01:53 -0700 | [diff] [blame] | 649 | long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 650 | { |
Ryusuke Konishi | 7a94619 | 2009-04-06 19:01:53 -0700 | [diff] [blame] | 651 | struct inode *inode = filp->f_dentry->d_inode; |
Li Hong | 7532340 | 2010-03-31 15:41:00 +0800 | [diff] [blame] | 652 | void __user *argp = (void __user *)arg; |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 653 | |
| 654 | switch (cmd) { |
| 655 | case NILFS_IOCTL_CHANGE_CPMODE: |
| 656 | return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp); |
| 657 | case NILFS_IOCTL_DELETE_CHECKPOINT: |
| 658 | return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp); |
| 659 | case NILFS_IOCTL_GET_CPINFO: |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 660 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 661 | sizeof(struct nilfs_cpinfo), |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 662 | nilfs_ioctl_do_get_cpinfo); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 663 | case NILFS_IOCTL_GET_CPSTAT: |
| 664 | return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp); |
| 665 | case NILFS_IOCTL_GET_SUINFO: |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 666 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 667 | sizeof(struct nilfs_suinfo), |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 668 | nilfs_ioctl_do_get_suinfo); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 669 | case NILFS_IOCTL_GET_SUSTAT: |
| 670 | return nilfs_ioctl_get_sustat(inode, filp, cmd, argp); |
| 671 | case NILFS_IOCTL_GET_VINFO: |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 672 | return nilfs_ioctl_get_info(inode, filp, cmd, argp, |
Ryusuke Konishi | 83aca8f | 2009-05-11 23:24:47 +0900 | [diff] [blame] | 673 | sizeof(struct nilfs_vinfo), |
Ryusuke Konishi | 47eb6b9 | 2009-04-30 02:21:00 +0900 | [diff] [blame] | 674 | nilfs_ioctl_do_get_vinfo); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 675 | case NILFS_IOCTL_GET_BDESCS: |
| 676 | return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp); |
| 677 | case NILFS_IOCTL_CLEAN_SEGMENTS: |
| 678 | return nilfs_ioctl_clean_segments(inode, filp, cmd, argp); |
Koji Sato | 7942b91 | 2009-04-06 19:01:41 -0700 | [diff] [blame] | 679 | case NILFS_IOCTL_SYNC: |
| 680 | return nilfs_ioctl_sync(inode, filp, cmd, argp); |
| 681 | default: |
| 682 | return -ENOTTY; |
| 683 | } |
| 684 | } |