Line data Source code
1 : #ifndef HEADER_fd_src_discof_backup_fd_snap_pool_h 2 : #define HEADER_fd_src_discof_backup_fd_snap_pool_h 3 : 4 : /* Snapshot inode/file descriptor management */ 5 : 6 : #include "fd_backup.h" 7 : 8 : /* fd_snap_pool_layout_t describes how the snapshot pool slots are 9 : partitioned: 10 : 11 : [0, full_max) retained full snapshots 12 : [full_max, retained_max) retained incremental snapshots 13 : [retained_max, ...) up to two scratch slots, for a 14 : snapshot class that is 15 : downloaded but not retained */ 16 : 17 : struct fd_snap_pool_layout { 18 : ulong full_max; 19 : ulong incr_max; 20 : ulong retained_max; /* full_max+incr_max */ 21 : ulong scratch_full; /* 0 or 1, slot retained_max */ 22 : ulong scratch_incr; /* 0 or 1, slot retained_max+scratch_full */ 23 : ulong max; /* total slot count */ 24 : }; 25 : 26 : typedef struct fd_snap_pool_layout fd_snap_pool_layout_t; 27 : 28 : FD_PROTOTYPES_BEGIN 29 : 30 : FD_FN_CONST static inline fd_snap_pool_layout_t 31 : fd_snap_pool_layout( ulong full_max, 32 : ulong incr_max, 33 : int incremental_enabled, 34 0 : int download_enabled ) { 35 0 : fd_snap_pool_layout_t layout = { 36 0 : .full_max = full_max, 37 0 : .incr_max = incr_max, 38 0 : .retained_max = full_max + incr_max, 39 0 : .scratch_full = (ulong)( !!download_enabled && !full_max ), 40 0 : .scratch_incr = (ulong)( !!download_enabled && !!incremental_enabled && !incr_max ) 41 0 : }; 42 0 : layout.max = layout.retained_max + layout.scratch_full + layout.scratch_incr; 43 0 : return layout; 44 0 : } 45 : 46 : /* Formats the canonical partial name for a pool slot. */ 47 : 48 : FD_FN_UNUSED static char * 49 : fd_snap_pool_partial_name( char name[ static FD_SNAP_NAME_MAX ], 50 0 : uint idx ) { 51 0 : FD_TEST( fd_cstr_printf_check( name, FD_SNAP_NAME_MAX, NULL, ".snapshot-x%u.partial", idx ) ); 52 0 : return name; 53 0 : } 54 : 55 : /* Recovers directory-entry metadata for each inherited pool 56 : descriptor. The caller must ensure directory ownership is quiescent 57 : for the duration of the scan. */ 58 : 59 : void 60 : fd_snap_pool_recover( int snapshots_fd, 61 : char const * snapshots_path, 62 : fd_backup_inode_t * pool, 63 : uint pool_max ); 64 : 65 : FD_PROTOTYPES_END 66 : 67 : #endif /* HEADER_fd_src_discof_backup_fd_snap_pool_h */