Skip to content

Commit

Permalink
handle lustre version file containing bare version
Browse files Browse the repository at this point in the history
Up to Lustre 2.8, the running lustre version could be found in
/proc/fs/lustre/version, formatted like this:

	lustre: 2.0.56
	kernel: patchless_client
	build:  2.0.56.0-gf83e7db-CHANGED-2.6.18-194.17.1.el5_lustre.gf83e7db

As of Lustre 2.10, the version is found in /sys/fs/lustre/version and
contains a bare version string, like this:

	2.10.8_5.chaos

This patch alters _read_lustre_version_string() so that it parses both
types of content correctly.

Add an error check in _find_mdt_dir() to correctly detect when
_read_lustre_version_string() returns an error rather than a packed
lustre version.

Fixes #31

Signed-off-by: Olaf Faaland <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
  • Loading branch information
ofaaland committed Nov 20, 2019
1 parent 91c9c9d commit f984897
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions libproc/lustre.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ _find_mdt_dir (pctx_t ctx)
{
int lustre_version = _packed_lustre_version (ctx);

if (lustre_version == -1)
msg_exit ("failed to determine lustre version");

/* Keep adding to the top of this as changes accrue */
if (lustre_version >= LUSTRE_2_0)
return PROC_FS_LUSTRE_2_0_MDT_DIR;
Expand Down Expand Up @@ -1033,19 +1036,36 @@ _read_lustre_version_string(pctx_t ctx, char **version_string)
rh = hash_create (STATS_HASH_SIZE, (hash_key_f)hash_key_string,
(hash_cmp_f)strcmp, (hash_del_f)_destroy_shash);

/*
* For Lustre <= 2.8 version file was 3-record key-value format.
* Afterwards it was just a bare version string.
*/
ret = _hash_stats (ctx, rh);

proc_close (ctx);

if (!(version = hash_find (rh, "lustre:"))) {
ret = -1;
goto done;
}
if (hash_count(rh) > 0) {
if (!(version = hash_find (rh, "lustre:"))) {
ret = -1;
goto done;
}

if (!(*version_string = strdup(version->val)))
msg_exit ("out of memeory");
if (!(*version_string = strdup(version->val)))
msg_exit ("out of memeory");
ret = 0;

} else {
char buf[64];
int rc;

rc = proc_gets (ctx, PROC_FS_LUSTRE_VERSION, buf, sizeof(buf));
if (rc < 0) {
msg_exit ("Unable to read version string");
}
if (!(*version_string = strdup(buf)))
msg_exit ("out of memory");
ret = 0;
}

ret = 0;
done:
if (rh)
hash_destroy(rh);
Expand Down

0 comments on commit f984897

Please sign in to comment.