svn commit: r256992 - in projects/vps: sys/vps usr.sbin/vpsctl
Will Andrews
will at FreeBSD.org
Wed Oct 23 17:17:58 UTC 2013
Author: will
Date: Wed Oct 23 17:17:57 2013
New Revision: 256992
URL: http://svnweb.freebsd.org/changeset/base/256992
Log:
Sync with svn.7he.at/vps/trunk r193.
r193 | klaus | 2013-07-19 09:26:49 -0600 (Fri, 19 Jul 2013) | 3 lines
Some modifications in order to allow migration of vps with nfs root.
Submitted by: Klaus P. Ohrhallinger <k at 7he.at>
Modified:
projects/vps/sys/vps/vps_libdump.h
projects/vps/sys/vps/vps_restore.c
projects/vps/sys/vps/vps_snapst.c
projects/vps/usr.sbin/vpsctl/vpsctl.c
Modified: projects/vps/sys/vps/vps_libdump.h
==============================================================================
--- projects/vps/sys/vps/vps_libdump.h Wed Oct 23 17:13:07 2013 (r256991)
+++ projects/vps/sys/vps/vps_libdump.h Wed Oct 23 17:17:57 2013 (r256992)
@@ -131,7 +131,7 @@ void vps_libdump_printheader(struct vps_
#define VPS_DUMPOBJT_UCRED 120
#define VPS_DUMPH_MAGIC 0xc0debabe
-#define VPS_DUMPH_VERSION 0x20130715
+#define VPS_DUMPH_VERSION 0x20130719
#define VPS_DUMPH_MSB 12
#define VPS_DUMPH_LSB 21
#define VPS_DUMPH_32BIT 32
@@ -318,11 +318,19 @@ struct vps_dump_mount {
char mnton[0x80];
char fstype[0x10];
uint8 vpsmount;
- uint8 _pad0[7];
+ uint8 optcnt;
+ uint8 _pad0[6];
uint64 flags;
PTR(mnt_cred);
};
+struct vps_dump_mount_opt {
+ char name[0x40];
+ char value[0x100];
+ uint16 len;
+ uint16 _pad0[3];
+};
+
struct vps_dump_vnet {
PTR(orig_ptr);
};
Modified: projects/vps/sys/vps/vps_restore.c
==============================================================================
--- projects/vps/sys/vps/vps_restore.c Wed Oct 23 17:13:07 2013 (r256991)
+++ projects/vps/sys/vps/vps_restore.c Wed Oct 23 17:17:57 2013 (r256992)
@@ -4161,6 +4161,7 @@ static int
vps_restore_mounts(struct vps_snapst_ctx *ctx, struct vps *vps,
char *rootfspath)
{
+ struct vps_dump_mount_opt *dvmopt;
struct vps_dump_mount *dvm;
struct vps_dumpobj *o1;
struct vps *savevps;
@@ -4171,6 +4172,7 @@ vps_restore_mounts(struct vps_snapst_ctx
char *fspath;
char *errmsg;
int error = 0;
+ int i;
ncr = NULL;
@@ -4185,7 +4187,7 @@ vps_restore_mounts(struct vps_snapst_ctx
save_rdir = save_cdir = NULL;
}
- errmsg_len = 0x100;
+ errmsg_len = 0xf0;
errmsg = malloc(errmsg_len, M_TEMP, M_WAITOK);
while (vdo_typeofnext(ctx) == VPS_DUMPOBJT_MOUNT) {
@@ -4204,6 +4206,34 @@ vps_restore_mounts(struct vps_snapst_ctx
if (vps != NULL && !strcmp(dvm->mnton, rootfspath))
continue;
+ ma = NULL;
+
+ if (dvm->optcnt * sizeof(*dvmopt) >
+ (o1->size - sizeof(*dvm))) {
+ ERRMSG(ctx, "%s: dvm->optcnt=%d seems invalid !\n",
+ __func__, dvm->optcnt);
+ error = EINVAL;
+ goto out;
+ }
+ dvmopt = (struct vps_dump_mount_opt *)(dvm+1);
+ for (i = 0; i < dvm->optcnt; i++) {
+ DBGR("%s: opt name=[%s] value=%p len=%u\n",
+ __func__, dvmopt->name, dvmopt->value,
+ dvmopt->len);
+
+ if (!strcmp(dvm->fstype, "nfs")) {
+ /*
+ if (!strcmp(dvmopt->name, "addr") ||
+ !strcmp(dvmopt->name, "fh") ||
+ !strcmp(dvmopt->name, "hostname"))
+ */
+ if (1)
+ ma = mount_arg(ma, dvmopt->name,
+ dvmopt->value, dvmopt->len);
+ }
+ dvmopt += 1;
+ }
+
if (vdo_typeofnext(ctx) == VPS_DUMPOBJT_UCRED) {
vdo_next(ctx);
}
@@ -4236,24 +4266,11 @@ vps_restore_mounts(struct vps_snapst_ctx
if (dvm->vpsmount)
/* dvm->mnton is always absolute, so we have to
strip it. */
- fspath = dvm->mnton + strlen (rootfspath);
+ fspath = dvm->mnton + strlen(rootfspath);
else
fspath = dvm->mnton;
+ /*DBGR("%s: fspath=[%s]\n", __func__, fspath);*/
-#if 0
- error = kernel_vmount(
- dvm->flags,
- "fstype", dvm->fstype,
- /* "fspath", dvm->mnton, */
- "fspath", fspath,
- /* --> nullfs */
- "target", dvm->mntfrom,
- "from", dvm->mntfrom,
- "errmsg", errmsg,
- NULL
- );
-#endif
- ma = NULL;
ma = mount_arg(ma, "fstype", dvm->fstype, -1);
ma = mount_arg(ma, "fspath", fspath, -1);
if (!strcmp(dvm->fstype, "nullfs") ||
@@ -4262,11 +4279,11 @@ vps_restore_mounts(struct vps_snapst_ctx
ma = mount_arg(ma, "from", dvm->mntfrom, -1);
ma = mount_arg(ma, "errmsg", errmsg, errmsg_len);
memset(errmsg, 0, errmsg_len);
- error = kernel_mount(ma, dvm->flags);
+ error = kernel_mount(ma, dvm->flags);
if (error) {
ERRMSG(ctx, "%s: kernel_mount() error: %d [%s]\n",
- __func__, error, errmsg);
+ __func__, error, errmsg);
goto out;
}
Modified: projects/vps/sys/vps/vps_snapst.c
==============================================================================
--- projects/vps/sys/vps/vps_snapst.c Wed Oct 23 17:13:07 2013 (r256991)
+++ projects/vps/sys/vps/vps_snapst.c Wed Oct 23 17:17:57 2013 (r256992)
@@ -677,6 +677,8 @@ vps_snapshot_vnodepath(struct vps_snapst
if (error != 0) {
free(buf, M_TEMP);
vrele(vp);
+ ERRMSG(ctx, "%s: vn_fullpath1() failed for vp=%p\n",
+ __func__, vp);
return (error);
}
@@ -907,8 +909,10 @@ static int
vps_snapshot_mounts(struct vps_snapst_ctx *ctx, struct vps *vps)
{
int error = 0;
- struct vps_dumpobj *o1;
+ struct vps_dumpobj *o1, *o2;
struct vps_dump_mount *vdm;
+ struct vps_dump_mount_opt *vdmopt;
+ struct vfsopt *opt;
struct mount *mp;
char *mntfrom, *mnton, *fstype, *vpsroot;
int len;
@@ -924,7 +928,7 @@ vps_snapshot_mounts(struct vps_snapst_ct
*/
DBGS("%s: vps's rootpath=[%s] vnode=%p\n",
- __func__, vps->_rootpath, vps->_rootvnode);
+ __func__, vps->_rootpath, vps->_rootvnode);
vpsroot = strdup(vps->_rootpath, M_TEMP);
if (vpsroot[strlen(vpsroot) - 1] == '/')
@@ -932,7 +936,8 @@ vps_snapshot_mounts(struct vps_snapst_ct
len = strlen(vpsroot);
/* If we ran out of memory previously, we try again. */
- again:
+ again:
+ o1 = NULL;
mtx_lock(&mountlist_mtx);
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
@@ -958,11 +963,20 @@ vps_snapshot_mounts(struct vps_snapst_ct
return (EINVAL);
}
#endif
- o1 = vdo_create(ctx, VPS_DUMPOBJT_MOUNT, M_WAITOK);
+ if ((o2 = vdo_create(ctx, VPS_DUMPOBJT_MOUNT, M_NOWAIT))
+ == NULL) {
+ mtx_unlock(&mountlist_mtx);
+ if (o1 != NULL)
+ vdo_discard(ctx, o1);
+ goto again;
+ }
+ /* Remember the dump object of the first mount. */
+ if (o1 == NULL)
+ o1 = o2;
vdm = vdo_space(ctx, sizeof(*vdm), M_NOWAIT);
-
if (vdm == NULL) {
+ mtx_unlock(&mountlist_mtx);
vdo_discard(ctx, o1);
goto again;
}
@@ -970,12 +984,35 @@ vps_snapshot_mounts(struct vps_snapst_ct
strlcpy(vdm->mnton, mnton, sizeof(vdm->mnton));
strlcpy(vdm->fstype, fstype, sizeof(vdm->fstype));
vdm->flags = mp->mnt_flag;
+ vdm->optcnt = 0;
/* Mounted from inside vps ? */
if (mp->mnt_cred->cr_vps == vps)
vdm->vpsmount = 1;
else
vdm->vpsmount = 0;
+ TAILQ_FOREACH(opt, mp->mnt_opt, link) {
+ vdmopt = vdo_space(ctx, sizeof(*vdmopt), M_NOWAIT);
+ if (vdmopt == NULL) {
+ mtx_unlock(&mountlist_mtx);
+ vdo_discard(ctx, o1);
+ goto again;
+ }
+ if (opt->len >= sizeof(vdmopt->value)) {
+ ERRMSG(ctx, "%s: opt->len=%d (name=[%s]) too big\n",
+ __func__, opt->len, opt->name);
+ mtx_unlock(&mountlist_mtx);
+ free(vpsroot, M_TEMP);
+ return (EINVAL);
+ }
+ strlcpy(vdmopt->name, opt->name, sizeof(vdmopt->name));
+ memcpy(vdmopt->value, opt->value, opt->len);
+ vdmopt->len = opt->len;
+ vdm->optcnt += 1;
+ DBGS("%s: opt name=[%s] value=%p len=%d\n",
+ __func__, opt->name, opt->value, opt->len);
+ }
+
if (vdm->vpsmount) {
vdm->mnt_cred = mp->mnt_cred;
Modified: projects/vps/usr.sbin/vpsctl/vpsctl.c
==============================================================================
--- projects/vps/usr.sbin/vpsctl/vpsctl.c Wed Oct 23 17:13:07 2013 (r256991)
+++ projects/vps/usr.sbin/vpsctl/vpsctl.c Wed Oct 23 17:17:57 2013 (r256992)
@@ -55,6 +55,7 @@
#include <sys/priv.h>
#include <sys/sysctl.h>
#include <sys/param.h>
+#include <sys/mount.h>
#include <signal.h>
#include <net/if.h>
#include <netinet/in.h>
@@ -308,7 +309,7 @@ vc_usage(FILE *out)
" snapshot <id> <file> \n"
" abort <id> \n"
" restore <id> <file> \n"
- " migrate <id> <remote-host> [norsync|onersync]\n"
+ " migrate <id> <remote-host> [norsync|onersync|tworsync]\n"
" \n"
" argshow <id> \n"
" ipnet <id> add <address/network, ...> \n"
@@ -1297,8 +1298,7 @@ vc_migrate(int argc, char **argv)
char *fsroot;
char cmd[0x100];
char file_n[MAXPATHLEN];
- char f_norsync = 0;
- char f_onersync = 0;
+ char cnt_rsync;
char str_suspend[] = "suspend";
char str_abort[] = "abort";
int pid, rfd, wfd;
@@ -1309,12 +1309,6 @@ vc_migrate(int argc, char **argv)
if (argc < 2)
return (vc_usage(stderr));
- if (argc > 2 && strcmp(argv[2], "norsync") == 0)
- f_norsync = 1;
-
- if (argc > 2 && strcmp(argv[2], "onersync") == 0)
- f_onersync = 1;
-
mig_did_suspend = 0;
mig_did_revoke = 0;
signal(SIGINT, vc_migrate_sighandler);
@@ -1341,6 +1335,28 @@ vc_migrate(int argc, char **argv)
else
fsroot = vc.fsroot;
+ if (1) {
+ struct statfs stf;
+
+ if ((error = statfs(fsroot, &stf)) != 0) {
+ fprintf(stderr, "statfs([%s]): error: %s\n",
+ fsroot, strerror(errno));
+ return (1);
+ }
+
+ if (stf.f_flags & MNT_LOCAL)
+ cnt_rsync = 2;
+ else
+ cnt_rsync = 0;
+ }
+
+ if (argc > 2 && strcmp(argv[2], "norsync") == 0)
+ cnt_rsync = 0;
+ else if (argc > 2 && strcmp(argv[2], "onersync") == 0)
+ cnt_rsync = 1;
+ else if (argc > 2 && strcmp(argv[2], "tworsync") == 0)
+ cnt_rsync = 2;
+
fprintf(stderr, "Opening ssh transport ... ");
if ((error = vc_get_ssh_transport(host, &pid, &rfd, &wfd)))
@@ -1348,43 +1364,44 @@ vc_migrate(int argc, char **argv)
fprintf(stderr, "done\n");
- if (f_norsync == 0) {
-
- fprintf(stderr, "Copying config file ... ");
- snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", _PATH_CONFDIR);
- write(wfd, cmd, strlen(cmd));
- if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, file_n)))
- goto resume;
+ /* Always syncing config file. */
+#if 1
+ fprintf(stderr, "Copying config file ... ");
+ snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", _PATH_CONFDIR);
+ write(wfd, cmd, strlen(cmd));
+ if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, file_n)))
+ goto resume;
- fprintf(stderr, "done\n");
+ fprintf(stderr, "done\n");
+#else
+ /* XXX transfer without using rsync */
+#endif
- /* Always create directories. */
- if (vc.fsroot_priv[0] != '\0') {
- /* Create vps' private root directory. */
- snprintf(cmd, sizeof(cmd), "mkdir -p %s\n", vc.fsroot_priv);
- write(wfd, cmd, strlen(cmd));
- //len = read(rfd, cmd, sizeof(cmd));
- }
- /* Create vps' mountpoint directory. */
- snprintf(cmd, sizeof(cmd), "mkdir -p %s\n", vc.fsroot);
+ /* Always create directories. */
+ if (vc.fsroot_priv[0] != '\0') {
+ /* Create vps' private root directory. */
+ snprintf(cmd, sizeof(cmd), "mkdir -p %s\n", vc.fsroot_priv);
write(wfd, cmd, strlen(cmd));
//len = read(rfd, cmd, sizeof(cmd));
+ }
+ /* Create vps' mountpoint directory. */
+ snprintf(cmd, sizeof(cmd), "mkdir -p %s\n", vc.fsroot);
+ write(wfd, cmd, strlen(cmd));
+ //len = read(rfd, cmd, sizeof(cmd));
- if (f_onersync == 0) {
-
- /* Start a first filesystem sync while vps is still running. */
+ if (cnt_rsync == 2) {
- fprintf(stderr, "Performing first filesystem sync ... ");
+ /* Start a first filesystem sync while vps is still running. */
- snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", fsroot);
- write(wfd, cmd, strlen(cmd));
- snprintf(cmd, sizeof(cmd), "%s/", fsroot);
- if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, cmd)))
- goto resume;
+ fprintf(stderr, "Performing first filesystem sync ... ");
- fprintf(stderr, "done\n");
+ snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", fsroot);
+ write(wfd, cmd, strlen(cmd));
+ snprintf(cmd, sizeof(cmd), "%s/", fsroot);
+ if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, cmd)))
+ goto resume;
- }
+ fprintf(stderr, "done\n");
}
@@ -1401,18 +1418,18 @@ vc_migrate(int argc, char **argv)
fprintf(stderr, "done\n");
- if (f_norsync == 0) {
+ if (cnt_rsync > 0) {
- fprintf(stderr, "Performing final filesystem sync ... ");
+ fprintf(stderr, "Performing final filesystem sync ... ");
- /* After suspending do the final filesystem sync. */
- snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", fsroot);
- write(wfd, cmd, strlen(cmd));
- snprintf(cmd, sizeof(cmd), "%s/", fsroot);
- if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, cmd)))
- goto resume;
+ /* After suspending do the final filesystem sync. */
+ snprintf(cmd, sizeof(cmd), "vpsctl rsyncserver %s/\n", fsroot);
+ write(wfd, cmd, strlen(cmd));
+ snprintf(cmd, sizeof(cmd), "%s/", fsroot);
+ if ((error = vc_rsync(RSYNC_MODE_CLIENT, rfd, wfd, cmd)))
+ goto resume;
- fprintf(stderr, "done\n");
+ fprintf(stderr, "done\n");
}
More information about the svn-src-projects
mailing list