GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / lustre / 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, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2013, 2014, Intel Corporation.
24  * Use is subject to license terms.
25  *
26  * Author: di wang <di.wang@intel.com>
27  */
28
29 /* There are several reasons to restrict the linkEA size:
30  *
31  * 1. Under DNE mode, if we do not restrict the linkEA size, and if there
32  *    are too many cross-MDTs hard links to the same object, then it will
33  *    casue the llog overflow.
34  *
35  * 2. Some backend has limited size for EA. For example, if without large
36  *    EA enabled, the ldiskfs will make all EAs to share one (4K) EA block.
37  *
38  * 3. Too many entries in linkEA will seriously affect linkEA performance
39  *    because we only support to locate linkEA entry consecutively.
40  */
41 #define MAX_LINKEA_SIZE         4096
42
43 struct linkea_data {
44         /**
45          * Buffer to keep link EA body.
46          */
47         struct lu_buf           *ld_buf;
48         /**
49          * The matched header, entry and its length in the EA
50          */
51         struct link_ea_header   *ld_leh;
52         struct link_ea_entry    *ld_lee;
53         int                     ld_reclen;
54 };
55
56 int linkea_data_new(struct linkea_data *ldata, struct lu_buf *buf);
57 int linkea_init(struct linkea_data *ldata);
58 int linkea_init_with_rec(struct linkea_data *ldata);
59 void linkea_entry_unpack(const struct link_ea_entry *lee, int *reclen,
60                          struct lu_name *lname, struct lu_fid *pfid);
61 int linkea_entry_pack(struct link_ea_entry *lee, const struct lu_name *lname,
62                       const struct lu_fid *pfid);
63 int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname,
64                    const struct lu_fid *pfid);
65 void linkea_del_buf(struct linkea_data *ldata, const struct lu_name *lname);
66 int linkea_links_find(struct linkea_data *ldata, const struct lu_name *lname,
67                       const struct lu_fid  *pfid);
68
69 static inline void linkea_first_entry(struct linkea_data *ldata)
70 {
71         LASSERT(ldata);
72         LASSERT(ldata->ld_leh);
73
74         if (ldata->ld_leh->leh_reccount == 0)
75                 ldata->ld_lee = NULL;
76         else
77                 ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
78 }
79
80 static inline void linkea_next_entry(struct linkea_data *ldata)
81 {
82         LASSERT(ldata);
83         LASSERT(ldata->ld_leh);
84
85         if (ldata->ld_lee) {
86                 ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
87                                                          ldata->ld_reclen);
88                 if ((char *)ldata->ld_lee >= ((char *)ldata->ld_leh +
89                                               ldata->ld_leh->leh_len))
90                         ldata->ld_lee = NULL;
91         }
92 }