nilfs.h 13 KB

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