Clean up temp cache dir handling.
Allow temp dir setting via specific env variable to point to fast devices like ramdisk,ssd.
This commit is contained in:
parent
2c4024792a
commit
d29f125ca7
5 changed files with 37 additions and 25 deletions
41
main.c
41
main.c
|
@ -1730,6 +1730,7 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
||||||
|
|
||||||
/* A host of sanity checks. */
|
/* A host of sanity checks. */
|
||||||
if (!pipe_mode) {
|
if (!pipe_mode) {
|
||||||
|
char *tmp;
|
||||||
if ((uncompfd = open(filename, O_RDWR, 0)) == -1)
|
if ((uncompfd = open(filename, O_RDWR, 0)) == -1)
|
||||||
err_exit(1, "Cannot open: %s", filename);
|
err_exit(1, "Cannot open: %s", filename);
|
||||||
|
|
||||||
|
@ -1786,7 +1787,13 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
||||||
*/
|
*/
|
||||||
strcpy(tmpfile1, filename);
|
strcpy(tmpfile1, filename);
|
||||||
strcpy(tmpfile1, dirname(tmpfile1));
|
strcpy(tmpfile1, dirname(tmpfile1));
|
||||||
strcpy(tmpdir, tmpfile1);
|
|
||||||
|
tmp = getenv("PCOMPRESS_CACHE_DIR");
|
||||||
|
if (tmp == NULL || !chk_dir(tmp)) {
|
||||||
|
strcpy(tmpdir, tmpfile1);
|
||||||
|
} else {
|
||||||
|
strcpy(tmpdir, tmp);
|
||||||
|
}
|
||||||
strcat(tmpfile1, "/.pcompXXXXXX");
|
strcat(tmpfile1, "/.pcompXXXXXX");
|
||||||
snprintf(to_filename, sizeof (to_filename), "%s" COMP_EXTN, filename);
|
snprintf(to_filename, sizeof (to_filename), "%s" COMP_EXTN, filename);
|
||||||
if ((compfd = mkstemp(tmpfile1)) == -1) {
|
if ((compfd = mkstemp(tmpfile1)) == -1) {
|
||||||
|
@ -1798,7 +1805,6 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
||||||
signal(SIGTERM, Int_Handler);
|
signal(SIGTERM, Int_Handler);
|
||||||
} else {
|
} else {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use stdin/stdout for pipe mode.
|
* Use stdin/stdout for pipe mode.
|
||||||
|
@ -1817,29 +1823,20 @@ start_compress(const char *filename, uint64_t chunksize, int level)
|
||||||
/*
|
/*
|
||||||
* Get a workable temporary dir. Required if global dedupe is enabled.
|
* Get a workable temporary dir. Required if global dedupe is enabled.
|
||||||
*/
|
*/
|
||||||
tmp = getenv("TMPDIR");
|
tmp = getenv("PCOMPRESS_CACHE_DIR");
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL || !chk_dir(tmp)) {
|
||||||
tmp = getenv("HOME");
|
tmp = getenv("TMPDIR");
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL || !chk_dir(tmp)) {
|
||||||
if (getcwd(tmpdir, MAXPATHLEN) == NULL) {
|
tmp = getenv("HOME");
|
||||||
tmp = "/tmp";
|
if (tmp == NULL || !chk_dir(tmp)) {
|
||||||
} else {
|
if (getcwd(tmpdir, MAXPATHLEN) == NULL) {
|
||||||
tmp = tmpdir;
|
tmp = "/tmp";
|
||||||
|
} else {
|
||||||
|
tmp = tmpdir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stat(tmp, &st) == -1) {
|
|
||||||
fprintf(stderr, "Unable to find writable temporary dir.\n");
|
|
||||||
COMP_BAIL;
|
|
||||||
}
|
|
||||||
if (!S_ISDIR(st.st_mode)) {
|
|
||||||
if (strcmp(tmp, "/tmp") != 0) {
|
|
||||||
tmp = "/tmp";
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Unable to find writable temporary dir.\n");
|
|
||||||
COMP_BAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strcpy(tmpdir, tmp);
|
strcpy(tmpdir, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -382,7 +382,6 @@ set_config_s(archive_config_t *cfg, const char *algo, cksum_t ck, cksum_t ck_sim
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg->segment_sz = cfg->segment_sz_bytes / cfg->chunk_sz_bytes;
|
cfg->segment_sz = cfg->segment_sz_bytes / cfg->chunk_sz_bytes;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,8 +181,8 @@ set_cfg:
|
||||||
*memreqd = MEM_REQD(*hash_slots, *hash_entry_size);
|
*memreqd = MEM_REQD(*hash_slots, *hash_entry_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If memory required is more than twice the indicated memory limit then
|
* If memory required is more than thrice the indicated memory limit then
|
||||||
* we switch to Segmented Cumulative Similarity based dedupe.
|
* we switch to Segmented Similarity based dedupe.
|
||||||
*/
|
*/
|
||||||
if (*memreqd > (memlimit * 3) && cfg->dedupe_mode == MODE_SIMPLE &&
|
if (*memreqd > (memlimit * 3) && cfg->dedupe_mode == MODE_SIMPLE &&
|
||||||
*pct_interval == 0 && tmppath != NULL) {
|
*pct_interval == 0 && tmppath != NULL) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -406,3 +407,17 @@ get_sys_limits(my_sysinfo *msys_info)
|
||||||
msys_info->freeram = (msys_info->freeram >> 1) + (msys_info->freeram >> 2);
|
msys_info->freeram = (msys_info->freeram >> 1) + (msys_info->freeram >> 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
chk_dir(char *dir)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(dir, &st) == -1) {
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
|
@ -219,6 +219,7 @@ extern uint64_t get_total_ram();
|
||||||
extern double get_wtime_millis(void);
|
extern double get_wtime_millis(void);
|
||||||
extern double get_mb_s(uint64_t bytes, double strt, double en);
|
extern double get_mb_s(uint64_t bytes, double strt, double en);
|
||||||
extern void get_sys_limits(my_sysinfo *msys_info);
|
extern void get_sys_limits(my_sysinfo *msys_info);
|
||||||
|
extern int chk_dir(char *dir);
|
||||||
extern void init_algo_props(algo_props_t *props);
|
extern void init_algo_props(algo_props_t *props);
|
||||||
extern void init_pcompress();
|
extern void init_pcompress();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue