2828#include "ccan/str/str.h"
2929
3030#include "builtin.h"
31+ #include "src/cmd/util/util.h"
3132
3233#define BLOBREF_ASYNC_MAX 1000
3334
@@ -50,10 +51,6 @@ struct fsck_ctx {
5051struct fsck_valref_data
5152{
5253 struct fsck_ctx * ctx ;
53- json_t * treeobj ;
54- int index ;
55- int count ;
56- int in_flight ;
5754 const char * path ;
5855 int errorcount ;
5956 int errnum ;
@@ -64,8 +61,6 @@ static void fsck_treeobj (struct fsck_ctx *ctx,
6461 const char * path ,
6562 json_t * treeobj );
6663
67- static void valref_validate (struct fsck_valref_data * fvd );
68-
6964static void vmsg (struct fsck_ctx * ctx , const char * fmt , va_list ap )
7065{
7166 char buf [128 ];
@@ -116,65 +111,28 @@ static void save_missing_ref_index (struct fsck_valref_data *fvd, int index)
116111 zlist_freefn (fvd -> missing_indexes , cpy , (zlist_free_fn * ) free , true);
117112}
118113
119- static void valref_validate_continuation ( flux_future_t * f , void * arg )
114+ static int err_blobref_cb ( int errnum , int index , void * arg )
120115{
121116 struct fsck_valref_data * fvd = arg ;
122117
123- if (flux_rpc_get (f , NULL ) < 0 ) {
124- int * index = flux_future_aux_get (f , "index" );
125- if (fvd -> ctx -> verbose ) {
126- if (errno == ENOENT )
127- errmsg (fvd -> ctx ,
128- "%s: missing blobref index=%d" ,
129- fvd -> path ,
130- (* index ));
131- else
132- errmsg (fvd -> ctx ,
133- "%s: error retrieving blobref index=%d: %s" ,
134- fvd -> path ,
135- (* index ),
136- future_strerror (f , errno ));
137- }
138- fvd -> errorcount ++ ;
139- fvd -> errnum = errno ; /* we'll report the last errno */
140- if (fvd -> ctx -> repair && errno == ENOENT )
141- save_missing_ref_index (fvd , * index );
142- }
143- fvd -> in_flight -- ;
144-
145- if (fvd -> index < fvd -> count ) {
146- valref_validate (fvd );
147- fvd -> in_flight ++ ;
148- fvd -> index ++ ;
118+ if (fvd -> ctx -> verbose ) {
119+ if (errnum == ENOENT )
120+ errmsg (fvd -> ctx ,
121+ "%s: missing blobref index=%d" ,
122+ fvd -> path ,
123+ index );
124+ else
125+ errmsg (fvd -> ctx ,
126+ "%s: error retrieving blobref index=%d: %s" ,
127+ fvd -> path ,
128+ index ,
129+ strerror (errnum ));
149130 }
150-
151- flux_future_destroy (f );
152- }
153-
154- static void valref_validate (struct fsck_valref_data * fvd )
155- {
156- const char * topic = fvd -> ctx -> validate_available ?
157- "content-backing.validate" : "content-backing.load" ;
158- uint32_t hash [BLOBREF_MAX_DIGEST_SIZE ];
159- ssize_t hash_size ;
160- const char * blobref ;
161- flux_future_t * f ;
162- int * indexp ;
163-
164- blobref = treeobj_get_blobref (fvd -> treeobj , fvd -> index );
165-
166- if ((hash_size = blobref_strtohash (blobref , hash , sizeof (hash ))) < 0 )
167- log_err_exit ("cannot get hash from ref string" );
168-
169- if (!(f = flux_rpc_raw (fvd -> ctx -> h , topic , hash , hash_size , 0 , 0 )))
170- log_err_exit ("failed to validate valref blob" );
171- if (flux_future_then (f , -1 , valref_validate_continuation , fvd ) < 0 )
172- log_err_exit ("cannot validate valref blob" );
173- if (!(indexp = (int * )malloc (sizeof (int ))))
174- log_err_exit ("cannot allocate index memory" );
175- (* indexp ) = fvd -> index ;
176- if (flux_future_aux_set (f , "index" , indexp , free ) < 0 )
177- log_err_exit ("could not save index value" );
131+ fvd -> errorcount ++ ;
132+ fvd -> errnum = errnum ; /* we'll report the last errno */
133+ if (fvd -> ctx -> repair && errnum == ENOENT )
134+ save_missing_ref_index (fvd , index );
135+ return 0 ; /* 0, continue to scan remaining blobrefs */
178136}
179137
180138static json_t * repair_valref (struct fsck_ctx * ctx ,
@@ -336,22 +294,20 @@ static void fsck_valref (struct fsck_ctx *ctx,
336294 const char * path ,
337295 json_t * treeobj )
338296{
297+ const char * topic = ctx -> validate_available ?
298+ "content-backing.validate" : "content-backing.load" ;
339299 struct fsck_valref_data fvd = {0 };
340300
341301 fvd .ctx = ctx ;
342- fvd .treeobj = treeobj ;
343- fvd .count = treeobj_get_count (treeobj );
344302 fvd .path = path ;
345303
346- while (fvd .in_flight < BLOBREF_ASYNC_MAX
347- && fvd .index < fvd .count ) {
348- valref_validate (& fvd );
349- fvd .in_flight ++ ;
350- fvd .index ++ ;
351- }
352-
353- if (flux_reactor_run (flux_get_reactor (ctx -> h ), 0 ) < 0 )
354- log_err_exit ("flux_reactor_run" );
304+ if (valref_blobrefs (ctx -> h ,
305+ topic ,
306+ treeobj ,
307+ NULL ,
308+ err_blobref_cb ,
309+ & fvd ) < 0 )
310+ log_err_exit ("unable to scan valref %s" , path );
355311
356312 if (fvd .errorcount ) {
357313 /* each invalid blobref will be output in verbose mode */
0 commit comments