nilfs.h 12 KB

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