Skip to content

Commit d9d8582

Browse files
committed
flux-fsck: use content.load on older versions
Problem: In older versions of flux, content.validate isn't available, thus flux-fsck cannot work against older versions of flux. Use content.load if content.validate is not available.
1 parent ed61e32 commit d9d8582

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

src/cmd/builtin/fsck.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
struct fsck_ctx {
3535
flux_t *h;
36+
bool validate_available;
3637
json_t *root;
3738
int sequence;
3839
int repair_count;
@@ -136,6 +137,8 @@ static void valref_validate_continuation (flux_future_t *f, void *arg)
136137

137138
static void valref_validate (struct fsck_valref_data *fvd)
138139
{
140+
const char *topic = fvd->ctx->validate_available ?
141+
"content-backing.validate" : "content-backing.load";
139142
uint32_t hash[BLOBREF_MAX_DIGEST_SIZE];
140143
ssize_t hash_size;
141144
const char *blobref;
@@ -147,13 +150,9 @@ static void valref_validate (struct fsck_valref_data *fvd)
147150
if ((hash_size = blobref_strtohash (blobref, hash, sizeof (hash))) < 0)
148151
log_err_exit ("cannot get hash from ref string");
149152

150-
if (!(f = flux_rpc_raw (fvd->ctx->h,
151-
"content-backing.validate",
152-
hash,
153-
hash_size,
154-
0,
155-
0))
156-
|| flux_future_then (f, -1, valref_validate_continuation, fvd) < 0)
153+
if (!(f = flux_rpc_raw (fvd->ctx->h, topic, hash, hash_size, 0, 0)))
154+
log_err_exit ("failed to validate valref blob");
155+
if (flux_future_then (f, -1, valref_validate_continuation, fvd) < 0)
157156
log_err_exit ("cannot validate valref blob");
158157
if (!(indexp = (int *)malloc (sizeof (int))))
159158
log_err_exit ("cannot allocate index memory");
@@ -636,6 +635,32 @@ static void sync_checkpoint (struct fsck_ctx *ctx)
636635
fprintf (stderr, "Updated primary checkpoint to include lost+found\n");
637636
}
638637

638+
/* "validate" support added in v0.77.0. Use "load" for backwards
639+
* compatibility if "validate" is not available.
640+
*/
641+
static void check_validate_available (struct fsck_ctx *ctx, const char *blobref)
642+
{
643+
uint32_t hash[BLOBREF_MAX_DIGEST_SIZE];
644+
ssize_t hash_size;
645+
flux_future_t *f;
646+
647+
if ((hash_size = blobref_strtohash (blobref, hash, sizeof (hash))) < 0)
648+
log_err_exit ("cannot get hash from ref string");
649+
650+
ctx->validate_available = true;
651+
// doesn't matter if the request is correct, we are looking for ENOSYS
652+
if ((f = flux_rpc_raw (ctx->h,
653+
"content-backing.validate",
654+
hash,
655+
hash_size,
656+
0,
657+
0))
658+
&& flux_rpc_get (f, NULL) < 0
659+
&& errno == ENOSYS)
660+
ctx->validate_available = false;
661+
flux_future_destroy (f);
662+
}
663+
639664
static int cmd_fsck (optparse_t *p, int ac, char *av[])
640665
{
641666
struct fsck_ctx ctx = {0};
@@ -695,6 +720,8 @@ static int cmd_fsck (optparse_t *p, int ac, char *av[])
695720
ctx.sequence = sequence;
696721
}
697722

723+
check_validate_available (&ctx, blobref);
724+
698725
fsck_blobref (&ctx, blobref);
699726

700727
flux_future_destroy (f);

0 commit comments

Comments
 (0)