ioctl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. #include <linux/fs.h>
  23. #include <linux/wait.h>
  24. #include <linux/smp_lock.h> /* lock_kernel(), unlock_kernel() */
  25. #include <linux/capability.h> /* capable() */
  26. #include <linux/uaccess.h> /* copy_from_user(), copy_to_user() */
  27. #include <linux/vmalloc.h>
  28. #include <linux/nilfs2_fs.h>
  29. #include "nilfs.h"
  30. #include "segment.h"
  31. #include "bmap.h"
  32. #include "cpfile.h"
  33. #include "sufile.h"
  34. #include "dat.h"
  35. static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
  36. struct nilfs_argv *argv, int dir,
  37. ssize_t (*dofunc)(struct the_nilfs *,
  38. __u64 *, int,
  39. void *, size_t, size_t))
  40. {
  41. void *buf;
  42. void __user *base = (void __user *)(unsigned long)argv->v_base;
  43. size_t maxmembs, total, n;
  44. ssize_t nr;
  45. int ret, i;
  46. __u64 pos, ppos;
  47. if (argv->v_nmembs == 0)
  48. return 0;
  49. if (argv->v_size > PAGE_SIZE)
  50. return -EINVAL;
  51. buf = (void *)__get_free_pages(GFP_NOFS, 0);
  52. if (unlikely(!buf))
  53. return -ENOMEM;
  54. maxmembs = PAGE_SIZE / argv->v_size;
  55. ret = 0;
  56. total = 0;
  57. pos = argv->v_index;
  58. for (i = 0; i < argv->v_nmembs; i += n) {
  59. n = (argv->v_nmembs - i < maxmembs) ?
  60. argv->v_nmembs - i : maxmembs;
  61. if ((dir & _IOC_WRITE) &&
  62. copy_from_user(buf, base + argv->v_size * i,
  63. argv->v_size * n)) {
  64. ret = -EFAULT;
  65. break;
  66. }
  67. ppos = pos;
  68. nr = dofunc(nilfs, &pos, argv->v_flags, buf, argv->v_size,
  69. n);
  70. if (nr < 0) {
  71. ret = nr;
  72. break;
  73. }
  74. if ((dir & _IOC_READ) &&
  75. copy_to_user(base + argv->v_size * i, buf,
  76. argv->v_size * nr)) {
  77. ret = -EFAULT;
  78. break;
  79. }
  80. total += nr;
  81. if ((size_t)nr < n)
  82. break;
  83. if (pos == ppos)
  84. pos += n;
  85. }
  86. argv->v_nmembs = total;
  87. free_pages((unsigned long)buf, 0);
  88. return ret;
  89. }
  90. static int nilfs_ioctl_change_cpmode(struct inode *inode, struct file *filp,
  91. unsigned int cmd, void __user *argp)
  92. {
  93. struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
  94. struct nilfs_transaction_info ti;
  95. struct nilfs_cpmode cpmode;
  96. int ret;
  97. if (!capable(CAP_SYS_ADMIN))
  98. return -EPERM;
  99. if (copy_from_user(&cpmode, argp, sizeof(cpmode)))
  100. return -EFAULT;
  101. nilfs_transaction_begin(inode->i_sb, &ti, 0);
  102. ret = nilfs_cpfile_change_cpmode(
  103. cpfile, cpmode.cm_cno, cpmode.cm_mode);
  104. if (unlikely(ret < 0)) {
  105. nilfs_transaction_abort(inode->i_sb);
  106. return ret;
  107. }
  108. nilfs_transaction_commit(inode->i_sb); /* never fails */
  109. return ret;
  110. }
  111. static int
  112. nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
  113. unsigned int cmd, void __user *argp)
  114. {
  115. struct inode *cpfile = NILFS_SB(inode->i_sb)->s_nilfs->ns_cpfile;
  116. struct nilfs_transaction_info ti;
  117. __u64 cno;
  118. int ret;
  119. if (!capable(CAP_SYS_ADMIN))
  120. return -EPERM;
  121. if (copy_from_user(&cno, argp, sizeof(cno)))
  122. return -EFAULT;
  123. nilfs_transaction_begin(inode->i_sb, &ti, 0);
  124. ret = nilfs_cpfile_delete_checkpoint(cpfile, cno);
  125. if (unlikely(ret < 0)) {
  126. nilfs_transaction_abort(inode->i_sb);
  127. return ret;
  128. }
  129. nilfs_transaction_commit(inode->i_sb); /* never fails */
  130. return ret;
  131. }
  132. static ssize_t
  133. nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
  134. void *buf, size_t size, size_t nmembs)
  135. {
  136. int ret;
  137. down_read(&nilfs->ns_segctor_sem);
  138. ret = nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf,
  139. size, nmembs);
  140. up_read(&nilfs->ns_segctor_sem);
  141. return ret;
  142. }
  143. static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp,
  144. unsigned int cmd, void __user *argp)
  145. {
  146. struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
  147. struct nilfs_cpstat cpstat;
  148. int ret;
  149. down_read(&nilfs->ns_segctor_sem);
  150. ret = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
  151. up_read(&nilfs->ns_segctor_sem);
  152. if (ret < 0)
  153. return ret;
  154. if (copy_to_user(argp, &cpstat, sizeof(cpstat)))
  155. ret = -EFAULT;
  156. return ret;
  157. }
  158. static ssize_t
  159. nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
  160. void *buf, size_t size, size_t nmembs)
  161. {
  162. int ret;
  163. down_read(&nilfs->ns_segctor_sem);
  164. ret = nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, size,
  165. nmembs);
  166. up_read(&nilfs->ns_segctor_sem);
  167. return ret;
  168. }
  169. static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp,
  170. unsigned int cmd, void __user *argp)
  171. {
  172. struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
  173. struct nilfs_sustat sustat;
  174. int ret;
  175. down_read(&nilfs->ns_segctor_sem);
  176. ret = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
  177. up_read(&nilfs->ns_segctor_sem);
  178. if (ret < 0)
  179. return ret;
  180. if (copy_to_user(argp, &sustat, sizeof(sustat)))
  181. ret = -EFAULT;
  182. return ret;
  183. }
  184. static ssize_t
  185. nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
  186. void *buf, size_t size, size_t nmembs)
  187. {
  188. int ret;
  189. down_read(&nilfs->ns_segctor_sem);
  190. ret = nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, size, nmembs);
  191. up_read(&nilfs->ns_segctor_sem);
  192. return ret;
  193. }
  194. static ssize_t
  195. nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags,
  196. void *buf, size_t size, size_t nmembs)
  197. {
  198. struct inode *dat = nilfs_dat_inode(nilfs);
  199. struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
  200. struct nilfs_bdesc *bdescs = buf;
  201. int ret, i;
  202. down_read(&nilfs->ns_segctor_sem);
  203. for (i = 0; i < nmembs; i++) {
  204. ret = nilfs_bmap_lookup_at_level(bmap,
  205. bdescs[i].bd_offset,
  206. bdescs[i].bd_level + 1,
  207. &bdescs[i].bd_blocknr);
  208. if (ret < 0) {
  209. if (ret != -ENOENT) {
  210. up_read(&nilfs->ns_segctor_sem);
  211. return ret;
  212. }
  213. bdescs[i].bd_blocknr = 0;
  214. }
  215. }
  216. up_read(&nilfs->ns_segctor_sem);
  217. return nmembs;
  218. }
  219. static int nilfs_ioctl_get_bdescs(struct inode *inode, struct file *filp,
  220. unsigned int cmd, void __user *argp)
  221. {
  222. struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
  223. struct nilfs_argv argv;
  224. int ret;
  225. if (copy_from_user(&argv, argp, sizeof(argv)))
  226. return -EFAULT;
  227. if (argv.v_size != sizeof(struct nilfs_bdesc))
  228. return -EINVAL;
  229. ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd),
  230. nilfs_ioctl_do_get_bdescs);
  231. if (ret < 0)
  232. return ret;
  233. if (copy_to_user(argp, &argv, sizeof(argv)))
  234. ret = -EFAULT;
  235. return ret;
  236. }
  237. static int nilfs_ioctl_move_inode_block(struct inode *inode,
  238. struct nilfs_vdesc *vdesc,
  239. struct list_head *buffers)
  240. {
  241. struct buffer_head *bh;
  242. int ret;
  243. if (vdesc->vd_flags == 0)
  244. ret = nilfs_gccache_submit_read_data(
  245. inode, vdesc->vd_offset, vdesc->vd_blocknr,
  246. vdesc->vd_vblocknr, &bh);
  247. else
  248. ret = nilfs_gccache_submit_read_node(
  249. inode, vdesc->vd_blocknr, vdesc->vd_vblocknr, &bh);
  250. if (unlikely(ret < 0)) {
  251. if (ret == -ENOENT)
  252. printk(KERN_CRIT
  253. "%s: invalid virtual block address (%s): "
  254. "ino=%llu, cno=%llu, offset=%llu, "
  255. "blocknr=%llu, vblocknr=%llu\n",
  256. __func__, vdesc->vd_flags ? "node" : "data",
  257. (unsigned long long)vdesc->vd_ino,
  258. (unsigned long long)vdesc->vd_cno,
  259. (unsigned long long)vdesc->vd_offset,
  260. (unsigned long long)vdesc->vd_blocknr,
  261. (unsigned long long)vdesc->vd_vblocknr);
  262. return ret;
  263. }
  264. if (unlikely(!list_empty(&bh->b_assoc_buffers))) {
  265. printk(KERN_CRIT "%s: conflicting %s buffer: ino=%llu, "
  266. "cno=%llu, offset=%llu, blocknr=%llu, vblocknr=%llu\n",
  267. __func__, vdesc->vd_flags ? "node" : "data",
  268. (unsigned long long)vdesc->vd_ino,
  269. (unsigned long long)vdesc->vd_cno,
  270. (unsigned long long)vdesc->vd_offset,
  271. (unsigned long long)vdesc->vd_blocknr,
  272. (unsigned long long)vdesc->vd_vblocknr);
  273. brelse(bh);
  274. return -EEXIST;
  275. }
  276. list_add_tail(&bh->b_assoc_buffers, buffers);
  277. return 0;
  278. }
  279. static int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs,
  280. struct nilfs_argv *argv, void *buf)
  281. {
  282. size_t nmembs = argv->v_nmembs;
  283. struct inode *inode;
  284. struct nilfs_vdesc *vdesc;
  285. struct buffer_head *bh, *n;
  286. LIST_HEAD(buffers);
  287. ino_t ino;
  288. __u64 cno;
  289. int i, ret;
  290. for (i = 0, vdesc = buf; i < nmembs; ) {
  291. ino = vdesc->vd_ino;
  292. cno = vdesc->vd_cno;
  293. inode = nilfs_gc_iget(nilfs, ino, cno);
  294. if (unlikely(inode == NULL)) {
  295. ret = -ENOMEM;
  296. goto failed;
  297. }
  298. do {
  299. ret = nilfs_ioctl_move_inode_block(inode, vdesc,
  300. &buffers);
  301. if (unlikely(ret < 0))
  302. goto failed;
  303. vdesc++;
  304. } while (++i < nmembs &&
  305. vdesc->vd_ino == ino && vdesc->vd_cno == cno);
  306. }
  307. list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
  308. ret = nilfs_gccache_wait_and_mark_dirty(bh);
  309. if (unlikely(ret < 0)) {
  310. WARN_ON(ret == -EEXIST);
  311. goto failed;
  312. }
  313. list_del_init(&bh->b_assoc_buffers);
  314. brelse(bh);
  315. }
  316. return nmembs;
  317. failed:
  318. list_for_each_entry_safe(bh, n, &buffers, b_assoc_buffers) {
  319. list_del_init(&bh->b_assoc_buffers);
  320. brelse(bh);
  321. }
  322. return ret;
  323. }
  324. static int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs,
  325. struct nilfs_argv *argv, void *buf)
  326. {
  327. size_t nmembs = argv->v_nmembs;
  328. struct inode *cpfile = nilfs->ns_cpfile;
  329. struct nilfs_period *periods = buf;
  330. int ret, i;
  331. for (i = 0; i < nmembs; i++) {
  332. ret = nilfs_cpfile_delete_checkpoints(
  333. cpfile, periods[i].p_start, periods[i].p_end);
  334. if (ret < 0)
  335. return ret;
  336. }
  337. return nmembs;
  338. }
  339. static int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs,
  340. struct nilfs_argv *argv, void *buf)
  341. {
  342. size_t nmembs = argv->v_nmembs;
  343. int ret;
  344. ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs);
  345. return (ret < 0) ? ret : nmembs;
  346. }
  347. static int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
  348. struct nilfs_argv *argv, void *buf)
  349. {
  350. size_t nmembs = argv->v_nmembs;
  351. struct inode *dat = nilfs_dat_inode(nilfs);
  352. struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
  353. struct nilfs_bdesc *bdescs = buf;
  354. int ret, i;
  355. for (i = 0; i < nmembs; i++) {
  356. /* XXX: use macro or inline func to check liveness */
  357. ret = nilfs_bmap_lookup_at_level(bmap,
  358. bdescs[i].bd_offset,
  359. bdescs[i].bd_level + 1,
  360. &bdescs[i].bd_blocknr);
  361. if (ret < 0) {
  362. if (ret != -ENOENT)
  363. return ret;
  364. bdescs[i].bd_blocknr = 0;
  365. }
  366. if (bdescs[i].bd_blocknr != bdescs[i].bd_oblocknr)
  367. /* skip dead block */
  368. continue;
  369. if (bdescs[i].bd_level == 0) {
  370. ret = nilfs_mdt_mark_block_dirty(dat,
  371. bdescs[i].bd_offset);
  372. if (ret < 0) {
  373. WARN_ON(ret == -ENOENT);
  374. return ret;
  375. }
  376. } else {
  377. ret = nilfs_bmap_mark(bmap, bdescs[i].bd_offset,
  378. bdescs[i].bd_level);
  379. if (ret < 0) {
  380. WARN_ON(ret == -ENOENT);
  381. return ret;
  382. }
  383. }
  384. }
  385. return nmembs;
  386. }
  387. int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *nilfs,
  388. struct nilfs_argv *argv, void **kbufs)
  389. {
  390. const char *msg;
  391. int ret;
  392. ret = nilfs_ioctl_delete_checkpoints(nilfs, &argv[1], kbufs[1]);
  393. if (ret < 0) {
  394. /*
  395. * can safely abort because checkpoints can be removed
  396. * independently.
  397. */
  398. msg = "cannot delete checkpoints";
  399. goto failed;
  400. }
  401. ret = nilfs_ioctl_free_vblocknrs(nilfs, &argv[2], kbufs[2]);
  402. if (ret < 0) {
  403. /*
  404. * can safely abort because DAT file is updated atomically
  405. * using a copy-on-write technique.
  406. */
  407. msg = "cannot delete virtual blocks from DAT file";
  408. goto failed;
  409. }
  410. ret = nilfs_ioctl_mark_blocks_dirty(nilfs, &argv[3], kbufs[3]);
  411. if (ret < 0) {
  412. /*
  413. * can safely abort because the operation is nondestructive.
  414. */
  415. msg = "cannot mark copying blocks dirty";
  416. goto failed;
  417. }
  418. return 0;
  419. failed:
  420. printk(KERN_ERR "NILFS: GC failed during preparation: %s: err=%d\n",
  421. msg, ret);
  422. return ret;
  423. }
  424. static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
  425. unsigned int cmd, void __user *argp)
  426. {
  427. struct nilfs_argv argv[5];
  428. const static size_t argsz[5] = {
  429. sizeof(struct nilfs_vdesc),
  430. sizeof(struct nilfs_period),
  431. sizeof(__u64),
  432. sizeof(struct nilfs_bdesc),
  433. sizeof(__u64),
  434. };
  435. void __user *base;
  436. void *kbufs[5];
  437. struct the_nilfs *nilfs;
  438. size_t len, nsegs;
  439. int n, ret;
  440. if (!capable(CAP_SYS_ADMIN))
  441. return -EPERM;
  442. if (copy_from_user(argv, argp, sizeof(argv)))
  443. return -EFAULT;
  444. nsegs = argv[4].v_nmembs;
  445. if (argv[4].v_size != argsz[4])
  446. return -EINVAL;
  447. /*
  448. * argv[4] points to segment numbers this ioctl cleans. We
  449. * use kmalloc() for its buffer because memory used for the
  450. * segment numbers is enough small.
  451. */
  452. kbufs[4] = memdup_user((void __user *)(unsigned long)argv[4].v_base,
  453. nsegs * sizeof(__u64));
  454. if (IS_ERR(kbufs[4]))
  455. return PTR_ERR(kbufs[4]);
  456. nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
  457. for (n = 0; n < 4; n++) {
  458. ret = -EINVAL;
  459. if (argv[n].v_size != argsz[n])
  460. goto out_free;
  461. if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment)
  462. goto out_free;
  463. len = argv[n].v_size * argv[n].v_nmembs;
  464. base = (void __user *)(unsigned long)argv[n].v_base;
  465. if (len == 0) {
  466. kbufs[n] = NULL;
  467. continue;
  468. }
  469. kbufs[n] = vmalloc(len);
  470. if (!kbufs[n]) {
  471. ret = -ENOMEM;
  472. goto out_free;
  473. }
  474. if (copy_from_user(kbufs[n], base, len)) {
  475. ret = -EFAULT;
  476. vfree(kbufs[n]);
  477. goto out_free;
  478. }
  479. }
  480. /*
  481. * nilfs_ioctl_move_blocks() will call nilfs_gc_iget(),
  482. * which will operates an inode list without blocking.
  483. * To protect the list from concurrent operations,
  484. * nilfs_ioctl_move_blocks should be atomic operation.
  485. */
  486. if (test_and_set_bit(THE_NILFS_GC_RUNNING, &nilfs->ns_flags)) {
  487. ret = -EBUSY;
  488. goto out_free;
  489. }
  490. ret = nilfs_ioctl_move_blocks(nilfs, &argv[0], kbufs[0]);
  491. if (ret < 0)
  492. printk(KERN_ERR "NILFS: GC failed during preparation: "
  493. "cannot read source blocks: err=%d\n", ret);
  494. else
  495. ret = nilfs_clean_segments(inode->i_sb, argv, kbufs);
  496. if (ret < 0)
  497. nilfs_remove_all_gcinode(nilfs);
  498. clear_nilfs_gc_running(nilfs);
  499. out_free:
  500. while (--n >= 0)
  501. vfree(kbufs[n]);
  502. kfree(kbufs[4]);
  503. return ret;
  504. }
  505. static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
  506. unsigned int cmd, void __user *argp)
  507. {
  508. __u64 cno;
  509. int ret;
  510. ret = nilfs_construct_segment(inode->i_sb);
  511. if (ret < 0)
  512. return ret;
  513. if (argp != NULL) {
  514. cno = NILFS_SB(inode->i_sb)->s_nilfs->ns_cno - 1;
  515. if (copy_to_user(argp, &cno, sizeof(cno)))
  516. return -EFAULT;
  517. }
  518. return 0;
  519. }
  520. static int nilfs_ioctl_get_info(struct inode *inode, struct file *filp,
  521. unsigned int cmd, void __user *argp,
  522. size_t membsz,
  523. ssize_t (*dofunc)(struct the_nilfs *,
  524. __u64 *, int,
  525. void *, size_t, size_t))
  526. {
  527. struct the_nilfs *nilfs = NILFS_SB(inode->i_sb)->s_nilfs;
  528. struct nilfs_argv argv;
  529. int ret;
  530. if (copy_from_user(&argv, argp, sizeof(argv)))
  531. return -EFAULT;
  532. if (argv.v_size < membsz)
  533. return -EINVAL;
  534. ret = nilfs_ioctl_wrap_copy(nilfs, &argv, _IOC_DIR(cmd), dofunc);
  535. if (ret < 0)
  536. return ret;
  537. if (copy_to_user(argp, &argv, sizeof(argv)))
  538. ret = -EFAULT;
  539. return ret;
  540. }
  541. long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  542. {
  543. struct inode *inode = filp->f_dentry->d_inode;
  544. void __user *argp = (void * __user *)arg;
  545. switch (cmd) {
  546. case NILFS_IOCTL_CHANGE_CPMODE:
  547. return nilfs_ioctl_change_cpmode(inode, filp, cmd, argp);
  548. case NILFS_IOCTL_DELETE_CHECKPOINT:
  549. return nilfs_ioctl_delete_checkpoint(inode, filp, cmd, argp);
  550. case NILFS_IOCTL_GET_CPINFO:
  551. return nilfs_ioctl_get_info(inode, filp, cmd, argp,
  552. sizeof(struct nilfs_cpinfo),
  553. nilfs_ioctl_do_get_cpinfo);
  554. case NILFS_IOCTL_GET_CPSTAT:
  555. return nilfs_ioctl_get_cpstat(inode, filp, cmd, argp);
  556. case NILFS_IOCTL_GET_SUINFO:
  557. return nilfs_ioctl_get_info(inode, filp, cmd, argp,
  558. sizeof(struct nilfs_suinfo),
  559. nilfs_ioctl_do_get_suinfo);
  560. case NILFS_IOCTL_GET_SUSTAT:
  561. return nilfs_ioctl_get_sustat(inode, filp, cmd, argp);
  562. case NILFS_IOCTL_GET_VINFO:
  563. return nilfs_ioctl_get_info(inode, filp, cmd, argp,
  564. sizeof(struct nilfs_vinfo),
  565. nilfs_ioctl_do_get_vinfo);
  566. case NILFS_IOCTL_GET_BDESCS:
  567. return nilfs_ioctl_get_bdescs(inode, filp, cmd, argp);
  568. case NILFS_IOCTL_CLEAN_SEGMENTS:
  569. return nilfs_ioctl_clean_segments(inode, filp, cmd, argp);
  570. case NILFS_IOCTL_SYNC:
  571. return nilfs_ioctl_sync(inode, filp, cmd, argp);
  572. default:
  573. return -ENOTTY;
  574. }
  575. }