overlayfs.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright (C) 2011 Novell Inc.
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/uuid.h>
  8. #include <linux/fs.h>
  9. #include <linux/namei.h>
  10. #include "ovl_entry.h"
  11. #undef pr_fmt
  12. #define pr_fmt(fmt) "overlayfs: " fmt
  13. enum ovl_path_type {
  14. __OVL_PATH_UPPER = (1 << 0),
  15. __OVL_PATH_MERGE = (1 << 1),
  16. __OVL_PATH_ORIGIN = (1 << 2),
  17. };
  18. #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER)
  19. #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE)
  20. #define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN)
  21. #define OVL_XATTR_NAMESPACE "overlay."
  22. #define OVL_XATTR_TRUSTED_PREFIX XATTR_TRUSTED_PREFIX OVL_XATTR_NAMESPACE
  23. #define OVL_XATTR_USER_PREFIX XATTR_USER_PREFIX OVL_XATTR_NAMESPACE
  24. enum ovl_xattr {
  25. OVL_XATTR_OPAQUE,
  26. OVL_XATTR_REDIRECT,
  27. OVL_XATTR_ORIGIN,
  28. OVL_XATTR_IMPURE,
  29. OVL_XATTR_NLINK,
  30. OVL_XATTR_UPPER,
  31. OVL_XATTR_METACOPY,
  32. OVL_XATTR_PROTATTR,
  33. };
  34. enum ovl_inode_flag {
  35. /* Pure upper dir that may contain non pure upper entries */
  36. OVL_IMPURE,
  37. /* Non-merge dir that may contain whiteout entries */
  38. OVL_WHITEOUTS,
  39. OVL_INDEX,
  40. OVL_UPPERDATA,
  41. /* Inode number will remain constant over copy up. */
  42. OVL_CONST_INO,
  43. };
  44. enum ovl_entry_flag {
  45. OVL_E_UPPER_ALIAS,
  46. OVL_E_OPAQUE,
  47. OVL_E_CONNECTED,
  48. };
  49. enum {
  50. OVL_XINO_OFF,
  51. OVL_XINO_AUTO,
  52. OVL_XINO_ON,
  53. };
  54. /*
  55. * The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
  56. * where:
  57. * origin.fh - exported file handle of the lower file
  58. * origin.uuid - uuid of the lower filesystem
  59. */
  60. #define OVL_FH_VERSION 0
  61. #define OVL_FH_MAGIC 0xfb
  62. /* CPU byte order required for fid decoding: */
  63. #define OVL_FH_FLAG_BIG_ENDIAN (1 << 0)
  64. #define OVL_FH_FLAG_ANY_ENDIAN (1 << 1)
  65. /* Is the real inode encoded in fid an upper inode? */
  66. #define OVL_FH_FLAG_PATH_UPPER (1 << 2)
  67. #define OVL_FH_FLAG_ALL (OVL_FH_FLAG_BIG_ENDIAN | OVL_FH_FLAG_ANY_ENDIAN | \
  68. OVL_FH_FLAG_PATH_UPPER)
  69. #if defined(__LITTLE_ENDIAN)
  70. #define OVL_FH_FLAG_CPU_ENDIAN 0
  71. #elif defined(__BIG_ENDIAN)
  72. #define OVL_FH_FLAG_CPU_ENDIAN OVL_FH_FLAG_BIG_ENDIAN
  73. #else
  74. #error Endianness not defined
  75. #endif
  76. /* The type used to be returned by overlay exportfs for misaligned fid */
  77. #define OVL_FILEID_V0 0xfb
  78. /* The type returned by overlay exportfs for 32bit aligned fid */
  79. #define OVL_FILEID_V1 0xf8
  80. /* On-disk format for "origin" file handle */
  81. struct ovl_fb {
  82. u8 version; /* 0 */
  83. u8 magic; /* 0xfb */
  84. u8 len; /* size of this header + size of fid */
  85. u8 flags; /* OVL_FH_FLAG_* */
  86. u8 type; /* fid_type of fid */
  87. uuid_t uuid; /* uuid of filesystem */
  88. u32 fid[]; /* file identifier should be 32bit aligned in-memory */
  89. } __packed;
  90. /* In-memory and on-wire format for overlay file handle */
  91. struct ovl_fh {
  92. u8 padding[3]; /* make sure fb.fid is 32bit aligned */
  93. union {
  94. struct ovl_fb fb;
  95. DECLARE_FLEX_ARRAY(u8, buf);
  96. };
  97. } __packed;
  98. #define OVL_FH_WIRE_OFFSET offsetof(struct ovl_fh, fb)
  99. #define OVL_FH_LEN(fh) (OVL_FH_WIRE_OFFSET + (fh)->fb.len)
  100. #define OVL_FH_FID_OFFSET (OVL_FH_WIRE_OFFSET + \
  101. offsetof(struct ovl_fb, fid))
  102. extern const char *const ovl_xattr_table[][2];
  103. static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox)
  104. {
  105. return ovl_xattr_table[ox][ofs->config.userxattr];
  106. }
  107. /*
  108. * When changing ownership of an upper object map the intended ownership
  109. * according to the upper layer's idmapping. When an upper mount idmaps files
  110. * that are stored on-disk as owned by id 1001 to id 1000 this means stat on
  111. * this object will report it as being owned by id 1000 when calling stat via
  112. * the upper mount.
  113. * In order to change ownership of an object so stat reports id 1000 when
  114. * called on an idmapped upper mount the value written to disk - i.e., the
  115. * value stored in ia_*id - must 1001. The mount mapping helper will thus take
  116. * care to map 1000 to 1001.
  117. * The mnt idmapping helpers are nops if the upper layer isn't idmapped.
  118. */
  119. static inline int ovl_do_notify_change(struct ovl_fs *ofs,
  120. struct dentry *upperdentry,
  121. struct iattr *attr)
  122. {
  123. return notify_change(ovl_upper_mnt_userns(ofs), upperdentry, attr, NULL);
  124. }
  125. static inline int ovl_do_rmdir(struct ovl_fs *ofs,
  126. struct inode *dir, struct dentry *dentry)
  127. {
  128. int err = vfs_rmdir(ovl_upper_mnt_userns(ofs), dir, dentry);
  129. pr_debug("rmdir(%pd2) = %i\n", dentry, err);
  130. return err;
  131. }
  132. static inline int ovl_do_unlink(struct ovl_fs *ofs, struct inode *dir,
  133. struct dentry *dentry)
  134. {
  135. int err = vfs_unlink(ovl_upper_mnt_userns(ofs), dir, dentry, NULL);
  136. pr_debug("unlink(%pd2) = %i\n", dentry, err);
  137. return err;
  138. }
  139. static inline int ovl_do_link(struct ovl_fs *ofs, struct dentry *old_dentry,
  140. struct inode *dir, struct dentry *new_dentry)
  141. {
  142. int err = vfs_link(old_dentry, ovl_upper_mnt_userns(ofs), dir, new_dentry, NULL);
  143. pr_debug("link(%pd2, %pd2) = %i\n", old_dentry, new_dentry, err);
  144. return err;
  145. }
  146. static inline int ovl_do_create(struct ovl_fs *ofs,
  147. struct inode *dir, struct dentry *dentry,
  148. umode_t mode)
  149. {
  150. int err = vfs_create(ovl_upper_mnt_userns(ofs), dir, dentry, mode, true);
  151. pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
  152. return err;
  153. }
  154. static inline int ovl_do_mkdir(struct ovl_fs *ofs,
  155. struct inode *dir, struct dentry *dentry,
  156. umode_t mode)
  157. {
  158. int err = vfs_mkdir(ovl_upper_mnt_userns(ofs), dir, dentry, mode);
  159. pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
  160. return err;
  161. }
  162. static inline int ovl_do_mknod(struct ovl_fs *ofs,
  163. struct inode *dir, struct dentry *dentry,
  164. umode_t mode, dev_t dev)
  165. {
  166. int err = vfs_mknod(ovl_upper_mnt_userns(ofs), dir, dentry, mode, dev);
  167. pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err);
  168. return err;
  169. }
  170. static inline int ovl_do_symlink(struct ovl_fs *ofs,
  171. struct inode *dir, struct dentry *dentry,
  172. const char *oldname)
  173. {
  174. int err = vfs_symlink(ovl_upper_mnt_userns(ofs), dir, dentry, oldname);
  175. pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
  176. return err;
  177. }
  178. static inline ssize_t ovl_do_getxattr(const struct path *path, const char *name,
  179. void *value, size_t size)
  180. {
  181. int err, len;
  182. WARN_ON(path->dentry->d_sb != path->mnt->mnt_sb);
  183. err = vfs_getxattr(mnt_user_ns(path->mnt), path->dentry,
  184. name, value, size);
  185. len = (value && err > 0) ? err : 0;
  186. pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
  187. path->dentry, name, min(len, 48), value, size, err);
  188. return err;
  189. }
  190. static inline ssize_t ovl_getxattr_upper(struct ovl_fs *ofs,
  191. struct dentry *upperdentry,
  192. enum ovl_xattr ox, void *value,
  193. size_t size)
  194. {
  195. struct path upperpath = {
  196. .dentry = upperdentry,
  197. .mnt = ovl_upper_mnt(ofs),
  198. };
  199. return ovl_do_getxattr(&upperpath, ovl_xattr(ofs, ox), value, size);
  200. }
  201. static inline ssize_t ovl_path_getxattr(struct ovl_fs *ofs,
  202. const struct path *path,
  203. enum ovl_xattr ox, void *value,
  204. size_t size)
  205. {
  206. return ovl_do_getxattr(path, ovl_xattr(ofs, ox), value, size);
  207. }
  208. static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
  209. const char *name, const void *value,
  210. size_t size, int flags)
  211. {
  212. int err = vfs_setxattr(ovl_upper_mnt_userns(ofs), dentry, name,
  213. value, size, flags);
  214. pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n",
  215. dentry, name, min((int)size, 48), value, size, flags, err);
  216. return err;
  217. }
  218. static inline int ovl_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
  219. enum ovl_xattr ox, const void *value,
  220. size_t size)
  221. {
  222. return ovl_do_setxattr(ofs, dentry, ovl_xattr(ofs, ox), value, size, 0);
  223. }
  224. static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
  225. const char *name)
  226. {
  227. int err = vfs_removexattr(ovl_upper_mnt_userns(ofs), dentry, name);
  228. pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
  229. return err;
  230. }
  231. static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
  232. enum ovl_xattr ox)
  233. {
  234. return ovl_do_removexattr(ofs, dentry, ovl_xattr(ofs, ox));
  235. }
  236. static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir,
  237. struct dentry *olddentry, struct inode *newdir,
  238. struct dentry *newdentry, unsigned int flags)
  239. {
  240. int err;
  241. struct renamedata rd = {
  242. .old_mnt_userns = ovl_upper_mnt_userns(ofs),
  243. .old_dir = olddir,
  244. .old_dentry = olddentry,
  245. .new_mnt_userns = ovl_upper_mnt_userns(ofs),
  246. .new_dir = newdir,
  247. .new_dentry = newdentry,
  248. .flags = flags,
  249. };
  250. pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
  251. err = vfs_rename(&rd);
  252. if (err) {
  253. pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
  254. olddentry, newdentry, err);
  255. }
  256. return err;
  257. }
  258. static inline int ovl_do_whiteout(struct ovl_fs *ofs,
  259. struct inode *dir, struct dentry *dentry)
  260. {
  261. int err = vfs_whiteout(ovl_upper_mnt_userns(ofs), dir, dentry);
  262. pr_debug("whiteout(%pd2) = %i\n", dentry, err);
  263. return err;
  264. }
  265. static inline struct file *ovl_do_tmpfile(struct ovl_fs *ofs,
  266. struct dentry *dentry, umode_t mode)
  267. {
  268. struct path path = { .mnt = ovl_upper_mnt(ofs), .dentry = dentry };
  269. struct file *file = vfs_tmpfile_open(ovl_upper_mnt_userns(ofs), &path, mode,
  270. O_LARGEFILE | O_WRONLY, current_cred());
  271. int err = PTR_ERR_OR_ZERO(file);
  272. pr_debug("tmpfile(%pd2, 0%o) = %i\n", dentry, mode, err);
  273. return file;
  274. }
  275. static inline struct dentry *ovl_lookup_upper(struct ovl_fs *ofs,
  276. const char *name,
  277. struct dentry *base, int len)
  278. {
  279. return lookup_one(ovl_upper_mnt_userns(ofs), name, base, len);
  280. }
  281. static inline bool ovl_open_flags_need_copy_up(int flags)
  282. {
  283. if (!flags)
  284. return false;
  285. return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
  286. }
  287. static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs)
  288. {
  289. /*
  290. * To avoid regressions in existing setups with overlay lower offline
  291. * changes, we allow lower changes only if none of the new features
  292. * are used.
  293. */
  294. return (!ofs->config.index && !ofs->config.metacopy &&
  295. !ofs->config.redirect_dir && ofs->config.xino != OVL_XINO_ON);
  296. }
  297. /* util.c */
  298. int ovl_want_write(struct dentry *dentry);
  299. void ovl_drop_write(struct dentry *dentry);
  300. struct dentry *ovl_workdir(struct dentry *dentry);
  301. const struct cred *ovl_override_creds(struct super_block *sb);
  302. void ovl_revert_creds(struct super_block *sb, const struct cred *oldcred);
  303. int ovl_can_decode_fh(struct super_block *sb);
  304. struct dentry *ovl_indexdir(struct super_block *sb);
  305. bool ovl_index_all(struct super_block *sb);
  306. bool ovl_verify_lower(struct super_block *sb);
  307. struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
  308. bool ovl_dentry_remote(struct dentry *dentry);
  309. void ovl_dentry_update_reval(struct dentry *dentry, struct dentry *realdentry);
  310. void ovl_dentry_init_reval(struct dentry *dentry, struct dentry *upperdentry);
  311. void ovl_dentry_init_flags(struct dentry *dentry, struct dentry *upperdentry,
  312. unsigned int mask);
  313. bool ovl_dentry_weird(struct dentry *dentry);
  314. enum ovl_path_type ovl_path_type(struct dentry *dentry);
  315. void ovl_path_upper(struct dentry *dentry, struct path *path);
  316. void ovl_path_lower(struct dentry *dentry, struct path *path);
  317. void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
  318. struct inode *ovl_i_path_real(struct inode *inode, struct path *path);
  319. enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
  320. enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path);
  321. struct dentry *ovl_dentry_upper(struct dentry *dentry);
  322. struct dentry *ovl_dentry_lower(struct dentry *dentry);
  323. struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
  324. const struct ovl_layer *ovl_i_layer_lower(struct inode *inode);
  325. const struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
  326. struct dentry *ovl_dentry_real(struct dentry *dentry);
  327. struct dentry *ovl_i_dentry_upper(struct inode *inode);
  328. struct inode *ovl_inode_upper(struct inode *inode);
  329. struct inode *ovl_inode_lower(struct inode *inode);
  330. struct inode *ovl_inode_lowerdata(struct inode *inode);
  331. struct inode *ovl_inode_real(struct inode *inode);
  332. struct inode *ovl_inode_realdata(struct inode *inode);
  333. struct ovl_dir_cache *ovl_dir_cache(struct inode *inode);
  334. void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache);
  335. void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry);
  336. void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry);
  337. bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry);
  338. bool ovl_dentry_is_opaque(struct dentry *dentry);
  339. bool ovl_dentry_is_whiteout(struct dentry *dentry);
  340. void ovl_dentry_set_opaque(struct dentry *dentry);
  341. bool ovl_dentry_has_upper_alias(struct dentry *dentry);
  342. void ovl_dentry_set_upper_alias(struct dentry *dentry);
  343. bool ovl_dentry_needs_data_copy_up(struct dentry *dentry, int flags);
  344. bool ovl_dentry_needs_data_copy_up_locked(struct dentry *dentry, int flags);
  345. bool ovl_has_upperdata(struct inode *inode);
  346. void ovl_set_upperdata(struct inode *inode);
  347. bool ovl_redirect_dir(struct super_block *sb);
  348. const char *ovl_dentry_get_redirect(struct dentry *dentry);
  349. void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
  350. void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
  351. void ovl_dir_modified(struct dentry *dentry, bool impurity);
  352. u64 ovl_dentry_version_get(struct dentry *dentry);
  353. bool ovl_is_whiteout(struct dentry *dentry);
  354. struct file *ovl_path_open(const struct path *path, int flags);
  355. int ovl_copy_up_start(struct dentry *dentry, int flags);
  356. void ovl_copy_up_end(struct dentry *dentry);
  357. bool ovl_already_copied_up(struct dentry *dentry, int flags);
  358. bool ovl_path_check_dir_xattr(struct ovl_fs *ofs, const struct path *path,
  359. enum ovl_xattr ox);
  360. bool ovl_path_check_origin_xattr(struct ovl_fs *ofs, const struct path *path);
  361. static inline bool ovl_check_origin_xattr(struct ovl_fs *ofs,
  362. struct dentry *upperdentry)
  363. {
  364. struct path upperpath = {
  365. .dentry = upperdentry,
  366. .mnt = ovl_upper_mnt(ofs),
  367. };
  368. return ovl_path_check_origin_xattr(ofs, &upperpath);
  369. }
  370. int ovl_check_setxattr(struct ovl_fs *ofs, struct dentry *upperdentry,
  371. enum ovl_xattr ox, const void *value, size_t size,
  372. int xerr);
  373. int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
  374. bool ovl_inuse_trylock(struct dentry *dentry);
  375. void ovl_inuse_unlock(struct dentry *dentry);
  376. bool ovl_is_inuse(struct dentry *dentry);
  377. bool ovl_need_index(struct dentry *dentry);
  378. int ovl_nlink_start(struct dentry *dentry);
  379. void ovl_nlink_end(struct dentry *dentry);
  380. int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
  381. int ovl_check_metacopy_xattr(struct ovl_fs *ofs, const struct path *path);
  382. bool ovl_is_metacopy_dentry(struct dentry *dentry);
  383. char *ovl_get_redirect_xattr(struct ovl_fs *ofs, const struct path *path, int padding);
  384. int ovl_sync_status(struct ovl_fs *ofs);
  385. static inline void ovl_set_flag(unsigned long flag, struct inode *inode)
  386. {
  387. set_bit(flag, &OVL_I(inode)->flags);
  388. }
  389. static inline void ovl_clear_flag(unsigned long flag, struct inode *inode)
  390. {
  391. clear_bit(flag, &OVL_I(inode)->flags);
  392. }
  393. static inline bool ovl_test_flag(unsigned long flag, struct inode *inode)
  394. {
  395. return test_bit(flag, &OVL_I(inode)->flags);
  396. }
  397. static inline bool ovl_is_impuredir(struct super_block *sb,
  398. struct dentry *upperdentry)
  399. {
  400. struct ovl_fs *ofs = OVL_FS(sb);
  401. struct path upperpath = {
  402. .dentry = upperdentry,
  403. .mnt = ovl_upper_mnt(ofs),
  404. };
  405. return ovl_path_check_dir_xattr(ofs, &upperpath, OVL_XATTR_IMPURE);
  406. }
  407. /*
  408. * With xino=auto, we do best effort to keep all inodes on same st_dev and
  409. * d_ino consistent with st_ino.
  410. * With xino=on, we do the same effort but we warn if we failed.
  411. */
  412. static inline bool ovl_xino_warn(struct super_block *sb)
  413. {
  414. return OVL_FS(sb)->config.xino == OVL_XINO_ON;
  415. }
  416. /* All layers on same fs? */
  417. static inline bool ovl_same_fs(struct super_block *sb)
  418. {
  419. return OVL_FS(sb)->xino_mode == 0;
  420. }
  421. /* All overlay inodes have same st_dev? */
  422. static inline bool ovl_same_dev(struct super_block *sb)
  423. {
  424. return OVL_FS(sb)->xino_mode >= 0;
  425. }
  426. static inline unsigned int ovl_xino_bits(struct super_block *sb)
  427. {
  428. return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0;
  429. }
  430. static inline void ovl_inode_lock(struct inode *inode)
  431. {
  432. mutex_lock(&OVL_I(inode)->lock);
  433. }
  434. static inline int ovl_inode_lock_interruptible(struct inode *inode)
  435. {
  436. return mutex_lock_interruptible(&OVL_I(inode)->lock);
  437. }
  438. static inline void ovl_inode_unlock(struct inode *inode)
  439. {
  440. mutex_unlock(&OVL_I(inode)->lock);
  441. }
  442. /* namei.c */
  443. int ovl_check_fb_len(struct ovl_fb *fb, int fb_len);
  444. static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
  445. {
  446. if (fh_len < sizeof(struct ovl_fh))
  447. return -EINVAL;
  448. return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
  449. }
  450. struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
  451. struct vfsmount *mnt, bool connected);
  452. int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
  453. struct dentry *upperdentry, struct ovl_path **stackp);
  454. int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
  455. enum ovl_xattr ox, struct dentry *real, bool is_upper,
  456. bool set);
  457. struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);
  458. int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);
  459. int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,
  460. struct qstr *name);
  461. struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh);
  462. struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
  463. struct dentry *origin, bool verify);
  464. int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
  465. struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
  466. unsigned int flags);
  467. bool ovl_lower_positive(struct dentry *dentry);
  468. static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper,
  469. struct dentry *origin, bool set)
  470. {
  471. return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin,
  472. false, set);
  473. }
  474. static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
  475. struct dentry *upper, bool set)
  476. {
  477. return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set);
  478. }
  479. /* readdir.c */
  480. extern const struct file_operations ovl_dir_operations;
  481. struct file *ovl_dir_real_file(const struct file *file, bool want_upper);
  482. int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
  483. void ovl_cleanup_whiteouts(struct ovl_fs *ofs, struct dentry *upper,
  484. struct list_head *list);
  485. void ovl_cache_free(struct list_head *list);
  486. void ovl_dir_cache_free(struct inode *inode);
  487. int ovl_check_d_type_supported(const struct path *realpath);
  488. int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir,
  489. struct vfsmount *mnt, struct dentry *dentry, int level);
  490. int ovl_indexdir_cleanup(struct ovl_fs *ofs);
  491. /*
  492. * Can we iterate real dir directly?
  493. *
  494. * Non-merge dir may contain whiteouts from a time it was a merge upper, before
  495. * lower dir was removed under it and possibly before it was rotated from upper
  496. * to lower layer.
  497. */
  498. static inline bool ovl_dir_is_real(struct dentry *dir)
  499. {
  500. return !ovl_test_flag(OVL_WHITEOUTS, d_inode(dir));
  501. }
  502. /* inode.c */
  503. int ovl_set_nlink_upper(struct dentry *dentry);
  504. int ovl_set_nlink_lower(struct dentry *dentry);
  505. unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
  506. struct dentry *upperdentry,
  507. unsigned int fallback);
  508. int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
  509. struct iattr *attr);
  510. int ovl_getattr(struct user_namespace *mnt_userns, const struct path *path,
  511. struct kstat *stat, u32 request_mask, unsigned int flags);
  512. int ovl_permission(struct user_namespace *mnt_userns, struct inode *inode,
  513. int mask);
  514. int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
  515. const void *value, size_t size, int flags);
  516. int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
  517. void *value, size_t size);
  518. ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
  519. #ifdef CONFIG_FS_POSIX_ACL
  520. struct posix_acl *ovl_get_acl(struct inode *inode, int type, bool rcu);
  521. #else
  522. #define ovl_get_acl NULL
  523. #endif
  524. int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags);
  525. bool ovl_is_private_xattr(struct super_block *sb, const char *name);
  526. struct ovl_inode_params {
  527. struct inode *newinode;
  528. struct dentry *upperdentry;
  529. struct ovl_path *lowerpath;
  530. bool index;
  531. unsigned int numlower;
  532. char *redirect;
  533. struct dentry *lowerdata;
  534. };
  535. void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
  536. unsigned long ino, int fsid);
  537. struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
  538. struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
  539. bool is_upper);
  540. bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir);
  541. struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir);
  542. struct inode *ovl_get_inode(struct super_block *sb,
  543. struct ovl_inode_params *oip);
  544. void ovl_copyattr(struct inode *to);
  545. /* vfs inode flags copied from real to ovl inode */
  546. #define OVL_COPY_I_FLAGS_MASK (S_SYNC | S_NOATIME | S_APPEND | S_IMMUTABLE)
  547. /* vfs inode flags read from overlay.protattr xattr to ovl inode */
  548. #define OVL_PROT_I_FLAGS_MASK (S_APPEND | S_IMMUTABLE)
  549. /*
  550. * fileattr flags copied from lower to upper inode on copy up.
  551. * We cannot copy up immutable/append-only flags, because that would prevent
  552. * linking temp inode to upper dir, so we store them in xattr instead.
  553. */
  554. #define OVL_COPY_FS_FLAGS_MASK (FS_SYNC_FL | FS_NOATIME_FL)
  555. #define OVL_COPY_FSX_FLAGS_MASK (FS_XFLAG_SYNC | FS_XFLAG_NOATIME)
  556. #define OVL_PROT_FS_FLAGS_MASK (FS_APPEND_FL | FS_IMMUTABLE_FL)
  557. #define OVL_PROT_FSX_FLAGS_MASK (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE)
  558. void ovl_check_protattr(struct inode *inode, struct dentry *upper);
  559. int ovl_set_protattr(struct inode *inode, struct dentry *upper,
  560. struct fileattr *fa);
  561. static inline void ovl_copyflags(struct inode *from, struct inode *to)
  562. {
  563. unsigned int mask = OVL_COPY_I_FLAGS_MASK;
  564. inode_set_flags(to, from->i_flags & mask, mask);
  565. }
  566. /* dir.c */
  567. extern const struct inode_operations ovl_dir_inode_operations;
  568. int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
  569. struct dentry *dentry);
  570. struct ovl_cattr {
  571. dev_t rdev;
  572. umode_t mode;
  573. const char *link;
  574. struct dentry *hardlink;
  575. };
  576. #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
  577. int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir,
  578. struct dentry **newdentry, umode_t mode);
  579. struct dentry *ovl_create_real(struct ovl_fs *ofs,
  580. struct inode *dir, struct dentry *newdentry,
  581. struct ovl_cattr *attr);
  582. int ovl_cleanup(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry);
  583. struct dentry *ovl_lookup_temp(struct ovl_fs *ofs, struct dentry *workdir);
  584. struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir,
  585. struct ovl_cattr *attr);
  586. /* file.c */
  587. extern const struct file_operations ovl_file_operations;
  588. int __init ovl_aio_request_cache_init(void);
  589. void ovl_aio_request_cache_destroy(void);
  590. int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa);
  591. int ovl_real_fileattr_set(const struct path *realpath, struct fileattr *fa);
  592. int ovl_fileattr_get(struct dentry *dentry, struct fileattr *fa);
  593. int ovl_fileattr_set(struct user_namespace *mnt_userns,
  594. struct dentry *dentry, struct fileattr *fa);
  595. /* copy_up.c */
  596. int ovl_copy_up(struct dentry *dentry);
  597. int ovl_copy_up_with_data(struct dentry *dentry);
  598. int ovl_maybe_copy_up(struct dentry *dentry, int flags);
  599. int ovl_copy_xattr(struct super_block *sb, const struct path *path, struct dentry *new);
  600. int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat);
  601. struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
  602. bool is_upper);
  603. int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
  604. struct dentry *upper);
  605. /* export.c */
  606. extern const struct export_operations ovl_export_operations;