Skip to content

Commit 091146a

Browse files
committed
lustre: add initial changelog reader (WIP)
1 parent ce5dfed commit 091146a

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

contrib/lustre/changelog_reader.c

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
This file is part of GUFI, which is part of MarFS, which is released
3+
under the BSD license.
4+
5+
6+
Copyright (c) 2017, Los Alamos National Security (LANS), LLC
7+
All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without modification,
10+
are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice, this
13+
list of conditions and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions and the following disclaimer in the documentation and/or
17+
other materials provided with the distribution.
18+
19+
3. Neither the name of the copyright holder nor the names of its contributors
20+
may be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
35+
From Los Alamos National Security, LLC:
36+
LA-CC-15-039
37+
38+
Copyright (c) 2017, Los Alamos National Security, LLC All rights reserved.
39+
Copyright 2017. Los Alamos National Security, LLC. This software was produced
40+
under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
41+
Laboratory (LANL), which is operated by Los Alamos National Security, LLC for
42+
the U.S. Department of Energy. The U.S. Government has rights to use,
43+
reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
44+
ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
45+
ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is
46+
modified to produce derivative works, such modified software should be
47+
clearly marked, so as not to confuse it with the version available from
48+
LANL.
49+
50+
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
51+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
52+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53+
ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
54+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
59+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
60+
OF SUCH DAMAGE.
61+
*/
62+
63+
/*
64+
* To build:
65+
*
66+
* export LUSTRE_LIBRARY_DIR=/home/$USER/git/lustre-release/lustre/utils/.libs
67+
* export LUSTRE_INCLUDE_DIR=/home/$USER/git/lustre-release/lustre/include/
68+
* gcc -D_GNU_SOURCE -I$LUSTRE_INCLUDE_DIR -I$LUSTRE_INCLUDE_DIR/uapi/ -L$LUSTRE_LIBRARY_DIR -llustreapi changelog_reader.c
69+
*
70+
* To run:
71+
*
72+
* export LD_LIBRARY_PATH=$LUSTRE_LIBRARY_DIR
73+
* ./a.out
74+
*
75+
*/
76+
77+
#include <assert.h>
78+
#include <errno.h>
79+
#include <fcntl.h>
80+
#include <poll.h>
81+
#include <stdio.h>
82+
#include <stdlib.h>
83+
#include <string.h>
84+
#include <sys/types.h>
85+
#include <sys/stat.h>
86+
#include <unistd.h>
87+
88+
#include "lustre/lustreapi.h"
89+
90+
/** returns fid object sequence */
91+
static inline __u64 fid_seq(const struct lu_fid *fid)
92+
{
93+
return fid->f_seq;
94+
}
95+
96+
/** returns fid object id */
97+
static inline __u32 fid_oid(const struct lu_fid *fid)
98+
{
99+
return fid->f_oid;
100+
}
101+
102+
/**
103+
* Flatten 128-bit FID values into a 64-bit value for use as an inode number.
104+
*
105+
* This is taken from lustre/include/uapi/linux/lustre/lustre_fid.h, with
106+
* irrelevant parts (i.e., IGIF FIDs) removed.
107+
*
108+
* It would be better to directly include that header, but it's not part of the
109+
* public Lustre API, and is also not designed for inclusion in userspace programs
110+
* (e.g., it includes kernel headers which cannot be transitively included in
111+
* userspace programs).
112+
*
113+
* So for lack of a better option, I copy the definition.
114+
*/
115+
static inline __u64 fid_flatten64(const struct lu_fid *fid)
116+
{
117+
__u64 ino;
118+
__u64 seq;
119+
120+
seq = fid_seq(fid);
121+
122+
ino = (seq << 24) + ((seq >> 24) & 0xffffff0000ULL) + fid_oid(fid);
123+
124+
return ino ?: fid_oid(fid);
125+
}
126+
127+
int main(int argc, char *argv[])
128+
{
129+
void *changelog_priv;
130+
long long startrec = 0;
131+
struct changelog_rec *rec;
132+
int rc;
133+
134+
char *mdd = "lustre-MDT0000"; // TODO: make this a CLI arg?
135+
136+
rc = llapi_changelog_start(&changelog_priv,
137+
CHANGELOG_FLAG_BLOCK |
138+
CHANGELOG_FLAG_JOBID |
139+
CHANGELOG_FLAG_NID_BE |
140+
CHANGELOG_FLAG_EXTRA_FLAGS,
141+
mdd, startrec);
142+
if (rc < 0) {
143+
fprintf(stderr, "error starting changelog: %s\n", strerror(-rc));
144+
return EXIT_FAILURE;
145+
}
146+
147+
while ((rc = llapi_changelog_recv(changelog_priv, &rec)) == 0) {
148+
/*
149+
printf("record: %s, fid: "DFID", parent: "DFID,
150+
changelog_type2str(rec->cr_type),
151+
PFID(&rec->cr_tfid),
152+
PFID(&rec->cr_pfid));
153+
printf(" inode: ");
154+
*/
155+
156+
printf("%llu\n", fid_flatten64(&rec->cr_pfid));
157+
}
158+
159+
llapi_changelog_fini(&changelog_priv);
160+
161+
return rc == 1 ? EXIT_SUCCESS : EXIT_FAILURE;
162+
}

0 commit comments

Comments
 (0)