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