@@ -43,6 +43,13 @@ static const char *default_small_file_threshold = "1K";
4343const char * default_archive_hashtype = "sha1" ;
4444const char * default_name = "main" ;
4545
46+ #define OLD_FILEMAP_COMMAND 1
47+
48+ #if OLD_FILEMAP_COMMAND
49+ const char * filemap_warning = "⚠️This command is deprecated.⚠️ "
50+ " Use flux-archive(1) instead." ;
51+ #endif
52+
4653/* Return true if RFC 37 fileref has blobref encoding
4754 */
4855static bool is_blobvec_encoding (json_t * fileref )
@@ -60,6 +67,7 @@ struct create_ctx {
6067 const char * name ;
6168 const char * namespace ;
6269 int verbose ;
70+ bool use_mmap ;
6371 struct blobvec_param param ;
6472 json_t * archive ;
6573 flux_kvs_txn_t * txn ;
@@ -172,7 +180,7 @@ static void add_archive_file (struct create_ctx *ctx, const char *path)
172180 if (json_array_append_new (ctx -> archive , fileref ) < 0 )
173181 log_msg_exit ("%s: out of memory" , path );
174182 if (is_blobvec_encoding (fileref )) {
175- if (optparse_hasopt ( ctx -> p , "mmap" ) )
183+ if (ctx -> use_mmap )
176184 mmap_fileref_data (ctx , path );
177185 else
178186 store_fileref_data (ctx , path , fileref , & mapinfo );
@@ -210,9 +218,24 @@ static int subcmd_create (optparse_t *p, int ac, char *av[])
210218 optparse_print_usage (p );
211219 exit (1 );
212220 }
221+ ctx .name = optparse_get_str (p , "name" , NULL );
222+ #if OLD_FILEMAP_COMMAND
223+ if (streq (av [0 ], "map" )) {
224+ fprintf (stderr , "%s\n" , filemap_warning );
225+ if (!optparse_hasopt (p , "disable-mmap" ))
226+ ctx .use_mmap = true;
227+ ctx .name = optparse_get_str (p , "tags" , ctx .name );
228+ }
229+ else if (optparse_hasopt (p , "tags" )
230+ || optparse_hasopt (p , "disable-mmap" )) {
231+ optparse_print_usage (p );
232+ exit (1 );
233+ }
234+ #endif
235+ if (!ctx .name )
236+ ctx .name = default_name ;
213237
214238 ctx .p = p ;
215- ctx .name = optparse_get_str (p , "name" , default_name );
216239 ctx .namespace = "primary" ;
217240 if (optparse_hasopt (p , "no-force-primary" ))
218241 ctx .namespace = NULL ;
@@ -234,7 +257,9 @@ static int subcmd_create (optparse_t *p, int ac, char *av[])
234257 * - the files must not change while they are mapped
235258 * - when the files are unmapped, references (blobrefs) become invalid
236259 */
237- if (optparse_hasopt (p , "mmap" )) {
260+ if (optparse_hasopt (p , "mmap" ))
261+ ctx .use_mmap = true;
262+ if (ctx .use_mmap ) {
238263 uint32_t rank ;
239264 if (flux_get_rank (ctx .h , & rank ) < 0 )
240265 log_err_exit ("error fetching broker rank" );
@@ -401,14 +426,27 @@ static void unmap_archive (flux_t *h, const char *name)
401426static int subcmd_remove (optparse_t * p , int ac , char * av [])
402427{
403428 const char * namespace = "primary" ;
404- const char * name = optparse_get_str ( p , "name" , default_name ) ;
429+ const char * name ;
405430 int n = optparse_option_index (p );
406431 flux_t * h ;
407432
408433 if (n < ac ) {
409434 optparse_print_usage (p );
410435 exit (1 );
411436 }
437+ name = optparse_get_str (p , "name" , NULL );
438+ #if OLD_FILEMAP_COMMAND
439+ if (streq (av [0 ], "unmap" )) {
440+ fprintf (stderr , "%s\n" , filemap_warning );
441+ name = optparse_get_str (p , "tags" , name );
442+ }
443+ else if (optparse_hasopt (p , "tags" )) {
444+ optparse_print_usage (p );
445+ exit (1 );
446+ }
447+ #endif
448+ if (!name )
449+ name = default_name ;
412450 if (optparse_hasopt (p , "no-force-primary" ))
413451 namespace = NULL ;
414452 if (!(h = builtin_get_flux_handle (p )))
@@ -463,7 +501,7 @@ static int subcmd_extract (optparse_t *p, int ac, char *av[])
463501{
464502 int n = optparse_option_index (p );
465503 const char * directory = optparse_get_str (p , "directory" , NULL );
466- const char * name = optparse_get_str ( p , "name" , default_name ) ;
504+ const char * name ;
467505 const char * namespace = "primary" ;
468506 const char * pattern = NULL ;
469507 int opts = 0 ;
@@ -481,6 +519,19 @@ static int subcmd_extract (optparse_t *p, int ac, char *av[])
481519 optparse_print_usage (p );
482520 exit (1 );
483521 }
522+ name = optparse_get_str (p , "name" , NULL );
523+ #if OLD_FILEMAP_COMMAND
524+ if (streq (av [0 ], "get" )) {
525+ fprintf (stderr , "%s\n" , filemap_warning );
526+ name = optparse_get_str (p , "tags" , name );
527+ }
528+ else if (optparse_hasopt (p , "tags" )) {
529+ optparse_print_usage (p );
530+ exit (1 );
531+ }
532+ #endif
533+ if (!name )
534+ name = default_name ;
484535 if (asprintf (& key , "archive.%s" , name ) < 0 )
485536 log_msg_exit ("out of memory" );
486537 if (optparse_hasopt (p , "no-force-primary" ))
@@ -548,7 +599,7 @@ static int subcmd_extract (optparse_t *p, int ac, char *av[])
548599static int subcmd_list (optparse_t * p , int ac , char * av [])
549600{
550601 int n = optparse_option_index (p );
551- const char * name = optparse_get_str ( p , "name" , default_name ) ;
602+ const char * name ;
552603 const char * namespace = "primary" ;
553604 const char * pattern = NULL ;
554605 char * key ;
@@ -564,6 +615,15 @@ static int subcmd_list (optparse_t *p, int ac, char *av[])
564615 optparse_print_usage (p );
565616 exit (1 );
566617 }
618+ name = optparse_get_str (p , "name" , NULL );
619+ #if OLD_FILEMAP_COMMAND
620+ if (optparse_hasopt (p , "tags" )) {
621+ fprintf (stderr , "%s\n" , filemap_warning );
622+ name = optparse_get_str (p , "tags" , name );
623+ }
624+ #endif
625+ if (!name )
626+ name = default_name ;
567627 if (asprintf (& key , "archive.%s" , name ) < 0 )
568628 log_msg_exit ("out of memory" );
569629 if (optparse_hasopt (p , "no-force-primary" ))
@@ -626,13 +686,19 @@ static struct optparse_option create_opts[] = {
626686 .usage = "Use mmap(2) to map file content" },
627687 { .name = "chunksize" , .has_arg = 1 , .arginfo = "N[KMG]" ,
628688 .usage = "Limit blob size to N bytes with 0=unlimited (default 1M)" ,
629- .flags = OPTPARSE_OPT_HIDDEN ,
630- },
689+ .flags = OPTPARSE_OPT_HIDDEN , },
631690 { .name = "small-file-threshold" , .has_arg = 1 , .arginfo = "N[KMG]" ,
632691 .usage = "Adjust the maximum size of a \"small file\" in bytes"
633692 " (default 1K)" ,
634- .flags = OPTPARSE_OPT_HIDDEN ,
635- },
693+ .flags = OPTPARSE_OPT_HIDDEN , },
694+ #if OLD_FILEMAP_COMMAND
695+ { .name = "tags" , .key = 'T' , .has_arg = 1 , .arginfo = "TAG" ,
696+ .usage = "alias for --name" ,
697+ .flags = OPTPARSE_OPT_HIDDEN , },
698+ { .name = "disable-mmap" , .has_arg = 0 ,
699+ .usage = "map subcommand no longer implies mmap" ,
700+ .flags = OPTPARSE_OPT_HIDDEN , },
701+ #endif
636702 OPTPARSE_TABLE_END
637703};
638704
@@ -643,6 +709,11 @@ static struct optparse_option remove_opts[] = {
643709 .usage = "Do not force archive to be in the primary KVS namespace" , },
644710 { .name = "force" , .key = 'f' , .has_arg = 0 ,
645711 .usage = "Ignore a nonexistent archive" , },
712+ #if OLD_FILEMAP_COMMAND
713+ { .name = "tags" , .key = 'T' , .has_arg = 1 , .arginfo = "TAG" ,
714+ .usage = "alias for --name" ,
715+ .flags = OPTPARSE_OPT_HIDDEN , },
716+ #endif
646717 OPTPARSE_TABLE_END
647718};
648719
@@ -661,6 +732,11 @@ static struct optparse_option extract_opts[] = {
661732 .usage = "Do not force archive to be in the primary KVS namespace" , },
662733 { .name = "list-only" , .key = 't' , .has_arg = 0 ,
663734 .usage = "List table of contents without extracting" , },
735+ #if OLD_FILEMAP_COMMAND
736+ { .name = "tags" , .key = 'T' , .has_arg = 1 , .arginfo = "TAG" ,
737+ .usage = "alias for --name" ,
738+ .flags = OPTPARSE_OPT_HIDDEN , },
739+ #endif
664740 OPTPARSE_TABLE_END
665741};
666742
@@ -673,6 +749,11 @@ static struct optparse_option list_opts[] = {
673749 .usage = "Show file type, mode, size" , },
674750 { .name = "raw" , .has_arg = 0 ,
675751 .usage = "Show raw RFC 37 file system object without decoding" , },
752+ #if OLD_FILEMAP_COMMAND
753+ { .name = "tags" , .key = 'T' , .has_arg = 1 , .arginfo = "TAG" ,
754+ .usage = "alias for --name" ,
755+ .flags = OPTPARSE_OPT_HIDDEN , },
756+ #endif
676757 OPTPARSE_TABLE_END
677758};
678759
@@ -708,6 +789,47 @@ static struct optparse_subcommand archive_subcmds[] = {
708789 OPTPARSE_SUBCMD_END
709790};
710791
792+ #if OLD_FILEMAP_COMMAND
793+ int cmd_filemap (optparse_t * p , int ac , char * av [])
794+ {
795+ if (optparse_run_subcommand (p , ac , av ) != OPTPARSE_SUCCESS )
796+ exit (1 );
797+ return 0 ;
798+ }
799+
800+ static struct optparse_subcommand filemap_subcmds [] = {
801+ { "map" ,
802+ NULL ,
803+ NULL ,
804+ subcmd_create ,
805+ OPTPARSE_SUBCMD_HIDDEN ,
806+ create_opts ,
807+ },
808+ { "unmap" ,
809+ NULL ,
810+ NULL ,
811+ subcmd_remove ,
812+ OPTPARSE_SUBCMD_HIDDEN ,
813+ remove_opts ,
814+ },
815+ { "get" ,
816+ NULL ,
817+ NULL ,
818+ subcmd_extract ,
819+ OPTPARSE_SUBCMD_HIDDEN ,
820+ extract_opts ,
821+ },
822+ { "list" ,
823+ NULL ,
824+ NULL ,
825+ subcmd_list ,
826+ OPTPARSE_SUBCMD_HIDDEN ,
827+ list_opts ,
828+ },
829+ OPTPARSE_SUBCMD_END
830+ };
831+ #endif
832+
711833int subcommand_archive_register (optparse_t * p )
712834{
713835 optparse_err_t e ;
@@ -720,11 +842,27 @@ int subcommand_archive_register (optparse_t *p)
720842 0 ,
721843 NULL );
722844 if (e != OPTPARSE_SUCCESS )
723- return (-1 );
724-
845+ return -1 ;
725846 e = optparse_reg_subcommands (optparse_get_subcommand (p , "archive" ),
726847 archive_subcmds );
727- return (e == OPTPARSE_SUCCESS ? 0 : -1 );
848+ if (e != OPTPARSE_SUCCESS )
849+ return -1 ;
850+ #if OLD_FILEMAP_COMMAND
851+ e = optparse_reg_subcommand (p ,
852+ "filemap" ,
853+ cmd_filemap ,
854+ NULL ,
855+ filemap_warning ,
856+ 0 ,
857+ NULL );
858+ if (e != OPTPARSE_SUCCESS )
859+ return -1 ;
860+ e = optparse_reg_subcommands (optparse_get_subcommand (p , "filemap" ),
861+ filemap_subcmds );
862+ if (e != OPTPARSE_SUCCESS )
863+ return -1 ;
864+ #endif
865+ return 0 ;
728866}
729867
730868/*
0 commit comments