Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / include / lustre_linkea.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2013, 2017, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * Author: di wang <di.wang@intel.com>
28  */
29
30 /* There are several reasons to restrict the linkEA size:
31  *
32  * 1. Under DNE mode, if we do not restrict the linkEA size, and if there
33  *    are too many cross-MDTs hard links to the same object, then it will
34  *    casue the llog overflow.
35  *
36  * 2. Some backend has limited size for EA. For example, if without large
37  *    EA enabled, the ldiskfs will make all EAs to share one (4K) EA block.
38  *
39  * 3. Too many entries in linkEA will seriously affect linkEA performance
40  *    because we only support to locate linkEA entry consecutively.
41  */
42 #define MAX_LINKEA_SIZE 4096
43
44 struct linkea_data {
45         /**
46          * Buffer to keep link EA body.
47          */
48         struct lu_buf           *ld_buf;
49         /**
50          * The matched header, entry and its lenght in the EA
51          */
52         struct link_ea_header   *ld_leh;
53         struct link_ea_entry    *ld_lee;
54         int                     ld_reclen;
55 };
56
57 int linkea_data_new(struct linkea_data *ldata, struct lu_buf *buf);
58 int linkea_init(struct linkea_data *ldata);
59 int linkea_init_with_rec(struct linkea_data *ldata);
60 void linkea_entry_unpack(const struct link_ea_entry *lee, int *reclen,
61                          struct lu_name *lname, struct lu_fid *pfid);
62 int linkea_entry_pack(struct link_ea_entry *lee, const struct lu_name *lname,
63                       const struct lu_fid *pfid);
64 bool linkea_will_overflow(struct linkea_data *ldata,
65                           const struct lu_name *lname);
66 int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname,
67                    const struct lu_fid *pfid, bool err_on_overflow);
68 void linkea_del_buf(struct linkea_data *ldata, const struct lu_name *lname,
69                     bool is_encrypted);
70 int linkea_links_new(struct linkea_data *ldata, struct lu_buf *buf,
71                      const struct lu_name *cname, const struct lu_fid *pfid);
72 int linkea_overflow_shrink(struct linkea_data *ldata);
73 int linkea_links_find(struct linkea_data *ldata, const struct lu_name *lname,
74                       const struct lu_fid  *pfid);
75
76 static inline void linkea_first_entry(struct linkea_data *ldata)
77 {
78         LASSERT(ldata != NULL);
79         LASSERT(ldata->ld_leh != NULL);
80
81         if (ldata->ld_leh->leh_reccount == 0)
82                 ldata->ld_lee = NULL;
83         else
84                 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
85 }
86
87 static inline void linkea_next_entry(struct linkea_data *ldata)
88 {
89         LASSERT(ldata != NULL);
90         LASSERT(ldata->ld_leh != NULL);
91
92         if (ldata->ld_lee != NULL) {
93                 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
94                                                          ldata->ld_reclen);
95                 if ((char *)ldata->ld_lee >= ((char *)ldata->ld_leh +
96                                               ldata->ld_leh->leh_len))
97                         ldata->ld_lee = NULL;
98         }
99 }