Whamcloud - gitweb
LU-8769 lnet: removal of obsolete LNDs
[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, 2014, 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 <lustre/lustre_user.h>
47
48 int main(int argc, char *argv[])
49 {
50         int rc = 0;
51         int i;
52
53         for (i = 1; i < argc; i++) {
54                 char buf[1024]; /* allow xattr that may be larger */
55                 struct filter_fid *ff = (void *)buf;
56                 int size;
57
58                 size = getxattr(argv[i], "trusted.fid", buf,
59                                 sizeof(struct filter_fid_old));
60                 if (size < 0) {
61                         fprintf(stderr, "%s: error reading fid: %s\n",
62                                 argv[i], strerror(errno));
63                         if (rc == 0)
64                                 rc = size;
65                         continue;
66                 }
67                 if (size > sizeof(struct filter_fid_old)) {
68                         fprintf(stderr, "%s: warning: fid larger than expected"
69                                 " (%d bytes), recompile?\n", argv[i], size);
70                 } else if (size > sizeof(*ff)) {
71                         struct filter_fid_old *ffo = (void *)buf;
72
73                         /* old filter_fid */
74                         printf("%s: objid=%llu seq=%llu parent="DFID
75                                " stripe=%u\n", argv[i],
76                                (unsigned long long)__le64_to_cpu(ffo->ff_objid),
77                                (unsigned long long)__le64_to_cpu(ffo->ff_seq),
78                                (unsigned long long)__le64_to_cpu(ffo->ff_parent.f_seq),
79                                le32toh(ffo->ff_parent.f_oid), 0 /* ver */,
80                                /* this is stripe_nr actually */
81                                le32toh(ffo->ff_parent.f_stripe_idx));
82                 } else {
83                         printf("%s: parent="DFID" stripe=%u\n", argv[i],
84                                (unsigned long long)__le64_to_cpu(ff->ff_parent.f_seq),
85                                __le32_to_cpu(ff->ff_parent.f_oid), 0, /* ver */
86                                /* this is stripe_nr actually */
87                                __le32_to_cpu(ff->ff_parent.f_stripe_idx));
88                 }
89         }
90
91         return rc;
92 }