Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0
2 : /*
3 : * Copyright (c) 2022-2023 Oracle, Inc.
4 : * All Rights Reserved.
5 : */
6 : #ifndef __XFS_PARENT_H__
7 : #define __XFS_PARENT_H__
8 :
9 : /* Metadata validators */
10 : bool xfs_parent_namecheck(struct xfs_mount *mp,
11 : const struct xfs_parent_name_rec *rec, size_t reclen,
12 : unsigned int attr_flags);
13 : bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value,
14 : size_t valuelen);
15 :
16 : extern struct kmem_cache *xfs_parent_intent_cache;
17 :
18 : /*
19 : * Dynamically allocd structure used to wrap the needed data to pass around
20 : * the defer ops machinery
21 : */
22 : struct xfs_parent_defer {
23 : struct xfs_parent_name_rec rec;
24 : struct xfs_parent_name_rec new_rec;
25 : struct xfs_da_args args;
26 : bool have_log;
27 : };
28 :
29 : int __xfs_parent_init(struct xfs_mount *mp, bool grab_log,
30 : struct xfs_parent_defer **parentp);
31 :
32 : static inline int
33 139667378 : xfs_parent_start(
34 : struct xfs_mount *mp,
35 : struct xfs_parent_defer **pp)
36 : {
37 139667378 : *pp = NULL;
38 :
39 139667378 : if (xfs_has_parent(mp))
40 139174138 : return __xfs_parent_init(mp, true, pp);
41 : return 0;
42 : }
43 :
44 : static inline int
45 99844062 : xfs_parent_start_locked(
46 : struct xfs_mount *mp,
47 : struct xfs_parent_defer **pp)
48 : {
49 99844062 : *pp = NULL;
50 :
51 99844062 : if (xfs_has_parent(mp))
52 99839250 : return __xfs_parent_init(mp, false, pp);
53 : return 0;
54 : }
55 :
56 : int xfs_parent_add(struct xfs_trans *tp, struct xfs_parent_defer *parent,
57 : struct xfs_inode *dp, const struct xfs_name *parent_name,
58 : struct xfs_inode *child);
59 : int xfs_parent_remove(struct xfs_trans *tp, struct xfs_parent_defer *parent,
60 : struct xfs_inode *dp, const struct xfs_name *parent_name,
61 : struct xfs_inode *child);
62 : int xfs_parent_replace(struct xfs_trans *tp, struct xfs_parent_defer *parent,
63 : struct xfs_inode *old_dp, const struct xfs_name *old_name,
64 : struct xfs_inode *new_dp, const struct xfs_name *new_name,
65 : struct xfs_inode *child);
66 :
67 : void __xfs_parent_cancel(struct xfs_mount *mp, struct xfs_parent_defer *parent);
68 :
69 : static inline void
70 : xfs_parent_finish(
71 : struct xfs_mount *mp,
72 : struct xfs_parent_defer *p)
73 : {
74 239516506 : if (p)
75 239019591 : __xfs_parent_cancel(mp, p);
76 : }
77 :
78 : /*
79 : * Incore version of a parent pointer, also contains dirent name so callers
80 : * can pass/obtain all the parent pointer information in a single structure
81 : */
82 : struct xfs_parent_name_irec {
83 : /* Parent pointer attribute name fields */
84 : xfs_ino_t p_ino;
85 : uint32_t p_gen;
86 : xfs_dahash_t p_namehash;
87 :
88 : /* Parent pointer attribute value fields */
89 : uint8_t p_namelen;
90 : unsigned char p_name[MAXNAMELEN];
91 : };
92 :
93 : void xfs_parent_irec_from_disk(struct xfs_parent_name_irec *irec,
94 : const struct xfs_parent_name_rec *rec, const void *value,
95 : unsigned int valuelen);
96 : void xfs_parent_irec_to_disk(struct xfs_parent_name_rec *rec,
97 : const struct xfs_parent_name_irec *irec);
98 : void xfs_parent_irec_hashname(struct xfs_mount *mp,
99 : struct xfs_parent_name_irec *irec);
100 :
101 : /* Scratchpad memory so that raw parent operations don't burn stack space. */
102 : struct xfs_parent_scratch {
103 : struct xfs_parent_name_rec rec;
104 : struct xfs_da_args args;
105 : };
106 :
107 : int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip,
108 : const struct xfs_parent_name_irec *pptr,
109 : struct xfs_parent_scratch *scratch);
110 :
111 : int xfs_parent_set(struct xfs_inode *ip, xfs_ino_t owner,
112 : const struct xfs_parent_name_irec *pptr,
113 : struct xfs_parent_scratch *scratch);
114 :
115 : int xfs_parent_unset(struct xfs_inode *ip, xfs_ino_t owner,
116 : const struct xfs_parent_name_irec *rec,
117 : struct xfs_parent_scratch *scratch);
118 :
119 : #endif /* __XFS_PARENT_H__ */
|