From 3c00248aa6a385b7f173cf9b871c467d48ef527d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 30 Dec 2015 14:22:43 +0100 Subject: [PATCH] Add level knownledge to parity handle --- cmdline/check.c | 4 ++-- cmdline/dry.c | 2 +- cmdline/parity.c | 6 ++++-- cmdline/parity.h | 5 +++-- cmdline/scrub.c | 2 +- cmdline/sync.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index 55a35eb5..89c0fbe1 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1942,7 +1942,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b } parity_ptr[l] = &parity[l]; - ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); + ret = parity_create(parity_ptr[l], l, state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ log_fatal("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l)); @@ -1963,7 +1963,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b /* it may fail if the file doesn't exist, in this case we continue to check the files */ for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; - ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode); + ret = parity_open(parity_ptr[l], l, state->parity[l].path, state->file_mode); if (ret == -1) { msg_status("No accessible %s file, only files will be checked.\n", lev_name(l)); /* continue anyway */ diff --git a/cmdline/dry.c b/cmdline/dry.c index c9a460d2..812e9af0 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -219,7 +219,7 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t /* it may fail if the file doesn't exist, in this case we continue to dry the files */ for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; - ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode); + ret = parity_open(parity_ptr[l], l, state->parity[l].path, state->file_mode); if (ret == -1) { msg_status("No accessible %s file.\n", lev_name(l)); /* continue anyway */ diff --git a/cmdline/parity.c b/cmdline/parity.c index f62a3f41..400f0601 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -149,11 +149,12 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) } } -int parity_create(struct snapraid_parity_handle* parity, const char* path, data_off_t* out_size, int mode) +int parity_create(struct snapraid_parity_handle* parity, unsigned level, const char* path, data_off_t* out_size, int mode) { int ret; int flags; + parity->level = level; pathcpy(parity->path, sizeof(parity->path), path); /* opening in sequential mode in Windows */ @@ -323,11 +324,12 @@ bail: /* LCOV_EXCL_STOP */ } -int parity_open(struct snapraid_parity_handle* parity, const char* path, int mode) +int parity_open(struct snapraid_parity_handle* parity, unsigned level, const char* path, int mode) { int ret; int flags; + parity->level = level; pathcpy(parity->path, sizeof(parity->path), path); /* open for read */ diff --git a/cmdline/parity.h b/cmdline/parity.h index 066ff3d7..f63376bb 100644 --- a/cmdline/parity.h +++ b/cmdline/parity.h @@ -25,6 +25,7 @@ struct snapraid_parity_handle { char path[PATH_MAX]; /**< Path of the file. */ + unsigned level; /**< Level of the parity. */ int f; /**< Handle of the file. */ struct stat st; /**< Stat info of the opened file. */ data_off_t valid_size; /**< Size of the valid data. */ @@ -74,7 +75,7 @@ void parity_overflow(struct snapraid_state* state, data_off_t size); * Create the parity file. * \param out_size Return the size of the parity file. */ -int parity_create(struct snapraid_parity_handle* parity, const char* path, data_off_t* out_size, int mode); +int parity_create(struct snapraid_parity_handle* parity, unsigned level, const char* path, data_off_t* out_size, int mode); /** * Change the parity size. @@ -85,7 +86,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o /** * Open an already existing parity file. */ -int parity_open(struct snapraid_parity_handle* parity, const char* path, int mode); +int parity_open(struct snapraid_parity_handle* parity, unsigned level, const char* path, int mode); /** * Flush the parity file in the disk. diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 735d8459..fe10cdd2 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -723,7 +723,7 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan) /* open the file for reading */ for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; - ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode); + ret = parity_open(parity_ptr[l], l, state->parity[l].path, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ log_fatal("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); diff --git a/cmdline/sync.c b/cmdline/sync.c index e0a2aafe..d6712732 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -1258,7 +1258,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* create the file and open for writing */ parity_ptr[l] = &parity[l]; - ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); + ret = parity_create(parity_ptr[l], l, state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));