ioctl.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/bio.h>
  20. #include <linux/buffer_head.h>
  21. #include <linux/file.h>
  22. #include <linux/fs.h>
  23. #include <linux/fsnotify.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/highmem.h>
  26. #include <linux/time.h>
  27. #include <linux/init.h>
  28. #include <linux/string.h>
  29. #include <linux/backing-dev.h>
  30. #include <linux/mount.h>
  31. #include <linux/mpage.h>
  32. #include <linux/namei.h>
  33. #include <linux/swap.h>
  34. #include <linux/writeback.h>
  35. #include <linux/statfs.h>
  36. #include <linux/compat.h>
  37. #include <linux/bit_spinlock.h>
  38. #include <linux/security.h>
  39. #include <linux/xattr.h>
  40. #include <linux/vmalloc.h>
  41. #include "compat.h"
  42. #include "ctree.h"
  43. #include "disk-io.h"
  44. #include "transaction.h"
  45. #include "btrfs_inode.h"
  46. #include "ioctl.h"
  47. #include "print-tree.h"
  48. #include "volumes.h"
  49. #include "locking.h"
  50. /* Mask out flags that are inappropriate for the given type of inode. */
  51. static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
  52. {
  53. if (S_ISDIR(mode))
  54. return flags;
  55. else if (S_ISREG(mode))
  56. return flags & ~FS_DIRSYNC_FL;
  57. else
  58. return flags & (FS_NODUMP_FL | FS_NOATIME_FL);
  59. }
  60. /*
  61. * Export inode flags to the format expected by the FS_IOC_GETFLAGS ioctl.
  62. */
  63. static unsigned int btrfs_flags_to_ioctl(unsigned int flags)
  64. {
  65. unsigned int iflags = 0;
  66. if (flags & BTRFS_INODE_SYNC)
  67. iflags |= FS_SYNC_FL;
  68. if (flags & BTRFS_INODE_IMMUTABLE)
  69. iflags |= FS_IMMUTABLE_FL;
  70. if (flags & BTRFS_INODE_APPEND)
  71. iflags |= FS_APPEND_FL;
  72. if (flags & BTRFS_INODE_NODUMP)
  73. iflags |= FS_NODUMP_FL;
  74. if (flags & BTRFS_INODE_NOATIME)
  75. iflags |= FS_NOATIME_FL;
  76. if (flags & BTRFS_INODE_DIRSYNC)
  77. iflags |= FS_DIRSYNC_FL;
  78. return iflags;
  79. }
  80. /*
  81. * Update inode->i_flags based on the btrfs internal flags.
  82. */
  83. void btrfs_update_iflags(struct inode *inode)
  84. {
  85. struct btrfs_inode *ip = BTRFS_I(inode);
  86. inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
  87. if (ip->flags & BTRFS_INODE_SYNC)
  88. inode->i_flags |= S_SYNC;
  89. if (ip->flags & BTRFS_INODE_IMMUTABLE)
  90. inode->i_flags |= S_IMMUTABLE;
  91. if (ip->flags & BTRFS_INODE_APPEND)
  92. inode->i_flags |= S_APPEND;
  93. if (ip->flags & BTRFS_INODE_NOATIME)
  94. inode->i_flags |= S_NOATIME;
  95. if (ip->flags & BTRFS_INODE_DIRSYNC)
  96. inode->i_flags |= S_DIRSYNC;
  97. }
  98. /*
  99. * Inherit flags from the parent inode.
  100. *
  101. * Unlike extN we don't have any flags we don't want to inherit currently.
  102. */
  103. void btrfs_inherit_iflags(struct inode *inode, struct inode *dir)
  104. {
  105. unsigned int flags;
  106. if (!dir)
  107. return;
  108. flags = BTRFS_I(dir)->flags;
  109. if (S_ISREG(inode->i_mode))
  110. flags &= ~BTRFS_INODE_DIRSYNC;
  111. else if (!S_ISDIR(inode->i_mode))
  112. flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
  113. BTRFS_I(inode)->flags = flags;
  114. btrfs_update_iflags(inode);
  115. }
  116. static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
  117. {
  118. struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
  119. unsigned int flags = btrfs_flags_to_ioctl(ip->flags);
  120. if (copy_to_user(arg, &flags, sizeof(flags)))
  121. return -EFAULT;
  122. return 0;
  123. }
  124. static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
  125. {
  126. struct inode *inode = file->f_path.dentry->d_inode;
  127. struct btrfs_inode *ip = BTRFS_I(inode);
  128. struct btrfs_root *root = ip->root;
  129. struct btrfs_trans_handle *trans;
  130. unsigned int flags, oldflags;
  131. int ret;
  132. if (copy_from_user(&flags, arg, sizeof(flags)))
  133. return -EFAULT;
  134. if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
  135. FS_NOATIME_FL | FS_NODUMP_FL | \
  136. FS_SYNC_FL | FS_DIRSYNC_FL))
  137. return -EOPNOTSUPP;
  138. if (!is_owner_or_cap(inode))
  139. return -EACCES;
  140. mutex_lock(&inode->i_mutex);
  141. flags = btrfs_mask_flags(inode->i_mode, flags);
  142. oldflags = btrfs_flags_to_ioctl(ip->flags);
  143. if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
  144. if (!capable(CAP_LINUX_IMMUTABLE)) {
  145. ret = -EPERM;
  146. goto out_unlock;
  147. }
  148. }
  149. ret = mnt_want_write(file->f_path.mnt);
  150. if (ret)
  151. goto out_unlock;
  152. if (flags & FS_SYNC_FL)
  153. ip->flags |= BTRFS_INODE_SYNC;
  154. else
  155. ip->flags &= ~BTRFS_INODE_SYNC;
  156. if (flags & FS_IMMUTABLE_FL)
  157. ip->flags |= BTRFS_INODE_IMMUTABLE;
  158. else
  159. ip->flags &= ~BTRFS_INODE_IMMUTABLE;
  160. if (flags & FS_APPEND_FL)
  161. ip->flags |= BTRFS_INODE_APPEND;
  162. else
  163. ip->flags &= ~BTRFS_INODE_APPEND;
  164. if (flags & FS_NODUMP_FL)
  165. ip->flags |= BTRFS_INODE_NODUMP;
  166. else
  167. ip->flags &= ~BTRFS_INODE_NODUMP;
  168. if (flags & FS_NOATIME_FL)
  169. ip->flags |= BTRFS_INODE_NOATIME;
  170. else
  171. ip->flags &= ~BTRFS_INODE_NOATIME;
  172. if (flags & FS_DIRSYNC_FL)
  173. ip->flags |= BTRFS_INODE_DIRSYNC;
  174. else
  175. ip->flags &= ~BTRFS_INODE_DIRSYNC;
  176. trans = btrfs_join_transaction(root, 1);
  177. BUG_ON(!trans);
  178. ret = btrfs_update_inode(trans, root, inode);
  179. BUG_ON(ret);
  180. btrfs_update_iflags(inode);
  181. inode->i_ctime = CURRENT_TIME;
  182. btrfs_end_transaction(trans, root);
  183. mnt_drop_write(file->f_path.mnt);
  184. out_unlock:
  185. mutex_unlock(&inode->i_mutex);
  186. return 0;
  187. }
  188. static int btrfs_ioctl_getversion(struct file *file, int __user *arg)
  189. {
  190. struct inode *inode = file->f_path.dentry->d_inode;
  191. return put_user(inode->i_generation, arg);
  192. }
  193. static noinline int create_subvol(struct btrfs_root *root,
  194. struct dentry *dentry,
  195. char *name, int namelen)
  196. {
  197. struct btrfs_trans_handle *trans;
  198. struct btrfs_key key;
  199. struct btrfs_root_item root_item;
  200. struct btrfs_inode_item *inode_item;
  201. struct extent_buffer *leaf;
  202. struct btrfs_root *new_root = root;
  203. struct inode *dir;
  204. int ret;
  205. int err;
  206. u64 objectid;
  207. u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
  208. u64 index = 0;
  209. unsigned long nr = 1;
  210. ret = btrfs_check_metadata_free_space(root);
  211. if (ret)
  212. goto fail_commit;
  213. trans = btrfs_start_transaction(root, 1);
  214. BUG_ON(!trans);
  215. ret = btrfs_find_free_objectid(trans, root->fs_info->tree_root,
  216. 0, &objectid);
  217. if (ret)
  218. goto fail;
  219. leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
  220. 0, objectid, NULL, 0, 0, 0);
  221. if (IS_ERR(leaf)) {
  222. ret = PTR_ERR(leaf);
  223. goto fail;
  224. }
  225. memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
  226. btrfs_set_header_bytenr(leaf, leaf->start);
  227. btrfs_set_header_generation(leaf, trans->transid);
  228. btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV);
  229. btrfs_set_header_owner(leaf, objectid);
  230. write_extent_buffer(leaf, root->fs_info->fsid,
  231. (unsigned long)btrfs_header_fsid(leaf),
  232. BTRFS_FSID_SIZE);
  233. write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid,
  234. (unsigned long)btrfs_header_chunk_tree_uuid(leaf),
  235. BTRFS_UUID_SIZE);
  236. btrfs_mark_buffer_dirty(leaf);
  237. inode_item = &root_item.inode;
  238. memset(inode_item, 0, sizeof(*inode_item));
  239. inode_item->generation = cpu_to_le64(1);
  240. inode_item->size = cpu_to_le64(3);
  241. inode_item->nlink = cpu_to_le32(1);
  242. inode_item->nbytes = cpu_to_le64(root->leafsize);
  243. inode_item->mode = cpu_to_le32(S_IFDIR | 0755);
  244. btrfs_set_root_bytenr(&root_item, leaf->start);
  245. btrfs_set_root_generation(&root_item, trans->transid);
  246. btrfs_set_root_level(&root_item, 0);
  247. btrfs_set_root_refs(&root_item, 1);
  248. btrfs_set_root_used(&root_item, 0);
  249. btrfs_set_root_last_snapshot(&root_item, 0);
  250. memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress));
  251. root_item.drop_level = 0;
  252. btrfs_tree_unlock(leaf);
  253. free_extent_buffer(leaf);
  254. leaf = NULL;
  255. btrfs_set_root_dirid(&root_item, new_dirid);
  256. key.objectid = objectid;
  257. key.offset = 0;
  258. btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
  259. ret = btrfs_insert_root(trans, root->fs_info->tree_root, &key,
  260. &root_item);
  261. if (ret)
  262. goto fail;
  263. /*
  264. * insert the directory item
  265. */
  266. key.offset = (u64)-1;
  267. dir = dentry->d_parent->d_inode;
  268. ret = btrfs_set_inode_index(dir, &index);
  269. BUG_ON(ret);
  270. ret = btrfs_insert_dir_item(trans, root,
  271. name, namelen, dir->i_ino, &key,
  272. BTRFS_FT_DIR, index);
  273. if (ret)
  274. goto fail;
  275. btrfs_i_size_write(dir, dir->i_size + namelen * 2);
  276. ret = btrfs_update_inode(trans, root, dir);
  277. BUG_ON(ret);
  278. ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
  279. objectid, root->root_key.objectid,
  280. dir->i_ino, index, name, namelen);
  281. BUG_ON(ret);
  282. ret = btrfs_commit_transaction(trans, root);
  283. if (ret)
  284. goto fail_commit;
  285. new_root = btrfs_read_fs_root_no_name(root->fs_info, &key);
  286. BUG_ON(!new_root);
  287. trans = btrfs_start_transaction(new_root, 1);
  288. BUG_ON(!trans);
  289. ret = btrfs_create_subvol_root(trans, new_root, dentry, new_dirid,
  290. BTRFS_I(dir)->block_group);
  291. if (ret)
  292. goto fail;
  293. fail:
  294. nr = trans->blocks_used;
  295. err = btrfs_commit_transaction(trans, new_root);
  296. if (err && !ret)
  297. ret = err;
  298. fail_commit:
  299. btrfs_btree_balance_dirty(root, nr);
  300. return ret;
  301. }
  302. static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
  303. char *name, int namelen)
  304. {
  305. struct btrfs_pending_snapshot *pending_snapshot;
  306. struct btrfs_trans_handle *trans;
  307. int ret = 0;
  308. int err;
  309. unsigned long nr = 0;
  310. if (!root->ref_cows)
  311. return -EINVAL;
  312. ret = btrfs_check_metadata_free_space(root);
  313. if (ret)
  314. goto fail_unlock;
  315. pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS);
  316. if (!pending_snapshot) {
  317. ret = -ENOMEM;
  318. goto fail_unlock;
  319. }
  320. pending_snapshot->name = kmalloc(namelen + 1, GFP_NOFS);
  321. if (!pending_snapshot->name) {
  322. ret = -ENOMEM;
  323. kfree(pending_snapshot);
  324. goto fail_unlock;
  325. }
  326. memcpy(pending_snapshot->name, name, namelen);
  327. pending_snapshot->name[namelen] = '\0';
  328. pending_snapshot->dentry = dentry;
  329. trans = btrfs_start_transaction(root, 1);
  330. BUG_ON(!trans);
  331. pending_snapshot->root = root;
  332. list_add(&pending_snapshot->list,
  333. &trans->transaction->pending_snapshots);
  334. err = btrfs_commit_transaction(trans, root);
  335. fail_unlock:
  336. btrfs_btree_balance_dirty(root, nr);
  337. return ret;
  338. }
  339. /* copy of may_create in fs/namei.c() */
  340. static inline int btrfs_may_create(struct inode *dir, struct dentry *child)
  341. {
  342. if (child->d_inode)
  343. return -EEXIST;
  344. if (IS_DEADDIR(dir))
  345. return -ENOENT;
  346. return inode_permission(dir, MAY_WRITE | MAY_EXEC);
  347. }
  348. /*
  349. * Create a new subvolume below @parent. This is largely modeled after
  350. * sys_mkdirat and vfs_mkdir, but we only do a single component lookup
  351. * inside this filesystem so it's quite a bit simpler.
  352. */
  353. static noinline int btrfs_mksubvol(struct path *parent, char *name,
  354. int mode, int namelen,
  355. struct btrfs_root *snap_src)
  356. {
  357. struct dentry *dentry;
  358. int error;
  359. mutex_lock_nested(&parent->dentry->d_inode->i_mutex, I_MUTEX_PARENT);
  360. dentry = lookup_one_len(name, parent->dentry, namelen);
  361. error = PTR_ERR(dentry);
  362. if (IS_ERR(dentry))
  363. goto out_unlock;
  364. error = -EEXIST;
  365. if (dentry->d_inode)
  366. goto out_dput;
  367. if (!IS_POSIXACL(parent->dentry->d_inode))
  368. mode &= ~current_umask();
  369. error = mnt_want_write(parent->mnt);
  370. if (error)
  371. goto out_dput;
  372. error = btrfs_may_create(parent->dentry->d_inode, dentry);
  373. if (error)
  374. goto out_drop_write;
  375. /*
  376. * Actually perform the low-level subvolume creation after all
  377. * this VFS fuzz.
  378. *
  379. * Eventually we want to pass in an inode under which we create this
  380. * subvolume, but for now all are under the filesystem root.
  381. *
  382. * Also we should pass on the mode eventually to allow creating new
  383. * subvolume with specific mode bits.
  384. */
  385. if (snap_src) {
  386. struct dentry *dir = dentry->d_parent;
  387. struct dentry *test = dir->d_parent;
  388. struct btrfs_path *path = btrfs_alloc_path();
  389. int ret;
  390. u64 test_oid;
  391. u64 parent_oid = BTRFS_I(dir->d_inode)->root->root_key.objectid;
  392. test_oid = snap_src->root_key.objectid;
  393. ret = btrfs_find_root_ref(snap_src->fs_info->tree_root,
  394. path, parent_oid, test_oid);
  395. if (ret == 0)
  396. goto create;
  397. btrfs_release_path(snap_src->fs_info->tree_root, path);
  398. /* we need to make sure we aren't creating a directory loop
  399. * by taking a snapshot of something that has our current
  400. * subvol in its directory tree. So, this loops through
  401. * the dentries and checks the forward refs for each subvolume
  402. * to see if is references the subvolume where we are
  403. * placing this new snapshot.
  404. */
  405. while (1) {
  406. if (!test ||
  407. dir == snap_src->fs_info->sb->s_root ||
  408. test == snap_src->fs_info->sb->s_root ||
  409. test->d_inode->i_sb != snap_src->fs_info->sb) {
  410. break;
  411. }
  412. if (S_ISLNK(test->d_inode->i_mode)) {
  413. printk(KERN_INFO "Btrfs symlink in snapshot "
  414. "path, failed\n");
  415. error = -EMLINK;
  416. btrfs_free_path(path);
  417. goto out_drop_write;
  418. }
  419. test_oid =
  420. BTRFS_I(test->d_inode)->root->root_key.objectid;
  421. ret = btrfs_find_root_ref(snap_src->fs_info->tree_root,
  422. path, test_oid, parent_oid);
  423. if (ret == 0) {
  424. printk(KERN_INFO "Btrfs snapshot creation "
  425. "failed, looping\n");
  426. error = -EMLINK;
  427. btrfs_free_path(path);
  428. goto out_drop_write;
  429. }
  430. btrfs_release_path(snap_src->fs_info->tree_root, path);
  431. test = test->d_parent;
  432. }
  433. create:
  434. btrfs_free_path(path);
  435. error = create_snapshot(snap_src, dentry, name, namelen);
  436. } else {
  437. error = create_subvol(BTRFS_I(parent->dentry->d_inode)->root,
  438. dentry, name, namelen);
  439. }
  440. if (error)
  441. goto out_drop_write;
  442. fsnotify_mkdir(parent->dentry->d_inode, dentry);
  443. out_drop_write:
  444. mnt_drop_write(parent->mnt);
  445. out_dput:
  446. dput(dentry);
  447. out_unlock:
  448. mutex_unlock(&parent->dentry->d_inode->i_mutex);
  449. return error;
  450. }
  451. static int btrfs_defrag_file(struct file *file)
  452. {
  453. struct inode *inode = fdentry(file)->d_inode;
  454. struct btrfs_root *root = BTRFS_I(inode)->root;
  455. struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
  456. struct btrfs_ordered_extent *ordered;
  457. struct page *page;
  458. unsigned long last_index;
  459. unsigned long ra_pages = root->fs_info->bdi.ra_pages;
  460. unsigned long total_read = 0;
  461. u64 page_start;
  462. u64 page_end;
  463. unsigned long i;
  464. int ret;
  465. ret = btrfs_check_data_free_space(root, inode, inode->i_size);
  466. if (ret)
  467. return -ENOSPC;
  468. mutex_lock(&inode->i_mutex);
  469. last_index = inode->i_size >> PAGE_CACHE_SHIFT;
  470. for (i = 0; i <= last_index; i++) {
  471. if (total_read % ra_pages == 0) {
  472. btrfs_force_ra(inode->i_mapping, &file->f_ra, file, i,
  473. min(last_index, i + ra_pages - 1));
  474. }
  475. total_read++;
  476. again:
  477. page = grab_cache_page(inode->i_mapping, i);
  478. if (!page)
  479. goto out_unlock;
  480. if (!PageUptodate(page)) {
  481. btrfs_readpage(NULL, page);
  482. lock_page(page);
  483. if (!PageUptodate(page)) {
  484. unlock_page(page);
  485. page_cache_release(page);
  486. goto out_unlock;
  487. }
  488. }
  489. wait_on_page_writeback(page);
  490. page_start = (u64)page->index << PAGE_CACHE_SHIFT;
  491. page_end = page_start + PAGE_CACHE_SIZE - 1;
  492. lock_extent(io_tree, page_start, page_end, GFP_NOFS);
  493. ordered = btrfs_lookup_ordered_extent(inode, page_start);
  494. if (ordered) {
  495. unlock_extent(io_tree, page_start, page_end, GFP_NOFS);
  496. unlock_page(page);
  497. page_cache_release(page);
  498. btrfs_start_ordered_extent(inode, ordered, 1);
  499. btrfs_put_ordered_extent(ordered);
  500. goto again;
  501. }
  502. set_page_extent_mapped(page);
  503. /*
  504. * this makes sure page_mkwrite is called on the
  505. * page if it is dirtied again later
  506. */
  507. clear_page_dirty_for_io(page);
  508. btrfs_set_extent_delalloc(inode, page_start, page_end);
  509. set_page_dirty(page);
  510. unlock_extent(io_tree, page_start, page_end, GFP_NOFS);
  511. unlock_page(page);
  512. page_cache_release(page);
  513. balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1);
  514. }
  515. out_unlock:
  516. mutex_unlock(&inode->i_mutex);
  517. return 0;
  518. }
  519. static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
  520. {
  521. u64 new_size;
  522. u64 old_size;
  523. u64 devid = 1;
  524. struct btrfs_ioctl_vol_args *vol_args;
  525. struct btrfs_trans_handle *trans;
  526. struct btrfs_device *device = NULL;
  527. char *sizestr;
  528. char *devstr = NULL;
  529. int ret = 0;
  530. int namelen;
  531. int mod = 0;
  532. if (root->fs_info->sb->s_flags & MS_RDONLY)
  533. return -EROFS;
  534. if (!capable(CAP_SYS_ADMIN))
  535. return -EPERM;
  536. vol_args = memdup_user(arg, sizeof(*vol_args));
  537. if (IS_ERR(vol_args))
  538. return PTR_ERR(vol_args);
  539. vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
  540. namelen = strlen(vol_args->name);
  541. mutex_lock(&root->fs_info->volume_mutex);
  542. sizestr = vol_args->name;
  543. devstr = strchr(sizestr, ':');
  544. if (devstr) {
  545. char *end;
  546. sizestr = devstr + 1;
  547. *devstr = '\0';
  548. devstr = vol_args->name;
  549. devid = simple_strtoull(devstr, &end, 10);
  550. printk(KERN_INFO "resizing devid %llu\n",
  551. (unsigned long long)devid);
  552. }
  553. device = btrfs_find_device(root, devid, NULL, NULL);
  554. if (!device) {
  555. printk(KERN_INFO "resizer unable to find device %llu\n",
  556. (unsigned long long)devid);
  557. ret = -EINVAL;
  558. goto out_unlock;
  559. }
  560. if (!strcmp(sizestr, "max"))
  561. new_size = device->bdev->bd_inode->i_size;
  562. else {
  563. if (sizestr[0] == '-') {
  564. mod = -1;
  565. sizestr++;
  566. } else if (sizestr[0] == '+') {
  567. mod = 1;
  568. sizestr++;
  569. }
  570. new_size = btrfs_parse_size(sizestr);
  571. if (new_size == 0) {
  572. ret = -EINVAL;
  573. goto out_unlock;
  574. }
  575. }
  576. old_size = device->total_bytes;
  577. if (mod < 0) {
  578. if (new_size > old_size) {
  579. ret = -EINVAL;
  580. goto out_unlock;
  581. }
  582. new_size = old_size - new_size;
  583. } else if (mod > 0) {
  584. new_size = old_size + new_size;
  585. }
  586. if (new_size < 256 * 1024 * 1024) {
  587. ret = -EINVAL;
  588. goto out_unlock;
  589. }
  590. if (new_size > device->bdev->bd_inode->i_size) {
  591. ret = -EFBIG;
  592. goto out_unlock;
  593. }
  594. do_div(new_size, root->sectorsize);
  595. new_size *= root->sectorsize;
  596. printk(KERN_INFO "new size for %s is %llu\n",
  597. device->name, (unsigned long long)new_size);
  598. if (new_size > old_size) {
  599. trans = btrfs_start_transaction(root, 1);
  600. ret = btrfs_grow_device(trans, device, new_size);
  601. btrfs_commit_transaction(trans, root);
  602. } else {
  603. ret = btrfs_shrink_device(device, new_size);
  604. }
  605. out_unlock:
  606. mutex_unlock(&root->fs_info->volume_mutex);
  607. kfree(vol_args);
  608. return ret;
  609. }
  610. static noinline int btrfs_ioctl_snap_create(struct file *file,
  611. void __user *arg, int subvol)
  612. {
  613. struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
  614. struct btrfs_ioctl_vol_args *vol_args;
  615. struct btrfs_dir_item *di;
  616. struct btrfs_path *path;
  617. struct file *src_file;
  618. u64 root_dirid;
  619. int namelen;
  620. int ret = 0;
  621. if (root->fs_info->sb->s_flags & MS_RDONLY)
  622. return -EROFS;
  623. vol_args = memdup_user(arg, sizeof(*vol_args));
  624. if (IS_ERR(vol_args))
  625. return PTR_ERR(vol_args);
  626. vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
  627. namelen = strlen(vol_args->name);
  628. if (strchr(vol_args->name, '/')) {
  629. ret = -EINVAL;
  630. goto out;
  631. }
  632. path = btrfs_alloc_path();
  633. if (!path) {
  634. ret = -ENOMEM;
  635. goto out;
  636. }
  637. root_dirid = root->fs_info->sb->s_root->d_inode->i_ino,
  638. di = btrfs_lookup_dir_item(NULL, root->fs_info->tree_root,
  639. path, root_dirid,
  640. vol_args->name, namelen, 0);
  641. btrfs_free_path(path);
  642. if (di && !IS_ERR(di)) {
  643. ret = -EEXIST;
  644. goto out;
  645. }
  646. if (IS_ERR(di)) {
  647. ret = PTR_ERR(di);
  648. goto out;
  649. }
  650. if (subvol) {
  651. ret = btrfs_mksubvol(&file->f_path, vol_args->name,
  652. file->f_path.dentry->d_inode->i_mode,
  653. namelen, NULL);
  654. } else {
  655. struct inode *src_inode;
  656. src_file = fget(vol_args->fd);
  657. if (!src_file) {
  658. ret = -EINVAL;
  659. goto out;
  660. }
  661. src_inode = src_file->f_path.dentry->d_inode;
  662. if (src_inode->i_sb != file->f_path.dentry->d_inode->i_sb) {
  663. printk(KERN_INFO "btrfs: Snapshot src from "
  664. "another FS\n");
  665. ret = -EINVAL;
  666. fput(src_file);
  667. goto out;
  668. }
  669. ret = btrfs_mksubvol(&file->f_path, vol_args->name,
  670. file->f_path.dentry->d_inode->i_mode,
  671. namelen, BTRFS_I(src_inode)->root);
  672. fput(src_file);
  673. }
  674. out:
  675. kfree(vol_args);
  676. return ret;
  677. }
  678. static int btrfs_ioctl_defrag(struct file *file)
  679. {
  680. struct inode *inode = fdentry(file)->d_inode;
  681. struct btrfs_root *root = BTRFS_I(inode)->root;
  682. int ret;
  683. ret = mnt_want_write(file->f_path.mnt);
  684. if (ret)
  685. return ret;
  686. switch (inode->i_mode & S_IFMT) {
  687. case S_IFDIR:
  688. if (!capable(CAP_SYS_ADMIN)) {
  689. ret = -EPERM;
  690. goto out;
  691. }
  692. btrfs_defrag_root(root, 0);
  693. btrfs_defrag_root(root->fs_info->extent_root, 0);
  694. break;
  695. case S_IFREG:
  696. if (!(file->f_mode & FMODE_WRITE)) {
  697. ret = -EINVAL;
  698. goto out;
  699. }
  700. btrfs_defrag_file(file);
  701. break;
  702. }
  703. out:
  704. mnt_drop_write(file->f_path.mnt);
  705. return ret;
  706. }
  707. static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
  708. {
  709. struct btrfs_ioctl_vol_args *vol_args;
  710. int ret;
  711. if (!capable(CAP_SYS_ADMIN))
  712. return -EPERM;
  713. vol_args = memdup_user(arg, sizeof(*vol_args));
  714. if (IS_ERR(vol_args))
  715. return PTR_ERR(vol_args);
  716. vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
  717. ret = btrfs_init_new_device(root, vol_args->name);
  718. kfree(vol_args);
  719. return ret;
  720. }
  721. static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
  722. {
  723. struct btrfs_ioctl_vol_args *vol_args;
  724. int ret;
  725. if (!capable(CAP_SYS_ADMIN))
  726. return -EPERM;
  727. if (root->fs_info->sb->s_flags & MS_RDONLY)
  728. return -EROFS;
  729. vol_args = memdup_user(arg, sizeof(*vol_args));
  730. if (IS_ERR(vol_args))
  731. return PTR_ERR(vol_args);
  732. vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
  733. ret = btrfs_rm_device(root, vol_args->name);
  734. kfree(vol_args);
  735. return ret;
  736. }
  737. static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
  738. u64 off, u64 olen, u64 destoff)
  739. {
  740. struct inode *inode = fdentry(file)->d_inode;
  741. struct btrfs_root *root = BTRFS_I(inode)->root;
  742. struct file *src_file;
  743. struct inode *src;
  744. struct btrfs_trans_handle *trans;
  745. struct btrfs_path *path;
  746. struct extent_buffer *leaf;
  747. char *buf;
  748. struct btrfs_key key;
  749. u32 nritems;
  750. int slot;
  751. int ret;
  752. u64 len = olen;
  753. u64 bs = root->fs_info->sb->s_blocksize;
  754. u64 hint_byte;
  755. /*
  756. * TODO:
  757. * - split compressed inline extents. annoying: we need to
  758. * decompress into destination's address_space (the file offset
  759. * may change, so source mapping won't do), then recompress (or
  760. * otherwise reinsert) a subrange.
  761. * - allow ranges within the same file to be cloned (provided
  762. * they don't overlap)?
  763. */
  764. /* the destination must be opened for writing */
  765. if (!(file->f_mode & FMODE_WRITE))
  766. return -EINVAL;
  767. ret = mnt_want_write(file->f_path.mnt);
  768. if (ret)
  769. return ret;
  770. src_file = fget(srcfd);
  771. if (!src_file) {
  772. ret = -EBADF;
  773. goto out_drop_write;
  774. }
  775. src = src_file->f_dentry->d_inode;
  776. ret = -EINVAL;
  777. if (src == inode)
  778. goto out_fput;
  779. ret = -EISDIR;
  780. if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode))
  781. goto out_fput;
  782. ret = -EXDEV;
  783. if (src->i_sb != inode->i_sb || BTRFS_I(src)->root != root)
  784. goto out_fput;
  785. ret = -ENOMEM;
  786. buf = vmalloc(btrfs_level_size(root, 0));
  787. if (!buf)
  788. goto out_fput;
  789. path = btrfs_alloc_path();
  790. if (!path) {
  791. vfree(buf);
  792. goto out_fput;
  793. }
  794. path->reada = 2;
  795. if (inode < src) {
  796. mutex_lock(&inode->i_mutex);
  797. mutex_lock(&src->i_mutex);
  798. } else {
  799. mutex_lock(&src->i_mutex);
  800. mutex_lock(&inode->i_mutex);
  801. }
  802. /* determine range to clone */
  803. ret = -EINVAL;
  804. if (off >= src->i_size || off + len > src->i_size)
  805. goto out_unlock;
  806. if (len == 0)
  807. olen = len = src->i_size - off;
  808. /* if we extend to eof, continue to block boundary */
  809. if (off + len == src->i_size)
  810. len = ((src->i_size + bs-1) & ~(bs-1))
  811. - off;
  812. /* verify the end result is block aligned */
  813. if ((off & (bs-1)) ||
  814. ((off + len) & (bs-1)))
  815. goto out_unlock;
  816. /* do any pending delalloc/csum calc on src, one way or
  817. another, and lock file content */
  818. while (1) {
  819. struct btrfs_ordered_extent *ordered;
  820. lock_extent(&BTRFS_I(src)->io_tree, off, off+len, GFP_NOFS);
  821. ordered = btrfs_lookup_first_ordered_extent(inode, off+len);
  822. if (BTRFS_I(src)->delalloc_bytes == 0 && !ordered)
  823. break;
  824. unlock_extent(&BTRFS_I(src)->io_tree, off, off+len, GFP_NOFS);
  825. if (ordered)
  826. btrfs_put_ordered_extent(ordered);
  827. btrfs_wait_ordered_range(src, off, off+len);
  828. }
  829. trans = btrfs_start_transaction(root, 1);
  830. BUG_ON(!trans);
  831. /* punch hole in destination first */
  832. btrfs_drop_extents(trans, root, inode, off, off + len,
  833. off + len, 0, &hint_byte, 1);
  834. /* clone data */
  835. key.objectid = src->i_ino;
  836. key.type = BTRFS_EXTENT_DATA_KEY;
  837. key.offset = 0;
  838. while (1) {
  839. /*
  840. * note the key will change type as we walk through the
  841. * tree.
  842. */
  843. ret = btrfs_search_slot(trans, root, &key, path, 0, 0);
  844. if (ret < 0)
  845. goto out;
  846. nritems = btrfs_header_nritems(path->nodes[0]);
  847. if (path->slots[0] >= nritems) {
  848. ret = btrfs_next_leaf(root, path);
  849. if (ret < 0)
  850. goto out;
  851. if (ret > 0)
  852. break;
  853. nritems = btrfs_header_nritems(path->nodes[0]);
  854. }
  855. leaf = path->nodes[0];
  856. slot = path->slots[0];
  857. btrfs_item_key_to_cpu(leaf, &key, slot);
  858. if (btrfs_key_type(&key) > BTRFS_EXTENT_DATA_KEY ||
  859. key.objectid != src->i_ino)
  860. break;
  861. if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) {
  862. struct btrfs_file_extent_item *extent;
  863. int type;
  864. u32 size;
  865. struct btrfs_key new_key;
  866. u64 disko = 0, diskl = 0;
  867. u64 datao = 0, datal = 0;
  868. u8 comp;
  869. size = btrfs_item_size_nr(leaf, slot);
  870. read_extent_buffer(leaf, buf,
  871. btrfs_item_ptr_offset(leaf, slot),
  872. size);
  873. extent = btrfs_item_ptr(leaf, slot,
  874. struct btrfs_file_extent_item);
  875. comp = btrfs_file_extent_compression(leaf, extent);
  876. type = btrfs_file_extent_type(leaf, extent);
  877. if (type == BTRFS_FILE_EXTENT_REG ||
  878. type == BTRFS_FILE_EXTENT_PREALLOC) {
  879. disko = btrfs_file_extent_disk_bytenr(leaf,
  880. extent);
  881. diskl = btrfs_file_extent_disk_num_bytes(leaf,
  882. extent);
  883. datao = btrfs_file_extent_offset(leaf, extent);
  884. datal = btrfs_file_extent_num_bytes(leaf,
  885. extent);
  886. } else if (type == BTRFS_FILE_EXTENT_INLINE) {
  887. /* take upper bound, may be compressed */
  888. datal = btrfs_file_extent_ram_bytes(leaf,
  889. extent);
  890. }
  891. btrfs_release_path(root, path);
  892. if (key.offset + datal < off ||
  893. key.offset >= off+len)
  894. goto next;
  895. memcpy(&new_key, &key, sizeof(new_key));
  896. new_key.objectid = inode->i_ino;
  897. new_key.offset = key.offset + destoff - off;
  898. if (type == BTRFS_FILE_EXTENT_REG ||
  899. type == BTRFS_FILE_EXTENT_PREALLOC) {
  900. ret = btrfs_insert_empty_item(trans, root, path,
  901. &new_key, size);
  902. if (ret)
  903. goto out;
  904. leaf = path->nodes[0];
  905. slot = path->slots[0];
  906. write_extent_buffer(leaf, buf,
  907. btrfs_item_ptr_offset(leaf, slot),
  908. size);
  909. extent = btrfs_item_ptr(leaf, slot,
  910. struct btrfs_file_extent_item);
  911. if (off > key.offset) {
  912. datao += off - key.offset;
  913. datal -= off - key.offset;
  914. }
  915. if (key.offset + datao + datal + key.offset >
  916. off + len)
  917. datal = off + len - key.offset - datao;
  918. /* disko == 0 means it's a hole */
  919. if (!disko)
  920. datao = 0;
  921. btrfs_set_file_extent_offset(leaf, extent,
  922. datao);
  923. btrfs_set_file_extent_num_bytes(leaf, extent,
  924. datal);
  925. if (disko) {
  926. inode_add_bytes(inode, datal);
  927. ret = btrfs_inc_extent_ref(trans, root,
  928. disko, diskl, 0,
  929. root->root_key.objectid,
  930. inode->i_ino,
  931. new_key.offset - datao);
  932. BUG_ON(ret);
  933. }
  934. } else if (type == BTRFS_FILE_EXTENT_INLINE) {
  935. u64 skip = 0;
  936. u64 trim = 0;
  937. if (off > key.offset) {
  938. skip = off - key.offset;
  939. new_key.offset += skip;
  940. }
  941. if (key.offset + datal > off+len)
  942. trim = key.offset + datal - (off+len);
  943. if (comp && (skip || trim)) {
  944. ret = -EINVAL;
  945. goto out;
  946. }
  947. size -= skip + trim;
  948. datal -= skip + trim;
  949. ret = btrfs_insert_empty_item(trans, root, path,
  950. &new_key, size);
  951. if (ret)
  952. goto out;
  953. if (skip) {
  954. u32 start =
  955. btrfs_file_extent_calc_inline_size(0);
  956. memmove(buf+start, buf+start+skip,
  957. datal);
  958. }
  959. leaf = path->nodes[0];
  960. slot = path->slots[0];
  961. write_extent_buffer(leaf, buf,
  962. btrfs_item_ptr_offset(leaf, slot),
  963. size);
  964. inode_add_bytes(inode, datal);
  965. }
  966. btrfs_mark_buffer_dirty(leaf);
  967. }
  968. next:
  969. btrfs_release_path(root, path);
  970. key.offset++;
  971. }
  972. ret = 0;
  973. out:
  974. btrfs_release_path(root, path);
  975. if (ret == 0) {
  976. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  977. if (destoff + olen > inode->i_size)
  978. btrfs_i_size_write(inode, destoff + olen);
  979. BTRFS_I(inode)->flags = BTRFS_I(src)->flags;
  980. ret = btrfs_update_inode(trans, root, inode);
  981. }
  982. btrfs_end_transaction(trans, root);
  983. unlock_extent(&BTRFS_I(src)->io_tree, off, off+len, GFP_NOFS);
  984. if (ret)
  985. vmtruncate(inode, 0);
  986. out_unlock:
  987. mutex_unlock(&src->i_mutex);
  988. mutex_unlock(&inode->i_mutex);
  989. vfree(buf);
  990. btrfs_free_path(path);
  991. out_fput:
  992. fput(src_file);
  993. out_drop_write:
  994. mnt_drop_write(file->f_path.mnt);
  995. return ret;
  996. }
  997. static long btrfs_ioctl_clone_range(struct file *file, void __user *argp)
  998. {
  999. struct btrfs_ioctl_clone_range_args args;
  1000. if (copy_from_user(&args, argp, sizeof(args)))
  1001. return -EFAULT;
  1002. return btrfs_ioctl_clone(file, args.src_fd, args.src_offset,
  1003. args.src_length, args.dest_offset);
  1004. }
  1005. /*
  1006. * there are many ways the trans_start and trans_end ioctls can lead
  1007. * to deadlocks. They should only be used by applications that
  1008. * basically own the machine, and have a very in depth understanding
  1009. * of all the possible deadlocks and enospc problems.
  1010. */
  1011. static long btrfs_ioctl_trans_start(struct file *file)
  1012. {
  1013. struct inode *inode = fdentry(file)->d_inode;
  1014. struct btrfs_root *root = BTRFS_I(inode)->root;
  1015. struct btrfs_trans_handle *trans;
  1016. int ret = 0;
  1017. if (!capable(CAP_SYS_ADMIN))
  1018. return -EPERM;
  1019. if (file->private_data) {
  1020. ret = -EINPROGRESS;
  1021. goto out;
  1022. }
  1023. ret = mnt_want_write(file->f_path.mnt);
  1024. if (ret)
  1025. goto out;
  1026. mutex_lock(&root->fs_info->trans_mutex);
  1027. root->fs_info->open_ioctl_trans++;
  1028. mutex_unlock(&root->fs_info->trans_mutex);
  1029. trans = btrfs_start_ioctl_transaction(root, 0);
  1030. if (trans)
  1031. file->private_data = trans;
  1032. else
  1033. ret = -ENOMEM;
  1034. /*printk(KERN_INFO "btrfs_ioctl_trans_start on %p\n", file);*/
  1035. out:
  1036. return ret;
  1037. }
  1038. /*
  1039. * there are many ways the trans_start and trans_end ioctls can lead
  1040. * to deadlocks. They should only be used by applications that
  1041. * basically own the machine, and have a very in depth understanding
  1042. * of all the possible deadlocks and enospc problems.
  1043. */
  1044. long btrfs_ioctl_trans_end(struct file *file)
  1045. {
  1046. struct inode *inode = fdentry(file)->d_inode;
  1047. struct btrfs_root *root = BTRFS_I(inode)->root;
  1048. struct btrfs_trans_handle *trans;
  1049. int ret = 0;
  1050. trans = file->private_data;
  1051. if (!trans) {
  1052. ret = -EINVAL;
  1053. goto out;
  1054. }
  1055. btrfs_end_transaction(trans, root);
  1056. file->private_data = NULL;
  1057. mutex_lock(&root->fs_info->trans_mutex);
  1058. root->fs_info->open_ioctl_trans--;
  1059. mutex_unlock(&root->fs_info->trans_mutex);
  1060. mnt_drop_write(file->f_path.mnt);
  1061. out:
  1062. return ret;
  1063. }
  1064. long btrfs_ioctl(struct file *file, unsigned int
  1065. cmd, unsigned long arg)
  1066. {
  1067. struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
  1068. void __user *argp = (void __user *)arg;
  1069. switch (cmd) {
  1070. case FS_IOC_GETFLAGS:
  1071. return btrfs_ioctl_getflags(file, argp);
  1072. case FS_IOC_SETFLAGS:
  1073. return btrfs_ioctl_setflags(file, argp);
  1074. case FS_IOC_GETVERSION:
  1075. return btrfs_ioctl_getversion(file, argp);
  1076. case BTRFS_IOC_SNAP_CREATE:
  1077. return btrfs_ioctl_snap_create(file, argp, 0);
  1078. case BTRFS_IOC_SUBVOL_CREATE:
  1079. return btrfs_ioctl_snap_create(file, argp, 1);
  1080. case BTRFS_IOC_DEFRAG:
  1081. return btrfs_ioctl_defrag(file);
  1082. case BTRFS_IOC_RESIZE:
  1083. return btrfs_ioctl_resize(root, argp);
  1084. case BTRFS_IOC_ADD_DEV:
  1085. return btrfs_ioctl_add_dev(root, argp);
  1086. case BTRFS_IOC_RM_DEV:
  1087. return btrfs_ioctl_rm_dev(root, argp);
  1088. case BTRFS_IOC_BALANCE:
  1089. return btrfs_balance(root->fs_info->dev_root);
  1090. case BTRFS_IOC_CLONE:
  1091. return btrfs_ioctl_clone(file, arg, 0, 0, 0);
  1092. case BTRFS_IOC_CLONE_RANGE:
  1093. return btrfs_ioctl_clone_range(file, argp);
  1094. case BTRFS_IOC_TRANS_START:
  1095. return btrfs_ioctl_trans_start(file);
  1096. case BTRFS_IOC_TRANS_END:
  1097. return btrfs_ioctl_trans_end(file);
  1098. case BTRFS_IOC_SYNC:
  1099. btrfs_sync_fs(file->f_dentry->d_sb, 1);
  1100. return 0;
  1101. }
  1102. return -ENOTTY;
  1103. }