Skip to content

Commit

Permalink
libzfs_FQ.c: Extend AUTOSNAP handling
Browse files Browse the repository at this point in the history
  Motivation:  CATALYST zpool/BUILD/BINDER/portage-GC-REPOS and using 'a{d}'
    * daily is minimum to be picked up by OSCAR backups

  - * AUTOSNAP := { D | H | Z | m }
  + * AUTOSNAP := { D | H | M | W | Y | Z | d | m }
    *   H == no Hourly
    *   D == no Daily
  + *   W == no Weekly
  + *   M == no Monthly
  + *   Y == no Yearly
    *   Z == no ZBhold
  + *   d == daily only
  • Loading branch information
TerraTech committed Feb 16, 2021
1 parent 418dd7c commit 36bf32f
Showing 1 changed file with 79 additions and 17 deletions.
96 changes: 79 additions & 17 deletions lib/libzfs/libzfs_FQ.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ FLAG := { [ A | a{[DHZm]} ] | h{[Hdt]}| B | t<int> }
* h{ HIDE } ... == hidden options
* t<int> ...... == truncate<width>
*
* AUTOSNAP := { D | H | Z | m }
* D == no Daily
* AUTOSNAP := { D | H | M | W | Y | Z | d | m }
* H == no Hourly
* D == no Daily
* W == no Weekly
* M == no Monthly
* Y == no Yearly
* Z == no ZBhold
* d == daily only
* m == allow minutely snapshots
*
* HIDE := { H | d | t }
Expand All @@ -67,13 +71,17 @@ FLAG := { [ A | a{[DHZm]} ] | h{[Hdt]}| B | t<int> }
// a{...}
#define FQXATTR_A_NO_DAILY (1 << 3)
#define FQXATTR_A_NO_HOURLY (1 << 4)
#define FQXATTR_A_NO_ZBHOLD (1 << 5)
#define FQXATTR_A_MINUTELY (1 << 6)
#define FQXATTR_A_NO_WEEKLY (1 << 5)
#define FQXATTR_A_NO_MONTHLY (1 << 6)
#define FQXATTR_A_NO_YEARLY (1 << 7)
#define FQXATTR_A_NO_ZBHOLD (1 << 8)
#define FQXATTR_A_ONLY_DAILY (1 << 9)
#define FQXATTR_A_MINUTELY (1 << 10)

// h{...}
#define FQXATTR_H_UNHIDE (1 << 7)
#define FQXATTR_H_DATASET (1 << 8)
#define FQXATTR_H_TREE (1 << 9)
#define FQXATTR_H_UNHIDE (1 << 11)
#define FQXATTR_H_DATASET (1 << 12)
#define FQXATTR_H_TREE (1 << 13)

