nilfs.h 14 KB

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