* High level function to manipulate export options on a mount point * and the passed in netexport. * Struct export_args *argp is the variable used to twiddle options, * the structure is described in sys/mount.h */
| 297 | * the structure is described in sys/mount.h |
| 298 | */ |
| 299 | int |
| 300 | vfs_export(struct mount *mp, struct export_args *argp) |
| 301 | { |
| 302 | struct netexport *nep; |
| 303 | int error; |
| 304 | |
| 305 | if ((argp->ex_flags & (MNT_DELEXPORT | MNT_EXPORTED)) == 0) |
| 306 | return (EINVAL); |
| 307 | |
| 308 | if ((argp->ex_flags & MNT_EXPORTED) != 0 && |
| 309 | (argp->ex_numsecflavors < 0 |
| 310 | || argp->ex_numsecflavors >= MAXSECFLAVORS)) |
| 311 | return (EINVAL); |
| 312 | |
| 313 | error = 0; |
| 314 | lockmgr(&mp->mnt_explock, LK_EXCLUSIVE, NULL); |
| 315 | nep = mp->mnt_export; |
| 316 | if (argp->ex_flags & MNT_DELEXPORT) { |
| 317 | if (nep == NULL) { |
| 318 | error = ENOENT; |
| 319 | goto out; |
| 320 | } |
| 321 | if (mp->mnt_flag & MNT_EXPUBLIC) { |
| 322 | vfs_setpublicfs(NULL, NULL, NULL); |
| 323 | MNT_ILOCK(mp); |
| 324 | mp->mnt_flag &= ~MNT_EXPUBLIC; |
| 325 | MNT_IUNLOCK(mp); |
| 326 | } |
| 327 | vfs_free_addrlist(nep); |
| 328 | mp->mnt_export = NULL; |
| 329 | free(nep, M_MOUNT); |
| 330 | nep = NULL; |
| 331 | MNT_ILOCK(mp); |
| 332 | mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED); |
| 333 | MNT_IUNLOCK(mp); |
| 334 | } |
| 335 | if (argp->ex_flags & MNT_EXPORTED) { |
| 336 | if (nep == NULL) { |
| 337 | nep = malloc(sizeof(struct netexport), M_MOUNT, M_WAITOK | M_ZERO); |
| 338 | mp->mnt_export = nep; |
| 339 | } |
| 340 | if (argp->ex_flags & MNT_EXPUBLIC) { |
| 341 | if ((error = vfs_setpublicfs(mp, nep, argp)) != 0) |
| 342 | goto out; |
| 343 | MNT_ILOCK(mp); |
| 344 | mp->mnt_flag |= MNT_EXPUBLIC; |
| 345 | MNT_IUNLOCK(mp); |
| 346 | } |
| 347 | if (argp->ex_numsecflavors == 0) { |
| 348 | argp->ex_numsecflavors = 1; |
| 349 | argp->ex_secflavors[0] = AUTH_SYS; |
| 350 | } |
| 351 | if ((error = vfs_hang_addrlist(mp, nep, argp))) |
| 352 | goto out; |
| 353 | MNT_ILOCK(mp); |
| 354 | mp->mnt_flag |= MNT_EXPORTED; |
| 355 | MNT_IUNLOCK(mp); |
| 356 | } |
no test coverage detected