nilfs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * NILFS local header file.
  4. *
  5. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Written by Koji Sato and Ryusuke Konishi.
  8. */
  9. #ifndef _NILFS_H
  10. #define _NILFS_H
  11. #include <linux/kernel.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/fs_struct.h>
  16. #include <linux/nilfs2_api.h>
  17. #include <linux/nilfs2_ondisk.h>
  18. #include "the_nilfs.h"
  19. #include "bmap.h"
  20. /**
  21. * struct nilfs_inode_info - nilfs inode data in memory
  22. * @i_flags: inode flags
  23. * @i_type: inode type (combination of flags that inidicate usage)
  24. * @i_state: dynamic state flags
  25. * @i_bmap: pointer on i_bmap_data
  26. * @i_bmap_data: raw block mapping
  27. * @i_xattr: <TODO>
  28. * @i_dir_start_lookup: page index of last successful search
  29. * @i_cno: checkpoint number for GC inode
  30. * @i_assoc_inode: associated inode (B-tree node cache holder or back pointer)
  31. * @i_dirty: list for connecting dirty files
  32. * @xattr_sem: semaphore for extended attributes processing
  33. * @i_bh: buffer contains disk inode
  34. * @i_root: root object of the current filesystem tree
  35. * @vfs_inode: VFS inode object
  36. */
  37. struct nilfs_inode_info {
  38. __u32 i_flags;
  39. unsigned int i_type;
  40. unsigned long i_state; /* Dynamic state flags */
  41. struct nilfs_bmap *i_bmap;
  42. struct nilfs_bmap i_bmap_data;
  43. __u64 i_xattr; /* sector_t ??? */
  44. __u32 i_dir_start_lookup;
  45. __u64 i_cno; /* check point number for GC inode */
  46. struct inode *i_assoc_inode;
  47. struct list_head i_dirty; /* List for connecting dirty files */
  48. #ifdef CONFIG_NILFS_XATTR
  49. /*
  50. * Extended attributes can be read independently of the main file
  51. * data. Taking i_sem even when reading would cause contention
  52. * between readers of EAs and writers of regular file data, so
  53. * instead we synchronize on xattr_sem when reading or changing
  54. * EAs.
  55. */
  56. struct rw_semaphore xattr_sem;
  57. #endif
  58. struct buffer_head *i_bh; /*
  59. * i_bh contains a new or dirty
  60. * disk inode.
  61. */
  62. struct nilfs_root *i_root;
  63. struct inode vfs_inode;
  64. };
  65. static inline struct nilfs_inode_info *NILFS_I(const struct inode *inode)
  66. {
  67. return container_of(inode, struct nilfs_inode_info, vfs_inode);
  68. }
  69. static inline struct nilfs_inode_info *
  70. NILFS_BMAP_I(const struct nilfs_bmap *bmap)
  71. {
  72. return container_of(bmap, struct nilfs_inode_info, i_bmap_data);
  73. }
  74. /*
  75. * Dynamic state flags of NILFS on-memory inode (i_state)
  76. */
  77. enum {
  78. NILFS_I_NEW = 0, /* Inode is newly created */
  79. NILFS_I_DIRTY, /* The file is dirty */
  80. NILFS_I_QUEUED, /* inode is in dirty_files list */
  81. NILFS_I_BUSY, /*
  82. * Inode is grabbed by a segment
  83. * constructor
  84. */
  85. NILFS_I_COLLECTED, /* All dirty blocks are collected */
  86. NILFS_I_UPDATED, /* The file has been written back */
  87. NILFS_I_INODE_SYNC, /* dsync is not allowed for inode */
  88. NILFS_I_BMAP, /* has bmap and btnode_cache */
  89. };
  90. /*
  91. * Flags to identify the usage of on-memory inodes (i_type)
  92. */
  93. enum {
  94. NILFS_I_TYPE_NORMAL = 0,
  95. NILFS_I_TYPE_GC = 0x0001, /* For data caching during GC */
  96. NILFS_I_TYPE_BTNC = 0x0002, /* For btree node cache */
  97. NILFS_I_TYPE_SHADOW = 0x0004, /* For shadowed page cache */
  98. };
  99. /*
  100. * commit flags for nilfs_commit_super and nilfs_sync_super
  101. */
  102. enum {
  103. NILFS_SB_COMMIT = 0, /* Commit a super block alternately */
  104. NILFS_SB_COMMIT_ALL /* Commit both super blocks */
  105. };
  106. /**
  107. * define NILFS_MAX_VOLUME_NAME - maximum number of characters (bytes) in a
  108. * file system volume name
  109. *
  110. * Defined by the size of the volume name field in the on-disk superblocks.
  111. * This volume name does not include the terminating NULL byte if the string
  112. * length matches the field size, so use (NILFS_MAX_VOLUME_NAME + 1) for the
  113. * size of the buffer that requires a NULL byte termination.
  114. */
  115. #define NILFS_MAX_VOLUME_NAME \
  116. sizeof_field(struct nilfs_super_block, s_volume_name)
  117. /*
  118. * Macros to check inode numbers
  119. */
  120. #define NILFS_MDT_INO_BITS \
  121. (BIT(NILFS_DAT_INO) | BIT(NILFS_CPFILE_INO) | \
  122. BIT(NILFS_SUFILE_INO) | BIT(NILFS_IFILE_INO) | \
  123. BIT(NILFS_ATIME_INO) | BIT(NILFS_SKETCH_INO))
  124. #define NILFS_SYS_INO_BITS (BIT(NILFS_ROOT_INO) | NILFS_MDT_INO_BITS)
  125. #define NILFS_FIRST_INO(sb) (((struct the_nilfs *)sb->s_fs_info)->ns_first_ino)
  126. #define NILFS_MDT_INODE(sb, ino) \
  127. ((ino) < NILFS_USER_INO && (NILFS_MDT_INO_BITS & BIT(ino)))
  128. #define NILFS_VALID_INODE(sb, ino) \
  129. ((ino) >= NILFS_FIRST_INO(sb) || \
  130. ((ino) < NILFS_USER_INO && (NILFS_SYS_INO_BITS & BIT(ino))))
  131. #define NILFS_PRIVATE_INODE(ino) ({ \
  132. ino_t __ino = (ino); \
  133. ((__ino) < NILFS_USER_INO && (__ino) != NILFS_ROOT_INO && \
  134. (__ino) != NILFS_SKETCH_INO); })
  135. /**
  136. * struct nilfs_transaction_info: context information for synchronization
  137. * @ti_magic: Magic number
  138. * @ti_save: Backup of journal_info field of task_struct
  139. * @ti_flags: Flags
  140. * @ti_count: Nest level
  141. */
  142. struct nilfs_transaction_info {
  143. u32 ti_magic;
  144. void *ti_save;
  145. /*
  146. * This should never be used. If it happens,
  147. * one of other filesystems has a bug.
  148. */
  149. unsigned short ti_flags;
  150. unsigned short ti_count;
  151. };
  152. /* ti_magic */
  153. #define NILFS_TI_MAGIC 0xd9e392fb
  154. /* ti_flags */
  155. #define NILFS_TI_DYNAMIC_ALLOC 0x0001 /* Allocated from slab */
  156. #define NILFS_TI_SYNC 0x0002 /*
  157. * Force to construct segment at the
  158. * end of transaction.
  159. */
  160. #define NILFS_TI_GC 0x0004 /* GC context */
  161. #define NILFS_TI_COMMIT 0x0008 /* Change happened or not */
  162. #define NILFS_TI_WRITER 0x0010 /* Constructor context */
  163. int nilfs_transaction_begin(struct super_block *,
  164. struct nilfs_transaction_info *, int);
  165. int nilfs_transaction_commit(struct super_block *);
  166. void nilfs_transaction_abort(struct super_block *);
  167. static inline void nilfs_set_transaction_flag(unsigned int flag)
  168. {
  169. struct nilfs_transaction_info *ti = current->journal_info;
  170. ti->ti_flags |= flag;
  171. }
  172. static inline int nilfs_test_transaction_flag(unsigned int flag)
  173. {
  174. struct nilfs_transaction_info *ti = current->journal_info;
  175. if (ti == NULL || ti->ti_magic != NILFS_TI_MAGIC)
  176. return 0;
  177. return !!(ti->ti_flags & flag);
  178. }
  179. static inline int nilfs_doing_gc(void)
  180. {
  181. return nilfs_test_transaction_flag(NILFS_TI_GC);
  182. }
  183. static inline int nilfs_doing_construction(void)
  184. {
  185. return nilfs_test_transaction_flag(NILFS_TI_WRITER);
  186. }
  187. /*
  188. * function prototype
  189. */
  190. #ifdef CONFIG_NILFS_POSIX_ACL
  191. #error "NILFS: not yet supported POSIX ACL"
  192. extern int nilfs_acl_chmod(struct inode *);
  193. extern int nilfs_init_acl(struct inode *, struct inode *);
  194. #else
  195. static inline int nilfs_acl_chmod(struct inode *inode)
  196. {
  197. return 0;
  198. }
  199. static inline int nilfs_init_acl(struct inode *inode, struct inode *dir)
  200. {
  201. if (S_ISLNK(inode->i_mode))
  202. return 0;
  203. inode->i_mode &= ~current_umask();
  204. return 0;
  205. }
  206. #endif
  207. #define NILFS_ATIME_DISABLE
  208. /* Flags that should be inherited by new inodes from their parent. */
  209. #define NILFS_FL_INHERITED \
  210. (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \
  211. FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\
  212. FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)
  213. /* Mask out flags that are inappropriate for the given type of inode. */
  214. static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)
  215. {
  216. if (S_ISDIR(mode))
  217. return flags;
  218. else if (S_ISREG(mode))
  219. return flags & ~(FS_DIRSYNC_FL | FS_TOPDIR_FL);
  220. else
  221. return flags & (FS_NODUMP_FL | FS_NOATIME_FL);
  222. }
  223. /* dir.c */
  224. int nilfs_add_link(struct dentry *, struct inode *);
  225. int nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr, ino_t *ino);
  226. int nilfs_make_empty(struct inode *, struct inode *);
  227. struct nilfs_dir_entry *nilfs_find_entry(struct inode *, const struct qstr *,
  228. struct folio **);
  229. int nilfs_delete_entry(struct nilfs_dir_entry *, struct folio *);
  230. int nilfs_empty_dir(struct inode *);
  231. struct nilfs_dir_entry *nilfs_dotdot(struct inode *, struct folio **);
  232. int nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,
  233. struct folio *folio, struct inode *inode);
  234. /* file.c */
  235. extern int nilfs_sync_file(struct file *, loff_t, loff_t, int);
  236. /* ioctl.c */
  237. int nilfs_fileattr_get(struct dentry *dentry, struct file_kattr *m);
  238. int nilfs_fileattr_set(struct mnt_idmap *idmap,
  239. struct dentry *dentry, struct file_kattr *fa);
  240. long nilfs_ioctl(struct file *, unsigned int, unsigned long);
  241. long nilfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  242. int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,
  243. void **);
  244. /* inode.c */
  245. void nilfs_inode_add_blocks(struct inode *inode, int n);
  246. void nilfs_inode_sub_blocks(struct inode *inode, int n);
  247. extern struct inode *nilfs_new_inode(struct inode *, umode_t);
  248. extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
  249. extern void nilfs_set_inode_flags(struct inode *);
  250. extern int nilfs_read_inode_common(struct inode *, struct nilfs_inode *);
  251. void nilfs_write_inode_common(struct inode *inode,
  252. struct nilfs_inode *raw_inode);
  253. struct inode *nilfs_ilookup(struct super_block *sb, struct nilfs_root *root,
  254. unsigned long ino);
  255. struct inode *nilfs_iget_locked(struct super_block *sb, struct nilfs_root *root,
  256. unsigned long ino);
  257. struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
  258. unsigned long ino);
  259. extern struct inode *nilfs_iget_for_gc(struct super_block *sb,
  260. unsigned long ino, __u64 cno);
  261. int nilfs_attach_btree_node_cache(struct inode *inode);
  262. void nilfs_detach_btree_node_cache(struct inode *inode);
  263. struct inode *nilfs_iget_for_shadow(struct inode *inode);
  264. extern void nilfs_update_inode(struct inode *, struct buffer_head *, int);
  265. extern void nilfs_truncate(struct inode *);
  266. extern void nilfs_evict_inode(struct inode *);
  267. extern int nilfs_setattr(struct mnt_idmap *, struct dentry *,
  268. struct iattr *);
  269. extern void nilfs_write_failed(struct address_space *mapping, loff_t to);
  270. int nilfs_permission(struct mnt_idmap *idmap, struct inode *inode,
  271. int mask);
  272. int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh);
  273. extern int nilfs_inode_dirty(struct inode *);
  274. int nilfs_set_file_dirty(struct inode *inode, unsigned int nr_dirty);
  275. extern int __nilfs_mark_inode_dirty(struct inode *, int);
  276. extern void nilfs_dirty_inode(struct inode *, int flags);
  277. int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  278. __u64 start, __u64 len);
  279. static inline int nilfs_mark_inode_dirty(struct inode *inode)
  280. {
  281. return __nilfs_mark_inode_dirty(inode, I_DIRTY);
  282. }
  283. static inline int nilfs_mark_inode_dirty_sync(struct inode *inode)
  284. {
  285. return __nilfs_mark_inode_dirty(inode, I_DIRTY_SYNC);
  286. }
  287. /* super.c */
  288. extern struct inode *nilfs_alloc_inode(struct super_block *);
  289. __printf(2, 3)
  290. void __nilfs_msg(struct super_block *sb, const char *fmt, ...);
  291. extern __printf(3, 4)
  292. void __nilfs_error(struct super_block *sb, const char *function,
  293. const char *fmt, ...);
  294. #ifdef CONFIG_PRINTK
  295. #define nilfs_msg(sb, level, fmt, ...) \
  296. __nilfs_msg(sb, level fmt, ##__VA_ARGS__)
  297. #define nilfs_error(sb, fmt, ...) \
  298. __nilfs_error(sb, __func__, fmt, ##__VA_ARGS__)
  299. #else
  300. #define nilfs_msg(sb, level, fmt, ...) \
  301. do { \
  302. no_printk(level fmt, ##__VA_ARGS__); \
  303. (void)(sb); \
  304. } while (0)
  305. #define nilfs_error(sb, fmt, ...) \
  306. do { \
  307. no_printk(fmt, ##__VA_ARGS__); \
  308. __nilfs_error(sb, "", " "); \
  309. } while (0)
  310. #endif /* CONFIG_PRINTK */
  311. #define nilfs_crit(sb, fmt, ...) \
  312. nilfs_msg(sb, KERN_CRIT, fmt, ##__VA_ARGS__)
  313. #define nilfs_err(sb, fmt, ...) \
  314. nilfs_msg(sb, KERN_ERR, fmt, ##__VA_ARGS__)
  315. #define nilfs_warn(sb, fmt, ...) \
  316. nilfs_msg(sb, KERN_WARNING, fmt, ##__VA_ARGS__)
  317. #define nilfs_info(sb, fmt, ...) \
  318. nilfs_msg(sb, KERN_INFO, fmt, ##__VA_ARGS__)
  319. extern struct nilfs_super_block *
  320. nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **);
  321. extern int nilfs_store_magic(struct super_block *sb,
  322. struct nilfs_super_block *sbp);
  323. extern int nilfs_check_feature_compatibility(struct super_block *,
  324. struct nilfs_super_block *);
  325. extern void nilfs_set_log_cursor(struct nilfs_super_block *,
  326. struct the_nilfs *);
  327. struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
  328. int flip);
  329. int nilfs_commit_super(struct super_block *sb, int flag);
  330. int nilfs_cleanup_super(struct super_block *sb);
  331. int nilfs_resize_fs(struct super_block *sb, __u64 newsize);
  332. int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
  333. struct nilfs_root **root);
  334. int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno);
  335. /* gcinode.c */
  336. int nilfs_gccache_submit_read_data(struct inode *, sector_t, sector_t, __u64,
  337. struct buffer_head **);
  338. int nilfs_gccache_submit_read_node(struct inode *, sector_t, __u64,
  339. struct buffer_head **);
  340. int nilfs_gccache_wait_and_mark_dirty(struct buffer_head *);
  341. int nilfs_init_gcinode(struct inode *inode);
  342. void nilfs_remove_all_gcinodes(struct the_nilfs *nilfs);
  343. /* sysfs.c */
  344. int __init nilfs_sysfs_init(void);
  345. void nilfs_sysfs_exit(void);
  346. int nilfs_sysfs_create_device_group(struct super_block *);
  347. void nilfs_sysfs_delete_device_group(struct the_nilfs *);
  348. int nilfs_sysfs_create_snapshot_group(struct nilfs_root *);
  349. void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *);
  350. /*
  351. * Inodes and files operations
  352. */
  353. extern const struct file_operations nilfs_dir_operations;
  354. extern const struct inode_operations nilfs_file_inode_operations;
  355. extern const struct file_operations nilfs_file_operations;
  356. extern const struct address_space_operations nilfs_aops;
  357. extern const struct address_space_operations nilfs_buffer_cache_aops;
  358. extern const struct inode_operations nilfs_dir_inode_operations;
  359. extern const struct inode_operations nilfs_special_inode_operations;
  360. extern const struct inode_operations nilfs_symlink_inode_operations;
  361. /*
  362. * filesystem type
  363. */
  364. extern struct file_system_type nilfs_fs_type;
  365. #endif /* _NILFS_H */