Remove the magic way of configuring NFS backed swap.
This code dates back to the very first diskless support on FreeBSD, back when swapon(8) couldn't simply be run on a NFS backed file. Suggested replacement command sequence on the client: dd if=/dev/zero of=/swapfile bs=1k count=1 oseek=100000 swapon /swapfile rm -f /swapfile For whatever value of 100000 you want.
This commit is contained in:
parent
6d79a6e473
commit
0bddf4c8e9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=118944
@ -155,17 +155,14 @@ struct bootpc_globalcontext {
|
||||
struct bootpc_ifcontext *lastinterface;
|
||||
u_int32_t xid;
|
||||
int gotrootpath;
|
||||
int gotswappath;
|
||||
int gotgw;
|
||||
int ifnum;
|
||||
int secs;
|
||||
int starttime;
|
||||
struct bootp_packet reply;
|
||||
int replylen;
|
||||
struct bootpc_ifcontext *setswapfs;
|
||||
struct bootpc_ifcontext *setrootfs;
|
||||
struct bootpc_ifcontext *sethostname;
|
||||
char lookup_path[24];
|
||||
struct bootpc_tagcontext tmptag;
|
||||
struct bootpc_tagcontext tag;
|
||||
};
|
||||
@ -220,9 +217,6 @@ SYSCTL_STRING(_kern, OID_AUTO, bootp_cookie, CTLFLAG_RD,
|
||||
/* mountd RPC */
|
||||
static int md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp,
|
||||
int *fhsizep, struct nfs_args *args, struct thread *td);
|
||||
static int md_lookup_swap(struct sockaddr_in *mdsin, char *path,
|
||||
u_char *fhp, int *fhsizep, struct nfs_args *args,
|
||||
struct thread *td);
|
||||
static int setfs(struct sockaddr_in *addr, char *path, char *p);
|
||||
static int getdec(char **ptr);
|
||||
static char *substr(char *a, char *b);
|
||||
@ -1495,9 +1489,6 @@ bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
|
||||
ifctx->myaddr.sin_addr = ifctx->reply.yiaddr;
|
||||
|
||||
ip = ntohl(ifctx->myaddr.sin_addr.s_addr);
|
||||
snprintf(gctx->lookup_path, sizeof(gctx->lookup_path),
|
||||
"swap.%d.%d.%d.%d",
|
||||
ip >> 24, (ip >> 16) & 255, (ip >> 8) & 255, ip & 255);
|
||||
|
||||
printf("%s at ", ifctx->ireq.ifr_name);
|
||||
print_sin_addr(&ifctx->myaddr);
|
||||
@ -1575,45 +1566,6 @@ bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
|
||||
panic("Failed to set rootfs to %s", p);
|
||||
}
|
||||
|
||||
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
||||
TAG_SWAP);
|
||||
if (p != NULL) {
|
||||
if (gctx->setswapfs != NULL) {
|
||||
printf("swapfs %s (ignored) ", p);
|
||||
} else if (setfs(&nd->swap_saddr,
|
||||
nd->swap_hostnam, p)) {
|
||||
gctx->gotswappath = 1;
|
||||
gctx->setswapfs = ifctx;
|
||||
printf("swapfs %s ", p);
|
||||
|
||||
p = bootpc_tag(&gctx->tag, &ifctx->reply,
|
||||
ifctx->replylen,
|
||||
TAG_SWAPOPTS);
|
||||
if (p != NULL) {
|
||||
/* swap mount options */
|
||||
mountopts(&nd->swap_args, p);
|
||||
printf("swapopts %s ", p);
|
||||
}
|
||||
|
||||
p = bootpc_tag(&gctx->tag, &ifctx->reply,
|
||||
ifctx->replylen,
|
||||
TAG_SWAPSIZE);
|
||||
if (p != NULL) {
|
||||
int swaplen;
|
||||
if (gctx->tag.taglen != 4)
|
||||
panic("bootpc: "
|
||||
"Expected 4 bytes for swaplen, "
|
||||
"not %d bytes",
|
||||
gctx->tag.taglen);
|
||||
bcopy(p, &swaplen, 4);
|
||||
nd->swap_nblks = ntohl(swaplen);
|
||||
printf("swapsize %d KB ",
|
||||
nd->swap_nblks);
|
||||
}
|
||||
} else
|
||||
panic("Failed to set swapfs to %s", p);
|
||||
}
|
||||
|
||||
p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
|
||||
TAG_HOSTNAME);
|
||||
if (p != NULL) {
|
||||
@ -1762,14 +1714,10 @@ bootpc_init(void)
|
||||
|
||||
mountopts(&nd->root_args, NULL);
|
||||
|
||||
mountopts(&nd->swap_args, NULL);
|
||||
|
||||
for (ifctx = gctx->interfaces; ifctx != NULL; ifctx = ifctx->next)
|
||||
if (bootpc_ifctx_isresolved(ifctx) != 0)
|
||||
bootpc_decode_reply(nd, ifctx, gctx);
|
||||
|
||||
if (gctx->gotswappath == 0)
|
||||
nd->swap_nblks = 0;
|
||||
#ifdef BOOTP_NFSROOT
|
||||
if (gctx->gotrootpath == 0)
|
||||
panic("bootpc: No root path offered");
|
||||
@ -1802,24 +1750,6 @@ bootpc_init(void)
|
||||
if (error != 0)
|
||||
panic("nfs_boot: mountd root, error=%d", error);
|
||||
|
||||
if (gctx->gotswappath != 0) {
|
||||
|
||||
error = md_mount(&nd->swap_saddr,
|
||||
nd->swap_hostnam,
|
||||
nd->swap_fh, &nd->swap_fhsize,
|
||||
&nd->swap_args, td);
|
||||
if (error != 0)
|
||||
panic("nfs_boot: mountd swap, error=%d",
|
||||
error);
|
||||
|
||||
error = md_lookup_swap(&nd->swap_saddr,
|
||||
gctx->lookup_path,
|
||||
nd->swap_fh, &nd->swap_fhsize,
|
||||
&nd->swap_args, td);
|
||||
if (error != 0)
|
||||
panic("nfs_boot: lookup swap, error=%d",
|
||||
error);
|
||||
}
|
||||
nfs_diskless_valid = 3;
|
||||
}
|
||||
|
||||
@ -1936,96 +1866,3 @@ md_mount(struct sockaddr_in *mdsin, char *path, u_char *fhp, int *fhsizep,
|
||||
m_freem(m);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
md_lookup_swap(struct sockaddr_in *mdsin, char *path, u_char *fhp, int *fhsizep,
|
||||
struct nfs_args *args, struct thread *td)
|
||||
{
|
||||
struct mbuf *m;
|
||||
int error;
|
||||
int size = -1;
|
||||
int attribs_present;
|
||||
int status;
|
||||
union {
|
||||
u_int32_t v2[17];
|
||||
u_int32_t v3[21];
|
||||
} fattribs;
|
||||
|
||||
m = m_get(M_TRYWAIT, MT_DATA);
|
||||
if (m == NULL)
|
||||
return ENOBUFS;
|
||||
|
||||
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
||||
*mtod(m, u_int32_t *) = txdr_unsigned(*fhsizep);
|
||||
bcopy(fhp, mtod(m, u_char *) + sizeof(u_int32_t), *fhsizep);
|
||||
m->m_len = *fhsizep + sizeof(u_int32_t);
|
||||
} else {
|
||||
bcopy(fhp, mtod(m, u_char *), NFSX_V2FH);
|
||||
m->m_len = NFSX_V2FH;
|
||||
}
|
||||
|
||||
m->m_next = xdr_string_encode(path, strlen(path));
|
||||
if (m->m_next == NULL) {
|
||||
error = ENOBUFS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Do RPC to nfsd. */
|
||||
if ((args->flags & NFSMNT_NFSV3) != 0)
|
||||
error = krpc_call(mdsin, NFS_PROG, NFS_VER3,
|
||||
NFSPROC_LOOKUP, &m, NULL, td);
|
||||
else
|
||||
error = krpc_call(mdsin, NFS_PROG, NFS_VER2,
|
||||
NFSV2PROC_LOOKUP, &m, NULL, td);
|
||||
if (error != 0)
|
||||
return error; /* message already freed */
|
||||
|
||||
if (xdr_int_decode(&m, &status) != 0)
|
||||
goto bad;
|
||||
if (status != 0) {
|
||||
error = ENOENT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
||||
if (xdr_int_decode(&m, fhsizep) != 0 ||
|
||||
*fhsizep > NFSX_V3FHMAX ||
|
||||
*fhsizep <= 0)
|
||||
goto bad;
|
||||
} else
|
||||
*fhsizep = NFSX_V2FH;
|
||||
|
||||
if (xdr_opaque_decode(&m, fhp, *fhsizep) != 0)
|
||||
goto bad;
|
||||
|
||||
if ((args->flags & NFSMNT_NFSV3) != 0) {
|
||||
if (xdr_int_decode(&m, &attribs_present) != 0)
|
||||
goto bad;
|
||||
if (attribs_present != 0) {
|
||||
if (xdr_opaque_decode(&m, (u_char *) &fattribs.v3,
|
||||
sizeof(u_int32_t) * 21) != 0)
|
||||
goto bad;
|
||||
size = fxdr_unsigned(u_int32_t, fattribs.v3[6]);
|
||||
}
|
||||
} else {
|
||||
if (xdr_opaque_decode(&m,(u_char *) &fattribs.v2,
|
||||
sizeof(u_int32_t) * 17) != 0)
|
||||
goto bad;
|
||||
size = fxdr_unsigned(u_int32_t, fattribs.v2[5]);
|
||||
}
|
||||
|
||||
if (nfsv3_diskless.swap_nblks == 0 && size != -1) {
|
||||
nfsv3_diskless.swap_nblks = size / 1024;
|
||||
printf("md_lookup_swap: Swap size is %d KB\n",
|
||||
nfsv3_diskless.swap_nblks);
|
||||
}
|
||||
|
||||
goto out;
|
||||
|
||||
bad:
|
||||
error = EBADRPC;
|
||||
|
||||
out:
|
||||
m_freem(m);
|
||||
return error;
|
||||
}
|
||||
|
@ -129,8 +129,6 @@ nfs_setup_diskless(void)
|
||||
/* set up gateway */
|
||||
inaddr_to_sockaddr("boot.netif.gateway", &nd->mygateway);
|
||||
|
||||
/* XXX set up swap? */
|
||||
|
||||
/* set up root mount */
|
||||
nd->root_args.rsize = 8192; /* XXX tunable? */
|
||||
nd->root_args.wsize = 8192;
|
||||
|
@ -141,13 +141,6 @@ SYSCTL_OPAQUE(_vfs_nfs, OID_AUTO, diskless_rootaddr, CTLFLAG_RD,
|
||||
&nfsv3_diskless.root_saddr, sizeof nfsv3_diskless.root_saddr,
|
||||
"%Ssockaddr_in", "");
|
||||
|
||||
SYSCTL_STRING(_vfs_nfs, OID_AUTO, diskless_swappath, CTLFLAG_RD,
|
||||
nfsv3_diskless.swap_hostnam, 0, "");
|
||||
|
||||
SYSCTL_OPAQUE(_vfs_nfs, OID_AUTO, diskless_swapaddr, CTLFLAG_RD,
|
||||
&nfsv3_diskless.swap_saddr, sizeof nfsv3_diskless.swap_saddr,
|
||||
"%Ssockaddr_in","");
|
||||
|
||||
|
||||
void nfsargs_ntoh(struct nfs_args *);
|
||||
static int nfs_mountdiskless(char *, char *, int,
|
||||
@ -204,15 +197,6 @@ nfs_convert_diskless(void)
|
||||
sizeof(struct ifaliasreq));
|
||||
bcopy(&nfs_diskless.mygateway, &nfsv3_diskless.mygateway,
|
||||
sizeof(struct sockaddr_in));
|
||||
nfs_convert_oargs(&nfsv3_diskless.swap_args,&nfs_diskless.swap_args);
|
||||
nfsv3_diskless.swap_fhsize = NFSX_V2FH;
|
||||
bcopy(nfs_diskless.swap_fh, nfsv3_diskless.swap_fh, NFSX_V2FH);
|
||||
bcopy(&nfs_diskless.swap_saddr,&nfsv3_diskless.swap_saddr,
|
||||
sizeof(struct sockaddr_in));
|
||||
bcopy(nfs_diskless.swap_hostnam, nfsv3_diskless.swap_hostnam, MNAMELEN);
|
||||
nfsv3_diskless.swap_nblks = nfs_diskless.swap_nblks;
|
||||
bcopy(&nfs_diskless.swap_ucred, &nfsv3_diskless.swap_ucred,
|
||||
sizeof(struct ucred));
|
||||
nfs_convert_oargs(&nfsv3_diskless.root_args,&nfs_diskless.root_args);
|
||||
nfsv3_diskless.root_fhsize = NFSX_V2FH;
|
||||
bcopy(nfs_diskless.root_fh, nfsv3_diskless.root_fh, NFSX_V2FH);
|
||||
@ -385,7 +369,6 @@ nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, struct ucred *cred,
|
||||
int
|
||||
nfs_mountroot(struct mount *mp, struct thread *td)
|
||||
{
|
||||
struct mount *swap_mp;
|
||||
struct nfsv3_diskless *nd = &nfsv3_diskless;
|
||||
struct socket *so;
|
||||
struct vnode *vp;
|
||||
@ -409,17 +392,6 @@ nfs_mountroot(struct mount *mp, struct thread *td)
|
||||
*/
|
||||
splnet();
|
||||
|
||||
#ifdef notyet
|
||||
/* Set up swap credentials. */
|
||||
proc0.p_ucred->cr_uid = ntohl(nd->swap_ucred.cr_uid);
|
||||
proc0.p_ucred->cr_gid = ntohl(nd->swap_ucred.cr_gid);
|
||||
if ((proc0.p_ucred->cr_ngroups = ntohs(nd->swap_ucred.cr_ngroups)) >
|
||||
NGROUPS)
|
||||
proc0.p_ucred->cr_ngroups = NGROUPS;
|
||||
for (i = 0; i < proc0.p_ucred->cr_ngroups; i++)
|
||||
proc0.p_ucred->cr_groups[i] = ntohl(nd->swap_ucred.cr_groups[i]);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Do enough of ifconfig(8) so that the critical net interface can
|
||||
* talk to the server.
|
||||
@ -488,41 +460,6 @@ nfs_mountroot(struct mount *mp, struct thread *td)
|
||||
return (error);
|
||||
}
|
||||
|
||||
swap_mp = NULL;
|
||||
if (nd->swap_nblks) {
|
||||
|
||||
/* Convert to DEV_BSIZE instead of Kilobyte */
|
||||
nd->swap_nblks *= 2;
|
||||
|
||||
/*
|
||||
* Create a fake mount point just for the swap vnode so that the
|
||||
* swap file can be on a different server from the rootfs.
|
||||
*/
|
||||
nd->swap_args.fh = nd->swap_fh;
|
||||
nd->swap_args.fhsize = nd->swap_fhsize;
|
||||
l = ntohl(nd->swap_saddr.sin_addr.s_addr);
|
||||
snprintf(buf, sizeof(buf), "%ld.%ld.%ld.%ld:%s",
|
||||
(l >> 24) & 0xff, (l >> 16) & 0xff,
|
||||
(l >> 8) & 0xff, (l >> 0) & 0xff, nd->swap_hostnam);
|
||||
printf("NFS SWAP: %s\n", buf);
|
||||
if ((error = nfs_mountdiskless(buf, "/swap", 0,
|
||||
&nd->swap_saddr, &nd->swap_args, td, &vp, &swap_mp)) != 0)
|
||||
return (error);
|
||||
vfs_unbusy(swap_mp, td);
|
||||
|
||||
VTONFS(vp)->n_size = VTONFS(vp)->n_vattr.va_size =
|
||||
nd->swap_nblks * DEV_BSIZE ;
|
||||
/*
|
||||
* Since the swap file is not the root dir of a filesystem,
|
||||
* hack it to a regular file.
|
||||
*/
|
||||
vp->v_type = VREG;
|
||||
vp->v_vflag = 0;
|
||||
vp->v_iflag = 0;
|
||||
VREF(vp);
|
||||
swaponvp(td, vp, NODEV, nd->swap_nblks);
|
||||
}
|
||||
|
||||
mp->mnt_flag |= MNT_ROOTFS;
|
||||
mp->mnt_vnodecovered = NULLVP;
|
||||
rootvp = vp;
|
||||
|
@ -46,8 +46,7 @@
|
||||
* and to do a partial ifconfig(8) and route(8) so that the critical net
|
||||
* interface can communicate with the server.
|
||||
* The primary bootstrap is expected to fill in the appropriate fields before
|
||||
* starting the kernel. Whether or not the swap area is nfs mounted is
|
||||
* determined by the value in swdevt[0]. (equal to NODEV --> swap over nfs)
|
||||
* starting the kernel.
|
||||
* Currently only works for AF_INET protocols.
|
||||
* NB: All fields are stored in net byte order to avoid hassles with
|
||||
* client/server byte ordering differences.
|
||||
@ -64,13 +63,6 @@
|
||||
struct nfsv3_diskless {
|
||||
struct ifaliasreq myif; /* Default interface */
|
||||
struct sockaddr_in mygateway; /* Default gateway */
|
||||
struct nfs_args swap_args; /* Mount args for swap file */
|
||||
int swap_fhsize; /* Size of file handle */
|
||||
u_char swap_fh[NFSX_V3FHMAX]; /* Swap file's file handle */
|
||||
struct sockaddr_in swap_saddr; /* Address of swap server */
|
||||
char swap_hostnam[MNAMELEN]; /* Host name for mount pt */
|
||||
int swap_nblks; /* Size of server swap file */
|
||||
struct ucred swap_ucred; /* Swap credentials */
|
||||
struct nfs_args root_args; /* Mount args for root fs */
|
||||
int root_fhsize; /* Size of root file handle */
|
||||
u_char root_fh[NFSX_V3FHMAX]; /* File handle of root dir */
|
||||
@ -106,12 +98,6 @@ struct onfs_args {
|
||||
struct nfs_diskless {
|
||||
struct ifaliasreq myif; /* Default interface */
|
||||
struct sockaddr_in mygateway; /* Default gateway */
|
||||
struct onfs_args swap_args; /* Mount args for swap file */
|
||||
u_char swap_fh[NFSX_V2FH]; /* Swap file's file handle */
|
||||
struct sockaddr_in swap_saddr; /* Address of swap server */
|
||||
char swap_hostnam[MNAMELEN]; /* Host name for mount pt */
|
||||
int swap_nblks; /* Size of server swap file */
|
||||
struct ucred swap_ucred; /* Swap credentials */
|
||||
struct onfs_args root_args; /* Mount args for root fs */
|
||||
u_char root_fh[NFSX_V2FH]; /* File handle of root dir */
|
||||
struct sockaddr_in root_saddr; /* Address of root server */
|
||||
|
Loading…
Reference in New Issue
Block a user