Line data Source code
1 : /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 : /* 3 : * Copyright (C) 2018-2023 Oracle. All Rights Reserved. 4 : * Author: Darrick J. Wong <djwong@kernel.org> 5 : */ 6 : #ifndef __XFS_IMETA_H__ 7 : #define __XFS_IMETA_H__ 8 : 9 : /* How deep can we nest metadata dirs? */ 10 : #define XFS_IMETA_MAX_DEPTH 64 11 : 12 : /* Form an imeta path from a simple array of strings. */ 13 : #define XFS_IMETA_DEFINE_PATH(name, path) \ 14 : const struct xfs_imeta_path name = { \ 15 : .im_path = (path), \ 16 : .im_ftype = XFS_DIR3_FT_REG_FILE, \ 17 : .im_depth = ARRAY_SIZE(path), \ 18 : .im_dynamicmask = 0, \ 19 : } 20 : 21 : /* Key for looking up metadata inodes. */ 22 : struct xfs_imeta_path { 23 : /* Array of string pointers. */ 24 : const unsigned char **im_path; 25 : 26 : /* Number of strings in path. */ 27 : unsigned int im_depth; 28 : 29 : /* Expected file type. */ 30 : unsigned int im_ftype; 31 : 32 : /* Each bit corresponds to an element of im_path needing to be freed */ 33 : unsigned long long im_dynamicmask; 34 : }; 35 : 36 : /* Cleanup widget for metadata inode creation and deletion. */ 37 : struct xfs_imeta_update { 38 : struct xfs_mount *mp; 39 : struct xfs_trans *tp; 40 : 41 : const struct xfs_imeta_path *path; 42 : 43 : struct xfs_parent_defer *parent; 44 : 45 : /* Parent directory */ 46 : struct xfs_inode *dp; 47 : 48 : /* Metadata inode */ 49 : struct xfs_inode *ip; 50 : 51 : unsigned int dp_locked:1; 52 : unsigned int ip_locked:1; 53 : }; 54 : 55 : /* Grab the last path component, mostly for tracing. */ 56 : static inline const unsigned char * 57 0 : xfs_imeta_lastpath( 58 : const struct xfs_imeta_update *upd) 59 : { 60 0 : if (upd->path && upd->path->im_path && upd->path->im_depth > 0) 61 0 : return upd->path->im_path[upd->path->im_depth - 1]; 62 : return "?"; 63 : } 64 : 65 : /* Lookup keys for static metadata inodes. */ 66 : extern const struct xfs_imeta_path XFS_IMETA_RTBITMAP; 67 : extern const struct xfs_imeta_path XFS_IMETA_RTSUMMARY; 68 : extern const struct xfs_imeta_path XFS_IMETA_USRQUOTA; 69 : extern const struct xfs_imeta_path XFS_IMETA_GRPQUOTA; 70 : extern const struct xfs_imeta_path XFS_IMETA_PRJQUOTA; 71 : extern const struct xfs_imeta_path XFS_IMETA_METADIR; 72 : 73 : int xfs_imeta_lookup(struct xfs_mount *mp, const struct xfs_imeta_path *path, 74 : xfs_ino_t *ino); 75 : int xfs_imeta_dir_parent(struct xfs_mount *mp, 76 : const struct xfs_imeta_path *path, struct xfs_inode **dpp); 77 : 78 : int xfs_imeta_create_file_path(struct xfs_mount *mp, 79 : unsigned int nr_components, struct xfs_imeta_path **pathp); 80 : void xfs_imeta_free_path(struct xfs_imeta_path *path); 81 : 82 : void xfs_imeta_set_iflag(struct xfs_trans *tp, struct xfs_inode *ip); 83 : 84 : int xfs_imeta_create(struct xfs_imeta_update *upd, umode_t mode, 85 : struct xfs_inode **ipp); 86 : int xfs_imeta_unlink(struct xfs_imeta_update *upd); 87 : int xfs_imeta_link(struct xfs_imeta_update *upd); 88 : 89 : bool xfs_is_static_meta_ino(struct xfs_mount *mp, xfs_ino_t ino); 90 : int xfs_imeta_mount(struct xfs_mount *mp); 91 : void xfs_imeta_droplink(struct xfs_inode *ip); 92 : 93 : unsigned int xfs_imeta_create_space_res(struct xfs_mount *mp); 94 : unsigned int xfs_imeta_link_space_res(struct xfs_mount *mp); 95 : unsigned int xfs_imeta_unlink_space_res(struct xfs_mount *mp); 96 : 97 : /* Space reservations for metadata inodes. */ 98 : struct xfs_alloc_arg; 99 : 100 : bool xfs_imeta_resv_critical(struct xfs_inode *ip); 101 : void xfs_imeta_resv_alloc_extent(struct xfs_inode *ip, 102 : struct xfs_alloc_arg *args); 103 : void xfs_imeta_resv_free_extent(struct xfs_inode *ip, struct xfs_trans *tp, 104 : xfs_filblks_t len); 105 : void xfs_imeta_resv_free_inode(struct xfs_inode *ip); 106 : int xfs_imeta_resv_init_inode(struct xfs_inode *ip, xfs_filblks_t ask); 107 : 108 : /* Must be implemented by the libxfs client */ 109 : int xfs_imeta_iget(struct xfs_mount *mp, xfs_ino_t ino, unsigned char ftype, 110 : struct xfs_inode **ipp); 111 : void xfs_imeta_irele(struct xfs_inode *ip); 112 : 113 : #endif /* __XFS_IMETA_H__ */