Skip to content

Commit

Permalink
fix(stale_snaps): cherry-pick to delete internal created snaps, enabl…
Browse files Browse the repository at this point in the history
…e travis for v1.0.x (#13)

* fix(stale_snaps): delete internal created snaps for helping in rebuil… (#227) (#10)

...d during data connection

Signed-off-by: Vitta <[email protected]>

* Enabling travis build on v1.0.x

Signed-off-by: mayank <[email protected]>

* Changing branch `develop` to `v1.0.x` for CStor REPO

Signed-off-by: mayank <[email protected]>
  • Loading branch information
mynktl authored and vishnuitta committed Jun 4, 2019
1 parent 6138f90 commit dc3a4e5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sudo: required
branches:
only:
- master
- /^\d+\.\d+(\.\d+)?(-\S*)?$/
- /^v\d+\.\d+(\.\S*)?$/
env:
global:
# Travis limits maximum log size, we have to cut tests output
Expand Down Expand Up @@ -57,7 +59,7 @@ install:
- sudo ldconfig
- cd ..
- cd cstor
- git checkout develop
- git checkout v1.0.x
- sh autogen.sh
- ./configure --with-config=user --enable-code-coverage=yes --enable-debug --enable-uzfs=yes --with-jemalloc --with-fio=$PWD/../fio --with-libcstor=$PWD/../libcstor/include
- make -j4;
Expand Down
2 changes: 0 additions & 2 deletions include/data_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ int uzfs_zvol_create_internal_snapshot(zvol_state_t *zv, zvol_state_t **snap_zv,
void signal_fds_related_to_zinfo(zvol_info_t *zinfo);
void quiesce_wait(zvol_info_t *zinfo);

int uzfs_zvol_create_internal_snapshot(zvol_state_t *zv, zvol_state_t **snap_zv,
uint64_t io_num);
int uzfs_zvol_handle_rebuild_snap_done(zvol_io_hdr_t *, int, zvol_info_t *);

#ifdef __cplusplus
Expand Down
2 changes: 2 additions & 0 deletions include/uzfs_rebuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ int uzfs_zvol_release_internal_clone(zvol_state_t *zv,
*/
int uzfs_destroy_all_internal_snapshots(zvol_state_t *zv);
boolean_t is_stale_clone(zvol_state_t *);
int uzfs_destroy_all_iosnap_snapshots(zvol_state_t *zv);
boolean_t is_stale_clone(zvol_state_t *);

#ifdef __cplusplus
}
Expand Down
19 changes: 19 additions & 0 deletions src/data_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ uzfs_zvol_rebuild_scanner(void *arg)
uint64_t payload_size = 0;
char *snap_name;
zvol_rebuild_scanner_info_t *warg = NULL;
char *at_ptr = NULL;

if ((rc = setsockopt(fd, SOL_SOCKET, SO_LINGER, &lo, sizeof (lo)))
!= 0) {
Expand Down Expand Up @@ -1698,6 +1699,11 @@ uzfs_zvol_rebuild_scanner(void *arg)
snap_zv->zv_name);
LOG_INFO("closing snap %s", snap_name);
uzfs_close_dataset(snap_zv);
at_ptr = strchr(snap_name, '@');
VERIFY3P(at_ptr, !=, NULL);
VERIFY0(strncmp(at_ptr + 1,
IO_DIFF_SNAPNAME,
sizeof (IO_DIFF_SNAPNAME) - 1));
#if DEBUG
if (inject_error.delay.
helping_replica_rebuild_complete
Expand Down Expand Up @@ -1733,6 +1739,10 @@ uzfs_zvol_rebuild_scanner(void *arg)
snap_name = kmem_asprintf("%s", snap_zv->zv_name);
LOG_INFO("closing snap on conn break %s", snap_name);
uzfs_close_dataset(snap_zv);
at_ptr = strchr(snap_name, '@');
VERIFY3P(at_ptr, !=, NULL);
VERIFY0(strncmp(at_ptr + 1, IO_DIFF_SNAPNAME,
sizeof (IO_DIFF_SNAPNAME) - 1));
#if DEBUG
if (inject_error.delay.helping_replica_rebuild_complete
== 1)
Expand Down Expand Up @@ -2189,6 +2199,9 @@ open_zvol(int fd, zvol_info_t **zinfopp)
goto error_ret;
}

/* Destroy snaps that are internally created to help during rebuild */
uzfs_destroy_all_iosnap_snapshots(zinfo->main_zv);

status = find_apt_zvol_status(zinfo, &open_data);
if (status == ZVOL_STATUS_HEALTHY) {
ASSERT3P(zinfo->snapshot_zv, ==, NULL);
Expand All @@ -2214,6 +2227,12 @@ open_zvol(int fd, zvol_info_t **zinfopp)
(void) pthread_mutex_unlock(&zinfo->zinfo_mutex);
goto open_reply;
}

/*
* Destroy snaps that are internally created to help
* during rebuild
*/
uzfs_destroy_all_iosnap_snapshots(zinfo->clone_zv);
}
/*
* TODO: Once we support multiple concurrent data connections for a
Expand Down
60 changes: 52 additions & 8 deletions src/uzfs_rebuilding.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,36 @@ uzfs_zvol_get_or_create_internal_clone(zvol_state_t *zv,
return (ret);
}

typedef boolean_t (*uzfs_snapname_matching_func)(char *snapname);

/*
* To destroy all internal created snapshot
* on a dataset
* Return true for snaps that are internal created
*/
int
uzfs_destroy_all_internal_snapshots(zvol_state_t *zv)
boolean_t
uzfs_match_internal_snapshots(char *snapname)
{
if ((strcmp(snapname, REBUILD_SNAPSHOT_SNAPNAME) == 0) ||
(strncmp(snapname, IO_DIFF_SNAPNAME,
sizeof (IO_DIFF_SNAPNAME) - 1) == 0))
return (B_TRUE);
return (B_FALSE);
}

/*
* Return true for snaps that starts with .io_snap
*/
boolean_t
uzfs_match_iosnap_snapshots(char *snapname)
{
if (strncmp(snapname, IO_DIFF_SNAPNAME,
sizeof (IO_DIFF_SNAPNAME) - 1) == 0)
return (B_TRUE);
return (B_FALSE);
}

static int
uzfs_destroy_matching_snapshots(zvol_state_t *zv,
uzfs_snapname_matching_func matching_fn)
{
int ret;
char snapname[MAXNAMELEN];
Expand All @@ -418,11 +442,9 @@ uzfs_destroy_all_internal_snapshots(zvol_state_t *zv)
break;
}

if (!(strcmp(snapname, REBUILD_SNAPSHOT_SNAPNAME) == 0) &&
!(strncmp(snapname, IO_DIFF_SNAPNAME,
sizeof (IO_DIFF_SNAPNAME) - 1) == 0)) {
/* skip destroying non-matching snaps */
if ((*matching_fn)(snapname) == B_FALSE)
continue;
}

ret = destroy_snapshot_zv(zv, snapname);
if (ret != 0) {
Expand All @@ -434,3 +456,25 @@ uzfs_destroy_all_internal_snapshots(zvol_state_t *zv)

return (ret);
}

/*
* To destroy all internal created snapshot
* on a dataset
*/
int
uzfs_destroy_all_internal_snapshots(zvol_state_t *zv)
{
int ret;
ret = uzfs_destroy_matching_snapshots(zv,
uzfs_match_internal_snapshots);
return (ret);
}

int
uzfs_destroy_all_iosnap_snapshots(zvol_state_t *zv)
{
int ret;
ret = uzfs_destroy_matching_snapshots(zv,
uzfs_match_iosnap_snapshots);
return (ret);
}

0 comments on commit dc3a4e5

Please sign in to comment.