/* * called from qmp_migrate_set_cache_size in main thread, possibly while * a migration is in progress. * A running migration maybe using the cache and might finish during this * call, hence changes to the cache are protected by XBZRLE.lock(). */ int64_t xbzrle_cache_resize(int64_t new_size) { PageCache *new_cache; int64_t ret; if (new_size < TARGET_PAGE_SIZE) { return -1; } XBZRLE_cache_lock(); if (XBZRLE.cache != NULL) { if (pow2floor(new_size) == migrate_xbzrle_cache_size()) { goto out_new_size; } new_cache = cache_init(new_size / TARGET_PAGE_SIZE, TARGET_PAGE_SIZE); if (!new_cache) { error_report("Error creating cache"); ret = -1; goto out; } cache_fini(XBZRLE.cache); XBZRLE.cache = new_cache; } out_new_size: ret = pow2floor(new_size); out: XBZRLE_cache_unlock(); return ret; }
int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); int res, nb, fd; FILE *f; /* initialise cache system */ if (!wget_init()) { fprintf(stderr, "Failed to initialize CURL library. Abort.\n"); exit(3); } if (!cache_init()) { fprintf(stderr, "Failed to initialize cache system. Abort.\n"); exit(3); } res = fuse_opt_parse(&args, &mo, rofs_opts, rofs_parse_opt); if (res != 0) { fprintf(stderr, "Invalid arguments\n"); fprintf(stderr, "see `%s -h' for usage\n", argv[0]); exit(1); } /* copy args in local */ if (mo.path == NULL) { fprintf(stderr, "Missing URL. See -h for help.\n"); exit(1); } /* if mo.metadata == NULL, keep default value */ url_path = strdup(mo.path); if (mo.metadata != NULL) url_metadata = strdup(mo.metadata); if ((url_path == NULL)||(url_metadata == NULL)) { fprintf(stderr, "Internal error while copying options. Abort.\n"); exit(1); } if ((mo.chunks > 0)&&(mo.chunks <= CACHE_MAX_CHUNK)) { cache_chunks = mo.chunks; } else { if ((mo.chunks < 0)&&(mo.chunks > CACHE_MAX_CHUNK)) { fprintf(stderr, "Invalid number of chunks '%d' (allowed: 1-%d)\n", mo.chunks, CACHE_MAX_CHUNK); exit(1); } } if (mo.chunksize >= 512) { cache_chunksize = mo.chunksize; } else { if (mo.chunksize > 0) { fprintf(stderr, "Chunk size '%d' too small (min: 512).\n", mo.chunksize); exit(1); } } /* check: if using a updater program for metadata file, this one must be set with --metafile */ if ((url_metadata[0] == '@')&&(mo.metafile == NULL)) { fprintf(stderr, "Problem: you set a updater program name, but you\n" "did not set a name for the local metafil (--metafile option), so\n" "you program has no way to know which file to update.\n" "Abort.\n"); exit(8); } /* temp file to get the metadata for filesystem */ /* does user gives a metafile name? */ tpl[0] = '\0'; if (mo.metafile != NULL) { strcat(tpl, mo.metafile); } else { strcat(tpl, "/tmp/webfsdesc.XXXXXX"); fd = mkstemp(tpl); if (fd < 0) { fprintf(stderr, "Failed to create temporaty file.\n"); exit(5); } close(fd); /* we use a FILE, not a fd */ } /* build URL of metadata */ metaurl[0] = '\0'; /* special case: if url_metadata starts by @ it is the name of the program to use to update the code */ if (url_metadata[0] == '@') { strcat(metaurl, url_metadata); } else { strcat(metaurl, wget_encode(url_path, url_metadata)); } if (!load_metadata()) { fprintf(stderr, "Failed to download metadata file.\n"); exit(5); } /* load metadata to create FS tree */ f = fopen(tpl, "r"); if (f == NULL) { fprintf(stderr, "Failed to open description file. Abort.\n"); exit(9); } nb = tree_create(f); if (nb <= 0) { /* this is an error */ fprintf(stderr, "Error while loading filesystem description. Abort.\n"); exit(1); } printf("%d entries added in FS tree.\n", nb); tree_print(); fclose(f); update_ok = UP_OK; update_nbent = nb; printf("Info: chunksize: %d, #chunks: %d\n", cache_chunksize, cache_chunks); /* only for fuse 26. else remove the final NULL */ fuse_main(args.argc, args.argv, &callback_oper, NULL); /* terminate everythings */ tree_free(); cache_fini(); wget_fini(); /* remove temp file */ if (url_metadata[0] != '@') /* do not remove in this case */ unlink((const char *)tpl); return(0); }