2011-03-04 20:59:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Andrea Mazzoleni
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __STATE_H
|
|
|
|
|
#define __STATE_H
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
|
/* state */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Global variable to identify if Ctrl+C is pressed.
|
|
|
|
|
*/
|
|
|
|
|
extern volatile int global_interrupt;
|
|
|
|
|
|
2013-06-25 22:41:10 +02:00
|
|
|
#define SORT_PHYSICAL 1 /**< Sort by physical order. */
|
|
|
|
|
#define SORT_INODE 2 /**< Sort by inode. */
|
|
|
|
|
#define SORT_ALPHA 3 /**< Sort by alphabetic order. */
|
|
|
|
|
#define SORT_DIR 4 /**< Sort by directory order. */
|
|
|
|
|
|
2013-06-29 18:11:36 +02:00
|
|
|
/**
|
|
|
|
|
* Options set only at startup.
|
|
|
|
|
* For all these options a value of 0 means nothing set, and to use the default.
|
|
|
|
|
*/
|
|
|
|
|
struct snapraid_option {
|
2011-03-04 20:59:21 +01:00
|
|
|
int verbose; /**< Verbose output. */
|
2011-06-20 20:35:04 +02:00
|
|
|
int gui; /**< Gui output. */
|
2013-03-03 22:39:46 +01:00
|
|
|
int force_zero; /**< Forced dangerous operations of synching files now with zero size. */
|
|
|
|
|
int force_empty; /**< Forced dangerous operations of synching disks now empty. */
|
|
|
|
|
int force_uuid; /**< Forced dangerous operations of synching disks with uuid changed. */
|
2013-07-26 14:50:52 +02:00
|
|
|
int force_device; /**< Forced dangerous operations of using disks with save device id. */
|
2011-04-23 21:38:26 +02:00
|
|
|
int expect_unrecoverable; /**< Expect presence of unrecoverable error in checking or fixing. */
|
|
|
|
|
int expect_recoverable; /**< Expect presence of recoverable error in checking. */
|
2013-06-29 18:11:36 +02:00
|
|
|
int skip_device; /**< Skip devices matching checks. */
|
2013-02-28 23:06:42 +01:00
|
|
|
int skip_sign; /**< Skip the sign check for content files. */
|
|
|
|
|
int skip_fallocate; /**< Skip the use of fallocate(). */
|
2013-04-04 22:52:56 +02:00
|
|
|
int skip_sequential; /**< Skip sequential hint. */
|
2013-06-29 18:11:36 +02:00
|
|
|
int skip_lock; /**< Skip the lock file protection. */
|
|
|
|
|
int skip_self; /**< Skip the self-test. */
|
|
|
|
|
int kill_after_sync; /**< Kill the process after sync without saving the final state. */
|
2013-06-15 23:42:11 +02:00
|
|
|
int force_murmur3; /**< Force Murmur3 choice. */
|
|
|
|
|
int force_spooky2; /**< Force Spooky2 choice. */
|
2013-06-29 18:11:36 +02:00
|
|
|
int force_order; /**< Force sorting order. One of the SORT_* defines. */
|
|
|
|
|
unsigned force_scrub; /**< Force scrub for the specified number of blocks. */
|
2013-07-01 23:08:25 +02:00
|
|
|
int force_scrub_even; /**< Force scrub of all the even blocks. */
|
2013-08-09 13:55:02 +02:00
|
|
|
int force_content_write; /**< Force the update of the content file. */
|
2013-08-17 16:17:53 +02:00
|
|
|
int force_content_text; /**< Force the use of text version of content file. */
|
2013-06-29 18:11:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct snapraid_state {
|
|
|
|
|
struct snapraid_option opt; /**< Setup options. */
|
|
|
|
|
int filter_hidden; /**< Filter out hidden files. */
|
|
|
|
|
uint64_t autosave; /**< Autosave after the specified amount of data. 0 to disable. */
|
2011-03-19 22:00:08 +01:00
|
|
|
int need_write; /**< If the state is changed. */
|
2011-03-16 23:52:10 +01:00
|
|
|
uint32_t block_size; /**< Block size in bytes. */
|
2011-03-04 20:59:21 +01:00
|
|
|
char parity[PATH_MAX]; /**< Path of the parity file. */
|
2011-09-20 22:35:15 +02:00
|
|
|
uint64_t parity_device; /**< Device identifier of the parity. */
|
2011-04-23 21:38:26 +02:00
|
|
|
char qarity[PATH_MAX]; /**< Path of the qarity file. */
|
2011-09-20 22:35:15 +02:00
|
|
|
uint64_t qarity_device; /**< Device identifier of the qarity. */
|
2013-02-22 22:17:54 +01:00
|
|
|
char pool[PATH_MAX]; /**< Path of the pool tree. */
|
|
|
|
|
uint64_t pool_device; /**< Device identifier of the pool. */
|
2013-06-23 21:27:38 +02:00
|
|
|
unsigned char hashseed[HASH_SIZE]; /**< Hash seed. Just after a uint64 to provide a minimal alignment. */
|
2013-07-01 23:08:25 +02:00
|
|
|
unsigned char prevhashseed[HASH_SIZE]; /**< Previous hash seed. In case of rehash. */
|
2013-06-18 21:06:31 +02:00
|
|
|
char lockfile[PATH_MAX]; /**< Path of the lock file to use. */
|
2011-04-23 21:38:26 +02:00
|
|
|
unsigned level; /**< Number of parity levels. 1 for RAID5, 2 for RAID6. */
|
|
|
|
|
unsigned hash; /**< Hash kind used. */
|
2013-07-01 23:08:25 +02:00
|
|
|
unsigned prevhash; /**< Previous hash kind used. In case of rehash. */
|
2013-06-15 23:42:11 +02:00
|
|
|
unsigned besthash; /**< Best hash suggested. */
|
2013-03-03 22:39:46 +01:00
|
|
|
const char* command; /**< Command running. */
|
2011-04-25 13:43:51 +02:00
|
|
|
tommy_list contentlist; /**< List of content files. */
|
2011-09-23 21:48:50 +02:00
|
|
|
tommy_list disklist; /**< List of all the disks. */
|
2011-10-01 19:18:32 +02:00
|
|
|
tommy_list maplist; /**< List of all the disk mappings. */
|
2011-04-26 18:51:42 +02:00
|
|
|
tommy_list filterlist; /**< List of inclusion/exclusion. */
|
2013-02-27 21:07:16 +01:00
|
|
|
tommy_list importlist; /**< List of import file. */
|
|
|
|
|
tommy_hashdyn importset; /**< Hashtable by hash of all the import blocks. */
|
2013-07-01 23:08:25 +02:00
|
|
|
tommy_hashdyn previmportset; /**< Hashtable by prevhash of all the import blocks. Valid only if we are in a rehash state. */
|
2013-06-23 21:49:36 +02:00
|
|
|
tommy_arrayof infoarr; /**< Block information array. */
|
2012-10-09 23:02:46 +02:00
|
|
|
block_off_t loaded_blockmax; /**< Previous size of the parity file, computed from the loaded state. */
|
2011-06-20 20:35:04 +02:00
|
|
|
time_t progress_start; /**< Start of processing for progress visualization. */
|
|
|
|
|
time_t progress_last; /**< Last update of progress visualization. */
|
2012-03-13 23:59:59 +01:00
|
|
|
time_t progress_interruption; /**< Start of the measure interruption. */
|
|
|
|
|
time_t progress_subtract; /**< Time to subtract for the interruptions. */
|
2013-09-21 15:53:46 +02:00
|
|
|
int no_conf; /**< Automatically add missing info. Used to load content without a configuration file. */
|
2011-03-04 20:59:21 +01:00
|
|
|
};
|
|
|
|
|
|
2011-03-12 23:36:37 +01:00
|
|
|
/**
|
|
|
|
|
* Initializes the state.
|
|
|
|
|
*/
|
2011-03-04 20:59:21 +01:00
|
|
|
void state_init(struct snapraid_state* state);
|
|
|
|
|
|
2011-03-12 23:36:37 +01:00
|
|
|
/**
|
|
|
|
|
* Deinitializes the state.
|
|
|
|
|
*/
|
2011-03-04 20:59:21 +01:00
|
|
|
void state_done(struct snapraid_state* state);
|
|
|
|
|
|
2011-03-12 23:36:37 +01:00
|
|
|
/**
|
2011-12-14 21:08:17 +01:00
|
|
|
* Reads the configuration file.
|
2011-03-12 23:36:37 +01:00
|
|
|
*/
|
2013-06-29 18:11:36 +02:00
|
|
|
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-12-14 21:08:17 +01:00
|
|
|
* Reads the state.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
|
|
|
|
void state_read(struct snapraid_state* state);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 23:36:37 +01:00
|
|
|
* Writes the new state.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
|
|
|
|
void state_write(struct snapraid_state* state);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 23:36:37 +01:00
|
|
|
* Scans all the disks to update the state.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
2011-06-20 20:35:04 +02:00
|
|
|
void state_scan(struct snapraid_state* state, int output);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-03-12 23:36:37 +01:00
|
|
|
* Syncs the parity data.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
2011-03-23 18:54:08 +01:00
|
|
|
int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
|
|
|
|
/**
|
2012-10-07 23:18:10 +02:00
|
|
|
* Checks (and fixes) all the files and parity data.
|
|
|
|
|
* \param check If we have to check also the parity.
|
2013-03-02 23:17:55 +01:00
|
|
|
* \param fix If we have to fix, after checking. It requires also check==1.
|
2011-03-04 20:59:21 +01:00
|
|
|
*/
|
2013-06-29 17:53:40 +02:00
|
|
|
int state_check(struct snapraid_state* state, int check, int fix, block_off_t blockstart, block_off_t blockcount);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
2011-04-08 22:32:40 +02:00
|
|
|
/**
|
2011-12-08 20:37:27 +01:00
|
|
|
* Dry the files.
|
2011-04-08 22:32:40 +02:00
|
|
|
*/
|
|
|
|
|
void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t blockcount);
|
|
|
|
|
|
2013-06-15 23:42:11 +02:00
|
|
|
/**
|
|
|
|
|
* Rehash the files.
|
|
|
|
|
*/
|
|
|
|
|
void state_rehash(struct snapraid_state* state);
|
|
|
|
|
|
2013-06-29 17:53:40 +02:00
|
|
|
/**
|
|
|
|
|
* Scrub the files.
|
|
|
|
|
*/
|
2013-08-22 23:03:13 +02:00
|
|
|
int state_scrub(struct snapraid_state* state, int percentage, int olderthan);
|
2013-06-29 17:53:40 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print the status.
|
|
|
|
|
*/
|
|
|
|
|
int state_status(struct snapraid_state* state);
|
|
|
|
|
|
2011-12-08 20:37:27 +01:00
|
|
|
/**
|
2013-02-22 22:17:54 +01:00
|
|
|
* Finds duplicates.
|
2011-12-08 20:37:27 +01:00
|
|
|
*/
|
|
|
|
|
void state_dup(struct snapraid_state* state);
|
|
|
|
|
|
2013-02-22 22:17:54 +01:00
|
|
|
/**
|
|
|
|
|
* Creates pool tree.
|
|
|
|
|
*/
|
|
|
|
|
void state_pool(struct snapraid_state* state);
|
|
|
|
|
|
2011-03-30 00:14:43 +02:00
|
|
|
/**
|
2013-01-27 16:44:04 +01:00
|
|
|
* Filter files, symlinks and dirs.
|
|
|
|
|
* Apply an additional filter to the list currently loaded.
|
2011-03-30 00:14:43 +02:00
|
|
|
*/
|
2013-08-18 19:24:55 +02:00
|
|
|
void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tommy_list* filterlist_disk, int filter_missing, int filter_error);
|
2011-03-30 00:14:43 +02:00
|
|
|
|
2011-06-20 20:35:04 +02:00
|
|
|
/**
|
|
|
|
|
* Begins the progress visualization.
|
|
|
|
|
*/
|
2013-07-10 19:37:58 +02:00
|
|
|
int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, block_off_t countmax);
|
2011-06-20 20:35:04 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ends the progress visualization.
|
|
|
|
|
*/
|
|
|
|
|
void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize);
|
|
|
|
|
|
2011-03-12 23:36:37 +01:00
|
|
|
/**
|
|
|
|
|
* Writes the progress.
|
|
|
|
|
*/
|
2011-06-20 20:35:04 +02:00
|
|
|
int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize);
|
2011-03-04 20:59:21 +01:00
|
|
|
|
2012-03-13 23:59:59 +01:00
|
|
|
/**
|
|
|
|
|
* Stop temporarely the progress.
|
|
|
|
|
*/
|
|
|
|
|
void state_progress_stop(struct snapraid_state* state);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Restart the progress.
|
|
|
|
|
*/
|
|
|
|
|
void state_progress_restart(struct snapraid_state* state);
|
|
|
|
|
|
2013-09-21 15:53:46 +02:00
|
|
|
/****************************************************************************/
|
|
|
|
|
/* misc */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a dummy configuration file from a content file.
|
|
|
|
|
*/
|
|
|
|
|
void generate_configuration(const char* content);
|
|
|
|
|
|
2011-03-04 20:59:21 +01:00
|
|
|
#endif
|
2011-03-06 22:52:50 +01:00
|
|
|
|