Skip to content

Commit

Permalink
fix(stale_snaps): cherry-pick to delete stale snaps and installs debu…
Browse files Browse the repository at this point in the history
…g tools (#229)

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

...d during data connection

Signed-off-by: Vitta <vitta@mayadata.io>

* [2502] feat(debug-tools): installing curl/tcpdump/nslookup/ping packages

Signed-off-by: Vitta <vitta@mayadata.io>
  • Loading branch information
vishnuitta authored May 17, 2019
1 parent ff7e226 commit d69dbc9
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ FROM openebs/cstor-ubuntu:xenial-20181005
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
apt-get update && apt-get install -y \
curl tcpdump dnsutils iputils-ping \
libaio1 libaio-dev \
libkqueue-dev libssl1.0.0 rsyslog net-tools gdb apt-utils \
sed libjemalloc-dev openssh-server
RUN apt-get -y install apt-file && apt-file update

COPY zfs/bin/* /usr/local/bin/
COPY zfs/lib/* /usr/lib/
Expand Down
2 changes: 0 additions & 2 deletions include/data_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,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 @@ -66,6 +66,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
60 changes: 52 additions & 8 deletions lib/libzpool/uzfs_rebuilding.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,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 @@ -423,11 +447,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 @@ -439,3 +461,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);
}
19 changes: 19 additions & 0 deletions lib/libzrepl/data_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,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 @@ -1706,6 +1707,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 @@ -1741,6 +1747,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 @@ -2197,6 +2207,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 @@ -2222,6 +2235,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
52 changes: 52 additions & 0 deletions tests/cbtest/gtest/test_zrepl_prot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,58 @@ class Target {
int m_listenfd;
};

/*
* Stale Snapshot deletion verification
*/
TEST(StaleSnapshot, Destroy) {
Zrepl zrepl;
Target target;
int rc, control_fd;
SocketFd datasock;
TestPool pool("stale_snap_pool");
std::string vol_name = pool.getZvolName("vol");
std::string snap_name1 = pool.getZvolName("vol@usersnap");
std::string snap_name2 = pool.getZvolName("vol@.io_snap");
std::string snap_name3 = pool.getZvolName("vol@.io_snap1.2");
std::string snap_name4 = pool.getZvolName("vol@rebuild_snap");
std::string snap_name5 = pool.getZvolName("vol_rebuild_clone@.io_snap");
std::string snap_name6 = pool.getZvolName("vol_rebuild_clone@.io_snap1.2");
std::string host;
uint16_t port;
std::string output;

zrepl.start();
pool.create();
pool.createZvol("vol", "-o io.openebs:targetip=127.0.0.1");
pool.createZvol("vol_rebuild_clone", "-o io.openebs:targetip=127.0.0.2");
output = execCmd("zfs", std::string("snapshot ") + snap_name1);
output = execCmd("zfs", std::string("snapshot ") + snap_name2);
output = execCmd("zfs", std::string("snapshot ") + snap_name3);
output = execCmd("zfs", std::string("snapshot ") + snap_name4);
output = execCmd("zfs", std::string("snapshot ") + snap_name5);
output = execCmd("zfs", std::string("snapshot ") + snap_name6);
output = execCmd("zfs", std::string("list -t all"));

printf("%s\n", output.c_str());

zrepl.kill();

zrepl.start();
pool.import();

rc = target.listen();
ASSERT_GE(rc, 0);
control_fd = target.accept(-1);
ASSERT_GE(control_fd, 0);

do_handshake(vol_name, host, port, NULL, NULL, control_fd, ZVOL_OP_STATUS_OK);
do_data_connection(datasock.fd(), host, port, vol_name, 4096, 2);

output = execCmd("zfs", std::string("list -t all"));
printf("%s\n", output.c_str());
ASSERT_EQ(output.find(".io_snap"), std::string::npos);
}

class ZreplHandshakeTest : public testing::Test {
protected:
/* Shared setup hook for all zrepl handshake tests - called just once */
Expand Down

0 comments on commit d69dbc9

Please sign in to comment.