// gated handling
#define ALLOW B_FALSE
Expand All @@ -96,12 +104,19 @@ static boolean_t FQget_xattrs(zfs_handle_t *, FQxattrs_t *);
static boolean_t FQis_autosnap(const char *);
static boolean_t FQis_autosnap_daily(const char *);
static boolean_t FQis_autosnap_hourly(const char *);
static boolean_t FQis_autosnap_monthly(const char *);
static boolean_t FQis_autosnap_weekly(const char *);
static boolean_t FQis_autosnap_yearly(const char *);
static boolean_t FQis_autosnap_minutely(const char *);
// a{...}
static inline boolean_t FQxattrs_has_a(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_D(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_H(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_M(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_W(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_Y(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_Z(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_d(FQxattrs_t *);
static inline boolean_t FQxattrs_has_a_m(FQxattrs_t *);
// h{...}
static inline boolean_t FQxattrs_has_h(FQxattrs_t *);
Expand Down Expand Up @@ -241,31 +256,31 @@ FQexclude_autosnap(libzfs_handle_t *hdl, const char *snapshot) {
zfs_handle_t *zhp;

if (!FQis_autosnap(snapshot))
return (B_FALSE);
return (ALLOW);

(void) strlcpy(dataset, snapshot, sizeof(dataset));
amp = strchr(dataset, '@');
if (amp == NULL)
return (B_FALSE);
return (ALLOW);

*amp = '\0';

zhp = zfs_open(hdl, dataset, ZFS_TYPE_DATASET);
if (zhp == NULL)
return (B_FALSE);
return (ALLOW);

if (!FQget_xattrs(zhp, &xattrs)) {
zfs_close(zhp);
// handle 'minutely' here as well since it is an inclusion test
if (FQis_autosnap_minutely(snapshot))
return (EXCLUDE);

return (B_FALSE);
return (ALLOW);
}
zfs_close(zhp);

if (FQxattrs_has_A(&xattrs))
return (B_TRUE);
return (EXCLUDE);

//FQdebug("minutely:snapshot: %s\n", snapshot);
if (FQis_autosnap_minutely(snapshot)) {
Expand All @@ -277,15 +292,23 @@ FQexclude_autosnap(libzfs_handle_t *hdl, const char *snapshot) {
}

if (!FQxattrs_has_a(&xattrs))
return (B_FALSE);
return (ALLOW);

(void) FQxattrs_parse(&xattrs);
if (FQxattrs_has_a_H(&xattrs) && FQis_autosnap_hourly(snapshot))
return (B_TRUE);
if (FQxattrs_has_a_d(&xattrs) && !FQis_autosnap_daily(snapshot))
return (EXCLUDE);
else if (FQxattrs_has_a_H(&xattrs) && FQis_autosnap_hourly(snapshot))
return (EXCLUDE);
else if (FQxattrs_has_a_D(&xattrs) && FQis_autosnap_daily(snapshot))
return (B_TRUE);
return (EXCLUDE);
else if (FQxattrs_has_a_W(&xattrs) && FQis_autosnap_weekly(snapshot))
return (EXCLUDE);
else if (FQxattrs_has_a_M(&xattrs) && FQis_autosnap_monthly(snapshot))
return (EXCLUDE);
else if (FQxattrs_has_a_Y(&xattrs) && FQis_autosnap_yearly(snapshot))
return (EXCLUDE);

return (B_FALSE);
return (ALLOW);
}

boolean_t
Expand Down Expand Up @@ -390,7 +413,11 @@ FQxattrs_parse(FQxattrs_t *xattrs) {
switch (xxa[i]) {
case 'D': xattrs->a |= FQXATTR_A_NO_DAILY; break;;
case 'H': xattrs->a |= FQXATTR_A_NO_HOURLY; break;;
case 'M': xattrs->a |= FQXATTR_A_NO_MONTHLY; break;;
case 'W': xattrs->a |= FQXATTR_A_NO_WEEKLY; break;;
case 'Y': xattrs->a |= FQXATTR_A_NO_YEARLY; break;;
case 'Z': xattrs->a |= FQXATTR_A_NO_ZBHOLD; break;;
case 'd': xattrs->a |= FQXATTR_A_ONLY_DAILY; break;;
case 'm': xattrs->a |= FQXATTR_A_MINUTELY; break;;
}
i++;
Expand Down Expand Up @@ -441,6 +468,21 @@ FQis_autosnap_hourly(const char *snapshot) {
return (__FQis_autosnap(snapshot, "_hourly"));
}

static boolean_t
FQis_autosnap_weekly(const char *snapshot) {
return (__FQis_autosnap(snapshot, "_weekly"));
}

static boolean_t
FQis_autosnap_monthly(const char *snapshot) {
return (__FQis_autosnap(snapshot, "_monthly"));
}

static boolean_t
FQis_autosnap_yearly(const char *snapshot) {
return (__FQis_autosnap(snapshot, "_yearly"));
}

static boolean_t
FQis_autosnap_minutely(const char *snapshot) {
return (__FQis_autosnap(snapshot, "_minutely"));
Expand All @@ -464,11 +506,31 @@ FQxattrs_has_a_H(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_NO_HOURLY));
}

static inline boolean_t
FQxattrs_has_a_M(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_NO_MONTHLY));
}

static inline boolean_t
FQxattrs_has_a_W(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_NO_WEEKLY));
}

static inline boolean_t
FQxattrs_has_a_Y(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_NO_YEARLY));
}

static inline boolean_t
FQxattrs_has_a_Z(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_NO_ZBHOLD));
}

static inline boolean_t
FQxattrs_has_a_d(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_ONLY_DAILY));
}

static inline boolean_t
FQxattrs_has_a_m(FQxattrs_t *xattrs) {
return (__FQxattrs_has_a(xattrs, FQXATTR_A_MINUTELY));
Expand Down

0 comments on commit 36bf32f

Please sign in to comment.