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