Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * NILFS local header file.
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * Written by Koji Sato and Ryusuke Konishi.
0008  */
0009 
0010 #ifndef _NILFS_H
0011 #define _NILFS_H
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/buffer_head.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/blkdev.h>
0017 #include <linux/nilfs2_api.h>
0018 #include <linux/nilfs2_ondisk.h>
0019 #include "the_nilfs.h"
0020 #include "bmap.h"
0021 
0022 /**
0023  * struct nilfs_inode_info - nilfs inode data in memory
0024  * @i_flags: inode flags
0025  * @i_state: dynamic state flags
0026  * @i_bmap: pointer on i_bmap_data
0027  * @i_bmap_data: raw block mapping
0028  * @i_xattr: <TODO>
0029  * @i_dir_start_lookup: page index of last successful search
0030  * @i_cno: checkpoint number for GC inode
0031  * @i_assoc_inode: associated inode (B-tree node cache holder or back pointer)
0032  * @i_dirty: list for connecting dirty files
0033  * @xattr_sem: semaphore for extended attributes processing
0034  * @i_bh: buffer contains disk inode
0035  * @i_root: root object of the current filesystem tree
0036  * @vfs_inode: VFS inode object
0037  */
0038 struct nilfs_inode_info {
0039     __u32 i_flags;
0040     unsigned long  i_state;     /* Dynamic state flags */
0041     struct nilfs_bmap *i_bmap;
0042     struct nilfs_bmap i_bmap_data;
0043     __u64 i_xattr;  /* sector_t ??? */
0044     __u32 i_dir_start_lookup;
0045     __u64 i_cno;        /* check point number for GC inode */
0046     struct inode *i_assoc_inode;
0047     struct list_head i_dirty;   /* List for connecting dirty files */
0048 
0049 #ifdef CONFIG_NILFS_XATTR
0050     /*
0051      * Extended attributes can be read independently of the main file
0052      * data. Taking i_sem even when reading would cause contention
0053      * between readers of EAs and writers of regular file data, so
0054      * instead we synchronize on xattr_sem when reading or changing
0055      * EAs.
0056      */
0057     struct rw_semaphore xattr_sem;
0058 #endif
0059     struct buffer_head *i_bh;   /*
0060                      * i_bh contains a new or dirty
0061                      * disk inode.
0062                      */
0063     struct nilfs_root *i_root;
0064     struct inode vfs_inode;
0065 };
0066 
0067 static inline struct nilfs_inode_info *NILFS_I(const struct inode *inode)
0068 {
0069     return container_of(inode, struct nilfs_inode_info, vfs_inode);
0070 }
0071 
0072 static inline struct nilfs_inode_info *
0073 NILFS_BMAP_I(const struct nilfs_bmap *bmap)
0074 {
0075     return container_of(bmap, struct nilfs_inode_info, i_bmap_data);
0076 }
0077 
0078 /*
0079  * Dynamic state flags of NILFS on-memory inode (i_state)
0080  */
0081 enum {
0082     NILFS_I_NEW = 0,        /* Inode is newly created */
0083     NILFS_I_DIRTY,          /* The file is dirty */
0084     NILFS_I_QUEUED,         /* inode is in dirty_files list */
0085     NILFS_I_BUSY,           /*
0086                      * Inode is grabbed by a segment
0087                      * constructor
0088                      */
0089     NILFS_I_COLLECTED,      /* All dirty blocks are collected */
0090     NILFS_I_UPDATED,        /* The file has been written back */
0091     NILFS_I_INODE_SYNC,     /* dsync is not allowed for inode */
0092     NILFS_I_BMAP,           /* has bmap and btnode_cache */
0093     NILFS_I_GCINODE,        /* inode for GC, on memory only */
0094     NILFS_I_BTNC,           /* inode for btree node cache */
0095     NILFS_I_SHADOW,         /* inode for shadowed page cache */
0096 };
0097 
0098 /*
0099  * commit flags for nilfs_commit_super and nilfs_sync_super
0100  */
0101 enum {
0102     NILFS_SB_COMMIT = 0,    /* Commit a super block alternately */
0103     NILFS_SB_COMMIT_ALL /* Commit both super blocks */
0104 };
0105 
0106 /*
0107  * Macros to check inode numbers
0108  */
0109 #define NILFS_MDT_INO_BITS                      \
0110     (BIT(NILFS_DAT_INO) | BIT(NILFS_CPFILE_INO) |           \
0111      BIT(NILFS_SUFILE_INO) | BIT(NILFS_IFILE_INO) |         \
0112      BIT(NILFS_ATIME_INO) | BIT(NILFS_SKETCH_INO))
0113 
0114 #define NILFS_SYS_INO_BITS (BIT(NILFS_ROOT_INO) | NILFS_MDT_INO_BITS)
0115 
0116 #define NILFS_FIRST_INO(sb) (((struct the_nilfs *)sb->s_fs_info)->ns_first_ino)
0117 
0118 #define NILFS_MDT_INODE(sb, ino) \
0119     ((ino) < NILFS_FIRST_INO(sb) && (NILFS_MDT_INO_BITS & BIT(ino)))
0120 #define NILFS_VALID_INODE(sb, ino) \
0121     ((ino) >= NILFS_FIRST_INO(sb) || (NILFS_SYS_INO_BITS & BIT(ino)))
0122 
0123 /**
0124  * struct nilfs_transaction_info: context information for synchronization
0125  * @ti_magic: Magic number
0126  * @ti_save: Backup of journal_info field of task_struct
0127  * @ti_flags: Flags
0128  * @ti_count: Nest level
0129  */
0130 struct nilfs_transaction_info {
0131     u32         ti_magic;
0132     void               *ti_save;
0133                 /*
0134                  * This should never be used.  If it happens,
0135                  * one of other filesystems has a bug.
0136                  */
0137     unsigned short      ti_flags;
0138     unsigned short      ti_count;
0139 };
0140 
0141 /* ti_magic */
0142 #define NILFS_TI_MAGIC      0xd9e392fb
0143 
0144 /* ti_flags */
0145 #define NILFS_TI_DYNAMIC_ALLOC  0x0001  /* Allocated from slab */
0146 #define NILFS_TI_SYNC       0x0002  /*
0147                      * Force to construct segment at the
0148                      * end of transaction.
0149                      */
0150 #define NILFS_TI_GC     0x0004  /* GC context */
0151 #define NILFS_TI_COMMIT     0x0008  /* Change happened or not */
0152 #define NILFS_TI_WRITER     0x0010  /* Constructor context */
0153 
0154 
0155 int nilfs_transaction_begin(struct super_block *,
0156                 struct nilfs_transaction_info *, int);
0157 int nilfs_transaction_commit(struct super_block *);
0158 void nilfs_transaction_abort(struct super_block *);
0159 
0160 static inline void nilfs_set_transaction_flag(unsigned int flag)
0161 {
0162     struct nilfs_transaction_info *ti = current->journal_info;
0163 
0164     ti->ti_flags |= flag;
0165 }
0166 
0167 static inline int nilfs_test_transaction_flag(unsigned int flag)
0168 {
0169     struct nilfs_transaction_info *ti = current->journal_info;
0170 
0171     if (ti == NULL || ti->ti_magic != NILFS_TI_MAGIC)
0172         return 0;
0173     return !!(ti->ti_flags & flag);
0174 }
0175 
0176 static inline int nilfs_doing_gc(void)
0177 {
0178     return nilfs_test_transaction_flag(NILFS_TI_GC);
0179 }
0180 
0181 static inline int nilfs_doing_construction(void)
0182 {
0183     return nilfs_test_transaction_flag(NILFS_TI_WRITER);
0184 }
0185 
0186 /*
0187  * function prototype
0188  */
0189 #ifdef CONFIG_NILFS_POSIX_ACL
0190 #error "NILFS: not yet supported POSIX ACL"
0191 extern int nilfs_acl_chmod(struct inode *);
0192 extern int nilfs_init_acl(struct inode *, struct inode *);
0193 #else
0194 static inline int nilfs_acl_chmod(struct inode *inode)
0195 {
0196     return 0;
0197 }
0198 
0199 static inline int nilfs_init_acl(struct inode *inode, struct inode *dir)
0200 {
0201     if (S_ISLNK(inode->i_mode))
0202         return 0;
0203 
0204     inode->i_mode &= ~current_umask();
0205     return 0;
0206 }
0207 #endif
0208 
0209 #define NILFS_ATIME_DISABLE
0210 
0211 /* Flags that should be inherited by new inodes from their parent. */
0212 #define NILFS_FL_INHERITED                      \
0213     (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL |      \
0214      FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\
0215      FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)
0216 
0217 /* Mask out flags that are inappropriate for the given type of inode. */
0218 static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)
0219 {
0220     if (S_ISDIR(mode))
0221         return flags;
0222     else if (S_ISREG(mode))
0223         return flags & ~(FS_DIRSYNC_FL | FS_TOPDIR_FL);
0224     else
0225         return flags & (FS_NODUMP_FL | FS_NOATIME_FL);
0226 }
0227 
0228 /* dir.c */
0229 extern int nilfs_add_link(struct dentry *, struct inode *);
0230 extern ino_t nilfs_inode_by_name(struct inode *, const struct qstr *);
0231 extern int nilfs_make_empty(struct inode *, struct inode *);
0232 extern struct nilfs_dir_entry *
0233 nilfs_find_entry(struct inode *, const struct qstr *, struct page **);
0234 extern int nilfs_delete_entry(struct nilfs_dir_entry *, struct page *);
0235 extern int nilfs_empty_dir(struct inode *);
0236 extern struct nilfs_dir_entry *nilfs_dotdot(struct inode *, struct page **);
0237 extern void nilfs_set_link(struct inode *, struct nilfs_dir_entry *,
0238                struct page *, struct inode *);
0239 
0240 /* file.c */
0241 extern int nilfs_sync_file(struct file *, loff_t, loff_t, int);
0242 
0243 /* ioctl.c */
0244 int nilfs_fileattr_get(struct dentry *dentry, struct fileattr *m);
0245 int nilfs_fileattr_set(struct user_namespace *mnt_userns,
0246                struct dentry *dentry, struct fileattr *fa);
0247 long nilfs_ioctl(struct file *, unsigned int, unsigned long);
0248 long nilfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
0249 int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,
0250                        void **);
0251 
0252 /* inode.c */
0253 void nilfs_inode_add_blocks(struct inode *inode, int n);
0254 void nilfs_inode_sub_blocks(struct inode *inode, int n);
0255 extern struct inode *nilfs_new_inode(struct inode *, umode_t);
0256 extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
0257 extern void nilfs_set_inode_flags(struct inode *);
0258 extern int nilfs_read_inode_common(struct inode *, struct nilfs_inode *);
0259 extern void nilfs_write_inode_common(struct inode *, struct nilfs_inode *, int);
0260 struct inode *nilfs_ilookup(struct super_block *sb, struct nilfs_root *root,
0261                 unsigned long ino);
0262 struct inode *nilfs_iget_locked(struct super_block *sb, struct nilfs_root *root,
0263                 unsigned long ino);
0264 struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
0265              unsigned long ino);
0266 extern struct inode *nilfs_iget_for_gc(struct super_block *sb,
0267                        unsigned long ino, __u64 cno);
0268 int nilfs_attach_btree_node_cache(struct inode *inode);
0269 void nilfs_detach_btree_node_cache(struct inode *inode);
0270 struct inode *nilfs_iget_for_shadow(struct inode *inode);
0271 extern void nilfs_update_inode(struct inode *, struct buffer_head *, int);
0272 extern void nilfs_truncate(struct inode *);
0273 extern void nilfs_evict_inode(struct inode *);
0274 extern int nilfs_setattr(struct user_namespace *, struct dentry *,
0275              struct iattr *);
0276 extern void nilfs_write_failed(struct address_space *mapping, loff_t to);
0277 int nilfs_permission(struct user_namespace *mnt_userns, struct inode *inode,
0278              int mask);
0279 int nilfs_load_inode_block(struct inode *inode, struct buffer_head **pbh);
0280 extern int nilfs_inode_dirty(struct inode *);
0281 int nilfs_set_file_dirty(struct inode *inode, unsigned int nr_dirty);
0282 extern int __nilfs_mark_inode_dirty(struct inode *, int);
0283 extern void nilfs_dirty_inode(struct inode *, int flags);
0284 int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
0285          __u64 start, __u64 len);
0286 static inline int nilfs_mark_inode_dirty(struct inode *inode)
0287 {
0288     return __nilfs_mark_inode_dirty(inode, I_DIRTY);
0289 }
0290 static inline int nilfs_mark_inode_dirty_sync(struct inode *inode)
0291 {
0292     return __nilfs_mark_inode_dirty(inode, I_DIRTY_SYNC);
0293 }
0294 
0295 /* super.c */
0296 extern struct inode *nilfs_alloc_inode(struct super_block *);
0297 
0298 __printf(2, 3)
0299 void __nilfs_msg(struct super_block *sb, const char *fmt, ...);
0300 extern __printf(3, 4)
0301 void __nilfs_error(struct super_block *sb, const char *function,
0302            const char *fmt, ...);
0303 
0304 #ifdef CONFIG_PRINTK
0305 
0306 #define nilfs_msg(sb, level, fmt, ...)                  \
0307     __nilfs_msg(sb, level fmt, ##__VA_ARGS__)
0308 #define nilfs_error(sb, fmt, ...)                   \
0309     __nilfs_error(sb, __func__, fmt, ##__VA_ARGS__)
0310 
0311 #else
0312 
0313 #define nilfs_msg(sb, level, fmt, ...)                  \
0314     do {                                \
0315         no_printk(level fmt, ##__VA_ARGS__);            \
0316         (void)(sb);                     \
0317     } while (0)
0318 #define nilfs_error(sb, fmt, ...)                   \
0319     do {                                \
0320         no_printk(fmt, ##__VA_ARGS__);              \
0321         __nilfs_error(sb, "", " ");             \
0322     } while (0)
0323 
0324 #endif /* CONFIG_PRINTK */
0325 
0326 #define nilfs_crit(sb, fmt, ...)                    \
0327     nilfs_msg(sb, KERN_CRIT, fmt, ##__VA_ARGS__)
0328 #define nilfs_err(sb, fmt, ...)                     \
0329     nilfs_msg(sb, KERN_ERR, fmt, ##__VA_ARGS__)
0330 #define nilfs_warn(sb, fmt, ...)                    \
0331     nilfs_msg(sb, KERN_WARNING, fmt, ##__VA_ARGS__)
0332 #define nilfs_info(sb, fmt, ...)                    \
0333     nilfs_msg(sb, KERN_INFO, fmt, ##__VA_ARGS__)
0334 
0335 extern struct nilfs_super_block *
0336 nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **);
0337 extern int nilfs_store_magic_and_option(struct super_block *,
0338                     struct nilfs_super_block *, char *);
0339 extern int nilfs_check_feature_compatibility(struct super_block *,
0340                          struct nilfs_super_block *);
0341 extern void nilfs_set_log_cursor(struct nilfs_super_block *,
0342                  struct the_nilfs *);
0343 struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
0344                            int flip);
0345 int nilfs_commit_super(struct super_block *sb, int flag);
0346 int nilfs_cleanup_super(struct super_block *sb);
0347 int nilfs_resize_fs(struct super_block *sb, __u64 newsize);
0348 int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
0349                 struct nilfs_root **root);
0350 int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno);
0351 
0352 /* gcinode.c */
0353 int nilfs_gccache_submit_read_data(struct inode *, sector_t, sector_t, __u64,
0354                    struct buffer_head **);
0355 int nilfs_gccache_submit_read_node(struct inode *, sector_t, __u64,
0356                    struct buffer_head **);
0357 int nilfs_gccache_wait_and_mark_dirty(struct buffer_head *);
0358 int nilfs_init_gcinode(struct inode *inode);
0359 void nilfs_remove_all_gcinodes(struct the_nilfs *nilfs);
0360 
0361 /* sysfs.c */
0362 int __init nilfs_sysfs_init(void);
0363 void nilfs_sysfs_exit(void);
0364 int nilfs_sysfs_create_device_group(struct super_block *);
0365 void nilfs_sysfs_delete_device_group(struct the_nilfs *);
0366 int nilfs_sysfs_create_snapshot_group(struct nilfs_root *);
0367 void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *);
0368 
0369 /*
0370  * Inodes and files operations
0371  */
0372 extern const struct file_operations nilfs_dir_operations;
0373 extern const struct inode_operations nilfs_file_inode_operations;
0374 extern const struct file_operations nilfs_file_operations;
0375 extern const struct address_space_operations nilfs_aops;
0376 extern const struct inode_operations nilfs_dir_inode_operations;
0377 extern const struct inode_operations nilfs_special_inode_operations;
0378 extern const struct inode_operations nilfs_symlink_inode_operations;
0379 
0380 /*
0381  * filesystem type
0382  */
0383 extern struct file_system_type nilfs_fs_type;
0384 
0385 
0386 #endif  /* _NILFS_H */