Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 76a3730

Browse files
committed
mount nfs volumes when specified
Use external mount.nfs binary (nfs-utils-1-3-4, 188354e57) to avoid adding too much complexity (viz, rpc mnt protocol support). Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent 7641697 commit 76a3730

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

build/make-initrd.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cp ../src/init /tmp/hyperstart-rootfs
1515
cp busybox /tmp/hyperstart-rootfs
1616
cp iptables /tmp/hyperstart-rootfs
1717
cp libm.so.6 /tmp/hyperstart-rootfs/lib64/
18+
cp mount.nfs /tmp/hyperstart-rootfs/sbin/mount.nfs4
1819

1920
if [ "$1"x = "aarch64"x ]; then
2021
echo "build hyperstart for aarch64"

build/mount.nfs

112 KB
Binary file not shown.

src/container.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,33 @@ static int container_setup_volume(struct hyper_container *container)
113113
sprintf(path, "/tmp/%s", vol->mountpoint);
114114
sprintf(mountpoint, "./%s", vol->mountpoint);
115115

116-
fprintf(stdout, "mount %s to %s, tmp path %s\n",
117-
dev, vol->mountpoint, path);
118-
119116
if (hyper_mkdir(path, 0755) < 0) {
120117
perror("create volume dir failed");
121118
return -1;
122119
}
123120

124-
if (!strncmp(vol->fstype, "xfs", strlen("xfs")))
125-
options = "nouuid";
121+
if (!strcmp(vol->fstype, "nfs")) {
122+
fprintf(stdout, "mount nfs share %s to %s, tmp path %s\n",
123+
vol->device, vol->mountpoint, path);
126124

127-
if (mount(dev, path, vol->fstype, 0, options) < 0) {
128-
perror("mount volume device failed");
129-
return -1;
125+
if (hyper_mount_nfs(vol->device, path) < 0)
126+
return -1;
127+
/* nfs export has implicitly included _data part of the volume */
128+
sprintf(volume, "/%s/", path);
129+
} else {
130+
fprintf(stdout, "mount %s to %s, tmp path %s\n",
131+
dev, vol->mountpoint, path);
132+
133+
if (!strcmp(vol->fstype, "xfs"))
134+
options = "nouuid";
135+
136+
if (mount(dev, path, vol->fstype, 0, options) < 0) {
137+
perror("mount volume device failed");
138+
return -1;
139+
}
140+
sprintf(volume, "/%s/_data", path);
130141
}
131142

132-
sprintf(volume, "/%s/_data", path);
133143
if (container_check_file_volume(volume, &filevolume) < 0)
134144
return -1;
135145

src/util.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,11 @@ ssize_t nonblock_read(int fd, void *buf, size_t count)
703703

704704
return len > 0 ? len : ret;
705705
}
706+
707+
int hyper_mount_nfs(char *server, char *mountpoint)
708+
{
709+
char cmd[512];
710+
snprintf(cmd, sizeof(cmd), "mount.nfs4 -n %s %s", server, mountpoint);
711+
712+
return hyper_cmd(cmd);
713+
}

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ struct passwd *hyper_getpwnam(const char *name);
4040
struct group *hyper_getgrnam(const char *name);
4141
int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);
4242
ssize_t nonblock_read(int fd, void *buf, size_t count);
43+
int hyper_mount_nfs(char *server, char *mountpoint);
4344
#endif

0 commit comments

Comments
 (0)