Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / tests / lov_getstripe_old.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) 2021, DDN Storage Corporation.
24  */
25 /*
26  * lustre/tests/lov_getstripe_old.c
27  *
28  * ll_getstripe_old <file>:
29  * - to verify if the striping information of composite layout files returned
30  *   by llapi_file_get_stripe() is valid.
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <errno.h>
36 #include <sys/vfs.h>
37 #include <lustre/lustreapi.h>
38 #define LOV_MAGIC_MAGIC 0x0BD0
39 #define LOV_MAGIC_MASK  0xFFFF
40 #define LOV_MAGIC_V1            (0x0BD10000 | LOV_MAGIC_MAGIC)
41 #define LOV_MAGIC_JOIN_V1       (0x0BD20000 | LOV_MAGIC_MAGIC)
42 #define LOV_MAGIC_V3            (0x0BD30000 | LOV_MAGIC_MAGIC)
43 static inline int maxint(int a, int b)
44 {
45         return a > b ? a : b;
46 }
47
48 static void *alloc_lum()
49 {
50         int v1, v3;
51
52         v1 = sizeof(struct lov_user_md_v1) +
53              LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
54         v3 = sizeof(struct lov_user_md_v3) +
55              LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
56
57         return malloc(maxint(v1, v3));
58 }
59
60 int main(int argc, char **argv)
61 {
62         struct lov_user_md *lum_file = NULL;
63         int rc;
64
65         if (argc != 2) {
66                 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
67                 return 1;
68         }
69         lum_file = alloc_lum();
70         if (lum_file == NULL) {
71                 rc = ENOMEM;
72                 goto cleanup;
73         }
74
75         rc = llapi_file_get_stripe(argv[1], lum_file);
76         if (rc) {
77                 rc = errno;
78                 goto cleanup;
79         }
80         /* stripe_size stripe_count */
81         if (lum_file->lmm_magic == LOV_MAGIC_V1)
82                 printf("lmm_magic: v1\n");
83         else if (lum_file->lmm_magic == LOV_MAGIC_V3)
84                 printf("lmm_magic: v3\n");
85         else if (lum_file->lmm_magic == (0x0BD60000 | LOV_MAGIC_MAGIC))
86                 printf("lmm_magic: LOV_MAGIC component\n");
87
88         printf("stripe_count: %d\nstripe_size: %d\n",
89                 lum_file->lmm_stripe_count, lum_file->lmm_stripe_size);
90
91 cleanup:
92         if (lum_file != NULL)
93                 free(lum_file);
94         return rc;
95 }