ioctl.c 16 KB

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