Whamcloud - gitweb
LU-11546 utils: enable large_dir for ldiskfs
[fs/lustre-release.git] / lustre / utils / ll_decode_filter_fid.c
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) 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/utils/ll_decode_filter_fid.c
33  *
34  * Tool for printing the OST filter_fid structure on the objects
35  * in human readable form.
36  *
37  * Author: Andreas Dilger <adilger@sun.com>
38  */
39
40
41 #include <stdio.h>
42 #include <errno.h>
43 #include <sys/types.h>
44 #include <sys/xattr.h>
45 #include <asm/byteorder.h>
46 #include <linux/lustre/lustre_user.h>
47
48 #define PFID_STRIPE_IDX_BITS    16
49 #define PFID_STRIPE_COUNT_MASK  ((1 << PFID_STRIPE_IDX_BITS) - 1)
50
51 #if __BYTE_ORDER == __BIG_ENDIAN
52 static void lustre_swab_lu_fid(struct lu_fid *fid)
53 {
54         __swab64s(&fid->f_seq);
55         __swab32s(&fid->f_oid);
56         __swab32s(&fid->f_ver);
57 }
58
59 static void lustre_loa_swab(struct lustre_ost_attrs *loa)
60 {
61         struct lustre_mdt_attrs *lma = &loa->loa_lma;
62
63         __swab32s(&lma->lma_compat);
64         __swab32s(&lma->lma_incompat);
65         lustre_swab_lu_fid(&lma->lma_self_fid);
66         if (lma->lma_compat & LMAC_STRIPE_INFO) {
67                 lustre_swab_lu_fid(&loa->loa_parent_fid);
68                 __swab32s(&loa->loa_stripe_size);
69         }
70         if (lma->lma_compat & LMAC_COMP_INFO) {
71                 __swab32s(&loa->loa_comp_id);
72                 __swab64s(&loa->loa_comp_start);
73                 __swab64s(&loa->loa_comp_end);
74         }
75 };
76 #else
77 static void lustre_loa_swab(struct lustre_ost_attrs *loa)
78 {
79 }
80 #endif
81
82 int main(int argc, char *argv[])
83 {
84         int rc = 0;
85         int i;
86
87         for (i = 1; i < argc; i++) {
88                 char buf[1024]; /* allow xattr that may be larger */
89                 struct filter_fid *ff = (void *)buf;
90                 static int printed;
91                 int size;
92
93                 size = getxattr(argv[i], "trusted.fid", buf,
94                                 sizeof(struct filter_fid));
95                 if (size < 0) {
96                         if (errno == ENODATA) {
97                                 struct lustre_ost_attrs *loa = (void *)buf;
98                                 int rc1;
99
100                                 rc1 = getxattr(argv[i], "trusted.lma", loa,
101                                                sizeof(*loa));
102                                 if (rc1 < sizeof(*loa)) {
103                                         fprintf(stderr,
104                                                 "%s: error reading fid: %s\n",
105                                                 argv[i], strerror(ENODATA));
106                                         if (!rc)
107                                                 rc = size;
108                                         continue;
109                                 }
110
111                                 lustre_loa_swab(loa);
112                                 if (!(loa->loa_lma.lma_compat &
113                                       LMAC_STRIPE_INFO)) {
114                                         fprintf(stderr,
115                                                 "%s: not stripe info: %s\n",
116                                                 argv[i], strerror(ENODATA));
117                                         if (!rc)
118                                                 rc = size;
119                                         continue;
120                                 }
121
122                                 printf("%s: parent="DFID" stripe=%u "
123                                        "stripe_size=%u stripe_count=%u",
124                                        argv[i],
125                                        (unsigned long long)loa->loa_parent_fid.f_seq,
126                                        loa->loa_parent_fid.f_oid, 0, /* ver */
127                                        loa->loa_parent_fid.f_stripe_idx &
128                                                         PFID_STRIPE_COUNT_MASK,
129                                        loa->loa_stripe_size,
130                                        loa->loa_parent_fid.f_stripe_idx >>
131                                                         PFID_STRIPE_IDX_BITS);
132                                 if (loa->loa_comp_id != 0)
133                                         printf(" component_id=%u "
134                                                "component_start=%llu "
135                                                "component_end=%llu",
136                                                loa->loa_comp_id,
137                                                loa->loa_comp_start,
138                                                loa->loa_comp_end);
139                                 printf("\n");
140                                 continue;
141                         }
142
143                         fprintf(stderr, "%s: error reading fid: %s\n",
144                                 argv[i], strerror(errno));
145                         if (!rc)
146                                 rc = size;
147                         continue;
148                 }
149
150                 if (size != sizeof(struct filter_fid) &&
151                     size != sizeof(struct filter_fid_18_23) &&
152                     size != sizeof(struct filter_fid_24_29) &&
153                     size != sizeof(struct filter_fid_210) && !printed) {
154                         fprintf(stderr,
155                                 "%s: warning: ffid size is unexpected (%d bytes), recompile?\n",
156                                 argv[i], size);
157                         printed = 1;
158
159                         if (size < sizeof(struct filter_fid_24_29))
160                                 continue;
161                 }
162
163                 printf("%s: ", argv[i]);
164                 if (size == sizeof(struct filter_fid_18_23)) {
165                         struct filter_fid_18_23 *ffo = (void *)buf;
166
167                         printf("objid=%llu seq=%llu ",
168                                (unsigned long long)__le64_to_cpu(ffo->ff_objid),
169                                (unsigned long long)__le64_to_cpu(ffo->ff_seq));
170                 }
171
172                 printf("parent="DFID" stripe=%u",
173                        (unsigned long long)__le64_to_cpu(ff->ff_parent.f_seq),
174                        __le32_to_cpu(ff->ff_parent.f_oid), 0, /* ver */
175                        /* this is stripe_nr actually */
176                        __le32_to_cpu(ff->ff_parent.f_stripe_idx));
177
178                 if (size >= sizeof(struct filter_fid_210)) {
179                         struct ost_layout *ol = &ff->ff_layout;
180
181                         /* new filter_fid, support PFL */
182                         printf(" stripe_size=%u stripe_count=%u",
183                                __le32_to_cpu(ol->ol_stripe_size),
184                                __le32_to_cpu(ol->ol_stripe_count));
185                         if (ol->ol_comp_id != 0)
186                                 printf(" component_id=%u "
187                                        "component_start=%llu "
188                                        "component_end=%llu",
189                                        __le32_to_cpu(ol->ol_comp_id),
190                                        __le64_to_cpu(ol->ol_comp_start),
191                                        __le64_to_cpu(ol->ol_comp_end));
192                 }
193                 if (size >= sizeof(struct filter_fid))
194                         printf(" layout_version=%u range=%u",
195                                __le32_to_cpu(ff->ff_layout_version),
196                                __le32_to_cpu(ff->ff_range));
197
198                 printf("\n");
199         }
200
201         return rc;
202 }