Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2007 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stand-alone file reading package.
|
|
|
|
*/
|
|
|
|
|
2018-12-17 07:43:29 +00:00
|
|
|
#include <stand.h>
|
2012-08-05 14:48:28 +00:00
|
|
|
#include <sys/disk.h>
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/queue.h>
|
2012-08-05 14:48:28 +00:00
|
|
|
#include <part.h>
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <bootstrap.h>
|
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
#include "libzfs.h"
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
#include "zfsimpl.c"
|
2010-09-17 22:51:45 +00:00
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
/* Define the range of indexes to be populated with ZFS Boot Environments */
|
|
|
|
#define ZFS_BE_FIRST 4
|
|
|
|
#define ZFS_BE_LAST 8
|
|
|
|
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
static int zfs_open(const char *path, struct open_file *f);
|
|
|
|
static int zfs_close(struct open_file *f);
|
|
|
|
static int zfs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
|
|
|
|
static off_t zfs_seek(struct open_file *f, off_t offset, int where);
|
|
|
|
static int zfs_stat(struct open_file *f, struct stat *sb);
|
|
|
|
static int zfs_readdir(struct open_file *f, struct dirent *d);
|
|
|
|
|
2020-08-18 19:48:04 +00:00
|
|
|
static void zfs_bootenv_initial(const char *envname, spa_t *spa,
|
|
|
|
const char *name, const char *dsname, int checkpoint);
|
|
|
|
static void zfs_checkpoints_initial(spa_t *spa, const char *name,
|
|
|
|
const char *dsname);
|
2018-02-21 16:26:16 +00:00
|
|
|
|
2018-02-21 16:33:08 +00:00
|
|
|
struct devsw zfs_dev;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
|
|
|
struct fs_ops zfs_fsops = {
|
|
|
|
"zfs",
|
|
|
|
zfs_open,
|
|
|
|
zfs_close,
|
|
|
|
zfs_read,
|
2018-02-23 20:18:09 +00:00
|
|
|
null_write,
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
zfs_seek,
|
|
|
|
zfs_stat,
|
|
|
|
zfs_readdir
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In-core open file.
|
|
|
|
*/
|
|
|
|
struct file {
|
|
|
|
off_t f_seekp; /* seek pointer */
|
|
|
|
dnode_phys_t f_dnode;
|
|
|
|
uint64_t f_zap_type; /* zap type for readdir */
|
|
|
|
uint64_t f_num_leafs; /* number of fzap leaf blocks */
|
|
|
|
zap_leaf_phys_t *f_zap_leaf; /* zap leaf buffer */
|
|
|
|
};
|
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
static int zfs_env_index;
|
|
|
|
static int zfs_env_count;
|
|
|
|
|
|
|
|
SLIST_HEAD(zfs_be_list, zfs_be_entry) zfs_be_head = SLIST_HEAD_INITIALIZER(zfs_be_head);
|
|
|
|
struct zfs_be_list *zfs_be_headp;
|
|
|
|
struct zfs_be_entry {
|
2020-03-28 21:55:42 +00:00
|
|
|
char *name;
|
2015-12-31 20:00:53 +00:00
|
|
|
SLIST_ENTRY(zfs_be_entry) entries;
|
|
|
|
} *zfs_be, *zfs_be_tmp;
|
|
|
|
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
/*
|
|
|
|
* Open a file.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_open(const char *upath, struct open_file *f)
|
|
|
|
{
|
2012-05-12 09:03:30 +00:00
|
|
|
struct zfsmount *mount = (struct zfsmount *)f->f_devdata;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
struct file *fp;
|
|
|
|
int rc;
|
|
|
|
|
2012-05-13 10:54:43 +00:00
|
|
|
if (f->f_dev != &zfs_dev)
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* allocate file system specific data structure */
|
2019-11-03 14:36:16 +00:00
|
|
|
fp = calloc(1, sizeof(struct file));
|
|
|
|
if (fp == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
f->f_fsdata = fp;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
rc = zfs_lookup(mount, upath, &fp->f_dnode);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
fp->f_seekp = 0;
|
|
|
|
if (rc) {
|
|
|
|
f->f_fsdata = NULL;
|
|
|
|
free(fp);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_close(struct open_file *f)
|
|
|
|
{
|
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
|
2017-02-22 02:35:59 +00:00
|
|
|
dnode_cache_obj = NULL;
|
2019-11-03 14:36:16 +00:00
|
|
|
f->f_fsdata = NULL;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
|
|
|
free(fp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a portion of a file into kernel memory.
|
|
|
|
* Cross block boundaries when necessary.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_read(struct open_file *f, void *start, size_t size, size_t *resid /* out */)
|
|
|
|
{
|
2012-05-13 09:22:18 +00:00
|
|
|
const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
2011-02-27 19:41:40 +00:00
|
|
|
struct stat sb;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
size_t n;
|
|
|
|
int rc;
|
|
|
|
|
2011-02-27 19:41:40 +00:00
|
|
|
rc = zfs_stat(f, &sb);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
n = size;
|
2011-02-27 19:41:40 +00:00
|
|
|
if (fp->f_seekp + n > sb.st_size)
|
|
|
|
n = sb.st_size - fp->f_seekp;
|
2016-01-06 20:25:41 +00:00
|
|
|
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
rc = dnode_read(spa, &fp->f_dnode, fp->f_seekp, start, n);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
putchar(((char*) start)[i]);
|
|
|
|
}
|
|
|
|
fp->f_seekp += n;
|
|
|
|
if (resid)
|
|
|
|
*resid = size - n;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static off_t
|
|
|
|
zfs_seek(struct open_file *f, off_t offset, int where)
|
|
|
|
{
|
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
|
|
|
|
switch (where) {
|
|
|
|
case SEEK_SET:
|
|
|
|
fp->f_seekp = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
fp->f_seekp += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
2011-02-27 19:41:40 +00:00
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = zfs_stat(f, &sb);
|
|
|
|
if (error != 0) {
|
|
|
|
errno = error;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
fp->f_seekp = sb.st_size - offset;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
break;
|
2011-02-27 19:41:40 +00:00
|
|
|
}
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
default:
|
|
|
|
errno = EINVAL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (fp->f_seekp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_stat(struct open_file *f, struct stat *sb)
|
|
|
|
{
|
2012-05-13 09:22:18 +00:00
|
|
|
const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
|
2011-02-27 19:41:40 +00:00
|
|
|
return (zfs_dnode_stat(spa, &fp->f_dnode, sb));
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_readdir(struct open_file *f, struct dirent *d)
|
|
|
|
{
|
2012-05-13 09:22:18 +00:00
|
|
|
const spa_t *spa = ((struct zfsmount *)f->f_devdata)->spa;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
mzap_ent_phys_t mze;
|
2011-02-27 19:41:40 +00:00
|
|
|
struct stat sb;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
size_t bsize = fp->f_dnode.dn_datablkszsec << SPA_MINBLOCKSHIFT;
|
|
|
|
int rc;
|
|
|
|
|
2011-02-27 19:41:40 +00:00
|
|
|
rc = zfs_stat(f, &sb);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
if (!S_ISDIR(sb.st_mode))
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
return (ENOTDIR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the first read, get the zap type.
|
|
|
|
*/
|
|
|
|
if (fp->f_seekp == 0) {
|
|
|
|
rc = dnode_read(spa, &fp->f_dnode,
|
|
|
|
0, &fp->f_zap_type, sizeof(fp->f_zap_type));
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
if (fp->f_zap_type == ZBT_MICRO) {
|
|
|
|
fp->f_seekp = offsetof(mzap_phys_t, mz_chunk);
|
|
|
|
} else {
|
|
|
|
rc = dnode_read(spa, &fp->f_dnode,
|
|
|
|
offsetof(zap_phys_t, zap_num_leafs),
|
|
|
|
&fp->f_num_leafs,
|
|
|
|
sizeof(fp->f_num_leafs));
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
fp->f_seekp = bsize;
|
2019-11-03 14:36:16 +00:00
|
|
|
fp->f_zap_leaf = malloc(bsize);
|
|
|
|
if (fp->f_zap_leaf == NULL)
|
|
|
|
return (ENOMEM);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
rc = dnode_read(spa, &fp->f_dnode,
|
|
|
|
fp->f_seekp,
|
|
|
|
fp->f_zap_leaf,
|
|
|
|
bsize);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp->f_zap_type == ZBT_MICRO) {
|
|
|
|
mzap_next:
|
|
|
|
if (fp->f_seekp >= bsize)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
rc = dnode_read(spa, &fp->f_dnode,
|
|
|
|
fp->f_seekp, &mze, sizeof(mze));
|
2010-05-31 09:06:03 +00:00
|
|
|
if (rc)
|
|
|
|
return (rc);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
fp->f_seekp += sizeof(mze);
|
|
|
|
|
|
|
|
if (!mze.mze_name[0])
|
|
|
|
goto mzap_next;
|
|
|
|
|
|
|
|
d->d_fileno = ZFS_DIRENT_OBJ(mze.mze_value);
|
|
|
|
d->d_type = ZFS_DIRENT_TYPE(mze.mze_value);
|
|
|
|
strcpy(d->d_name, mze.mze_name);
|
|
|
|
d->d_namlen = strlen(d->d_name);
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
zap_leaf_t zl;
|
|
|
|
zap_leaf_chunk_t *zc, *nc;
|
|
|
|
int chunk;
|
|
|
|
size_t namelen;
|
|
|
|
char *p;
|
|
|
|
uint64_t value;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise this so we can use the ZAP size
|
|
|
|
* calculating macros.
|
|
|
|
*/
|
|
|
|
zl.l_bs = ilog2(bsize);
|
|
|
|
zl.l_phys = fp->f_zap_leaf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out which chunk we are currently looking at
|
|
|
|
* and consider seeking to the next leaf. We use the
|
|
|
|
* low bits of f_seekp as a simple chunk index.
|
|
|
|
*/
|
|
|
|
fzap_next:
|
|
|
|
chunk = fp->f_seekp & (bsize - 1);
|
|
|
|
if (chunk == ZAP_LEAF_NUMCHUNKS(&zl)) {
|
2016-04-21 19:57:40 +00:00
|
|
|
fp->f_seekp = rounddown2(fp->f_seekp, bsize) + bsize;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
chunk = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for EOF and read the new leaf.
|
|
|
|
*/
|
|
|
|
if (fp->f_seekp >= bsize * fp->f_num_leafs)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
rc = dnode_read(spa, &fp->f_dnode,
|
|
|
|
fp->f_seekp,
|
|
|
|
fp->f_zap_leaf,
|
|
|
|
bsize);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
zc = &ZAP_LEAF_CHUNK(&zl, chunk);
|
|
|
|
fp->f_seekp++;
|
|
|
|
if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY)
|
|
|
|
goto fzap_next;
|
|
|
|
|
2012-09-11 07:11:32 +00:00
|
|
|
namelen = zc->l_entry.le_name_numints;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
if (namelen > sizeof(d->d_name))
|
|
|
|
namelen = sizeof(d->d_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Paste the name back together.
|
|
|
|
*/
|
|
|
|
nc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_name_chunk);
|
|
|
|
p = d->d_name;
|
|
|
|
while (namelen > 0) {
|
|
|
|
int len;
|
|
|
|
len = namelen;
|
|
|
|
if (len > ZAP_LEAF_ARRAY_BYTES)
|
|
|
|
len = ZAP_LEAF_ARRAY_BYTES;
|
|
|
|
memcpy(p, nc->l_array.la_array, len);
|
|
|
|
p += len;
|
|
|
|
namelen -= len;
|
|
|
|
nc = &ZAP_LEAF_CHUNK(&zl, nc->l_array.la_next);
|
|
|
|
}
|
|
|
|
d->d_name[sizeof(d->d_name) - 1] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assume the first eight bytes of the value are
|
|
|
|
* a uint64_t.
|
|
|
|
*/
|
|
|
|
value = fzap_leaf_value(&zl, zc);
|
|
|
|
|
|
|
|
d->d_fileno = ZFS_DIRENT_OBJ(value);
|
|
|
|
d->d_type = ZFS_DIRENT_TYPE(value);
|
|
|
|
d->d_namlen = strlen(d->d_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-11-02 08:47:03 +00:00
|
|
|
vdev_read(vdev_t *vdev, void *priv, off_t offset, void *buf, size_t bytes)
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
{
|
2017-11-02 08:47:03 +00:00
|
|
|
int fd, ret;
|
2019-02-17 03:35:15 +00:00
|
|
|
size_t res, head, tail, total_size, full_sec_size;
|
|
|
|
unsigned secsz, do_tail_read;
|
|
|
|
off_t start_sec;
|
|
|
|
char *outbuf, *bouncebuf;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
|
|
|
fd = (uintptr_t) priv;
|
2019-02-17 03:35:15 +00:00
|
|
|
outbuf = (char *) buf;
|
2017-11-02 08:47:03 +00:00
|
|
|
bouncebuf = NULL;
|
|
|
|
|
|
|
|
ret = ioctl(fd, DIOCGSECTORSIZE, &secsz);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
2019-02-17 03:35:15 +00:00
|
|
|
/*
|
|
|
|
* Handling reads of arbitrary offset and size - multi-sector case
|
|
|
|
* and single-sector case.
|
|
|
|
*
|
|
|
|
* Multi-sector Case
|
|
|
|
* (do_tail_read = true if tail > 0)
|
|
|
|
*
|
|
|
|
* |<----------------------total_size--------------------->|
|
|
|
|
* | |
|
|
|
|
* |<--head-->|<--------------bytes------------>|<--tail-->|
|
|
|
|
* | | | |
|
|
|
|
* | | |<~full_sec_size~>| | |
|
|
|
|
* +------------------+ +------------------+
|
|
|
|
* | |0101010| . . . |0101011| |
|
|
|
|
* +------------------+ +------------------+
|
|
|
|
* start_sec start_sec + n
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Single-sector Case
|
|
|
|
* (do_tail_read = false)
|
|
|
|
*
|
|
|
|
* |<------total_size = secsz----->|
|
|
|
|
* | |
|
|
|
|
* |<-head->|<---bytes--->|<-tail->|
|
|
|
|
* +-------------------------------+
|
|
|
|
* | |0101010101010| |
|
|
|
|
* +-------------------------------+
|
|
|
|
* start_sec
|
|
|
|
*/
|
|
|
|
start_sec = offset / secsz;
|
|
|
|
head = offset % secsz;
|
|
|
|
total_size = roundup2(head + bytes, secsz);
|
|
|
|
tail = total_size - (head + bytes);
|
|
|
|
do_tail_read = ((tail > 0) && (head + bytes > secsz));
|
|
|
|
full_sec_size = total_size;
|
|
|
|
if (head > 0)
|
|
|
|
full_sec_size -= secsz;
|
|
|
|
if (do_tail_read)
|
|
|
|
full_sec_size -= secsz;
|
|
|
|
|
|
|
|
/* Return of partial sector data requires a bounce buffer. */
|
2020-05-09 06:25:20 +00:00
|
|
|
if ((head > 0) || do_tail_read || bytes < secsz) {
|
2020-02-26 18:12:12 +00:00
|
|
|
bouncebuf = malloc(secsz);
|
2017-11-02 08:47:03 +00:00
|
|
|
if (bouncebuf == NULL) {
|
|
|
|
printf("vdev_read: out of memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 17:44:22 +00:00
|
|
|
if (lseek(fd, start_sec * secsz, SEEK_SET) == -1) {
|
|
|
|
ret = errno;
|
|
|
|
goto error;
|
|
|
|
}
|
2019-02-17 03:35:15 +00:00
|
|
|
|
|
|
|
/* Partial data return from first sector */
|
|
|
|
if (head > 0) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
|
|
|
if (res != secsz) {
|
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
2019-02-17 17:47:08 +00:00
|
|
|
memcpy(outbuf, bouncebuf + head, min(secsz - head, bytes));
|
|
|
|
outbuf += min(secsz - head, bytes);
|
2019-02-17 03:35:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 06:25:20 +00:00
|
|
|
/*
|
|
|
|
* Full data return from read sectors.
|
|
|
|
* Note, there is still corner case where we read
|
|
|
|
* from sector boundary, but less than sector size, e.g. reading 512B
|
|
|
|
* from 4k sector.
|
|
|
|
*/
|
2019-02-17 03:35:15 +00:00
|
|
|
if (full_sec_size > 0) {
|
2020-05-09 06:25:20 +00:00
|
|
|
if (bytes < full_sec_size) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
|
|
|
if (res != secsz) {
|
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
memcpy(outbuf, bouncebuf, bytes);
|
|
|
|
} else {
|
|
|
|
res = read(fd, outbuf, full_sec_size);
|
|
|
|
if (res != full_sec_size) {
|
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
outbuf += full_sec_size;
|
2019-02-17 03:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Partial data return from last sector */
|
|
|
|
if (do_tail_read) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
|
|
|
if (res != secsz) {
|
2017-11-02 08:47:03 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
2019-02-17 03:35:15 +00:00
|
|
|
memcpy(outbuf, bouncebuf, secsz - tail);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
2017-11-02 08:47:03 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
error:
|
2020-02-26 18:12:12 +00:00
|
|
|
free(bouncebuf);
|
2017-11-02 08:47:03 +00:00
|
|
|
return (ret);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 06:23:31 +00:00
|
|
|
static int
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
vdev_write(vdev_t *vdev, off_t offset, void *buf, size_t bytes)
|
2020-06-20 06:23:31 +00:00
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
size_t head, tail, total_size, full_sec_size;
|
|
|
|
unsigned secsz, do_tail_write;
|
|
|
|
off_t start_sec;
|
|
|
|
ssize_t res;
|
|
|
|
char *outbuf, *bouncebuf;
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
fd = (uintptr_t)vdev->v_priv;
|
|
|
|
outbuf = (char *)buf;
|
2020-06-20 06:23:31 +00:00
|
|
|
bouncebuf = NULL;
|
|
|
|
|
|
|
|
ret = ioctl(fd, DIOCGSECTORSIZE, &secsz);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
start_sec = offset / secsz;
|
|
|
|
head = offset % secsz;
|
|
|
|
total_size = roundup2(head + bytes, secsz);
|
|
|
|
tail = total_size - (head + bytes);
|
|
|
|
do_tail_write = ((tail > 0) && (head + bytes > secsz));
|
|
|
|
full_sec_size = total_size;
|
|
|
|
if (head > 0)
|
|
|
|
full_sec_size -= secsz;
|
|
|
|
if (do_tail_write)
|
|
|
|
full_sec_size -= secsz;
|
|
|
|
|
|
|
|
/* Partial sector write requires a bounce buffer. */
|
|
|
|
if ((head > 0) || do_tail_write || bytes < secsz) {
|
|
|
|
bouncebuf = malloc(secsz);
|
|
|
|
if (bouncebuf == NULL) {
|
|
|
|
printf("vdev_write: out of memory\n");
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lseek(fd, start_sec * secsz, SEEK_SET) == -1) {
|
|
|
|
ret = errno;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Partial data for first sector */
|
|
|
|
if (head > 0) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
memcpy(bouncebuf + head, outbuf, min(secsz - head, bytes));
|
|
|
|
(void) lseek(fd, -secsz, SEEK_CUR);
|
|
|
|
res = write(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
outbuf += min(secsz - head, bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Full data write to sectors.
|
|
|
|
* Note, there is still corner case where we write
|
|
|
|
* to sector boundary, but less than sector size, e.g. write 512B
|
|
|
|
* to 4k sector.
|
|
|
|
*/
|
|
|
|
if (full_sec_size > 0) {
|
|
|
|
if (bytes < full_sec_size) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
memcpy(bouncebuf, outbuf, bytes);
|
|
|
|
(void) lseek(fd, -secsz, SEEK_CUR);
|
|
|
|
res = write(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = write(fd, outbuf, full_sec_size);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != full_sec_size) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
outbuf += full_sec_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Partial data write to last sector */
|
|
|
|
if (do_tail_write) {
|
|
|
|
res = read(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
memcpy(bouncebuf, outbuf, secsz - tail);
|
|
|
|
(void) lseek(fd, -secsz, SEEK_CUR);
|
|
|
|
res = write(fd, bouncebuf, secsz);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((unsigned)res != secsz) {
|
2020-06-20 06:23:31 +00:00
|
|
|
ret = EIO;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
error:
|
|
|
|
free(bouncebuf);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
static int
|
|
|
|
zfs_dev_init(void)
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
{
|
2012-10-06 19:40:12 +00:00
|
|
|
spa_t *spa;
|
|
|
|
spa_t *next;
|
|
|
|
spa_t *prev;
|
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
zfs_init();
|
|
|
|
if (archsw.arch_zfs_probe == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
archsw.arch_zfs_probe();
|
2012-10-06 19:40:12 +00:00
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
spa = STAILQ_FIRST(&zfs_pools);
|
|
|
|
while (spa != NULL) {
|
|
|
|
next = STAILQ_NEXT(spa, spa_link);
|
|
|
|
if (zfs_spa_init(spa)) {
|
|
|
|
if (prev == NULL)
|
|
|
|
STAILQ_REMOVE_HEAD(&zfs_pools, spa_link);
|
|
|
|
else
|
|
|
|
STAILQ_REMOVE_AFTER(&zfs_pools, prev, spa_link);
|
|
|
|
} else
|
|
|
|
prev = spa;
|
|
|
|
spa = next;
|
|
|
|
}
|
2012-05-12 09:03:30 +00:00
|
|
|
return (0);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 14:48:28 +00:00
|
|
|
struct zfs_probe_args {
|
|
|
|
int fd;
|
|
|
|
const char *devname;
|
|
|
|
uint64_t *pool_guid;
|
2016-01-11 15:35:29 +00:00
|
|
|
u_int secsz;
|
2012-08-05 14:48:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2017-02-01 20:10:56 +00:00
|
|
|
zfs_diskread(void *arg, void *buf, size_t blocks, uint64_t offset)
|
2012-08-05 14:48:28 +00:00
|
|
|
{
|
|
|
|
struct zfs_probe_args *ppa;
|
|
|
|
|
|
|
|
ppa = (struct zfs_probe_args *)arg;
|
|
|
|
return (vdev_read(NULL, (void *)(uintptr_t)ppa->fd,
|
|
|
|
offset * ppa->secsz, buf, blocks * ppa->secsz));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_probe(int fd, uint64_t *pool_guid)
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
{
|
2012-05-12 09:03:30 +00:00
|
|
|
spa_t *spa;
|
|
|
|
int ret;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
2018-08-15 21:38:06 +00:00
|
|
|
spa = NULL;
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
ret = vdev_probe(vdev_read, vdev_write, (void *)(uintptr_t)fd, &spa);
|
2012-08-05 14:48:28 +00:00
|
|
|
if (ret == 0 && pool_guid != NULL)
|
2020-09-23 08:22:14 +00:00
|
|
|
if (*pool_guid == 0)
|
|
|
|
*pool_guid = spa->spa_guid;
|
2012-08-05 14:48:28 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2016-05-18 05:59:05 +00:00
|
|
|
static int
|
2012-08-05 14:48:28 +00:00
|
|
|
zfs_probe_partition(void *arg, const char *partname,
|
|
|
|
const struct ptable_entry *part)
|
|
|
|
{
|
|
|
|
struct zfs_probe_args *ppa, pa;
|
|
|
|
struct ptable *table;
|
|
|
|
char devname[32];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Probe only freebsd-zfs and freebsd partitions */
|
|
|
|
if (part->type != PART_FREEBSD &&
|
|
|
|
part->type != PART_FREEBSD_ZFS)
|
2016-06-16 07:45:57 +00:00
|
|
|
return (0);
|
2012-08-05 14:48:28 +00:00
|
|
|
|
|
|
|
ppa = (struct zfs_probe_args *)arg;
|
|
|
|
strncpy(devname, ppa->devname, strlen(ppa->devname) - 1);
|
2012-08-15 09:18:49 +00:00
|
|
|
devname[strlen(ppa->devname) - 1] = '\0';
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
snprintf(devname, sizeof(devname), "%s%s:", devname, partname);
|
2020-06-20 06:23:31 +00:00
|
|
|
pa.fd = open(devname, O_RDWR);
|
2012-08-05 14:48:28 +00:00
|
|
|
if (pa.fd == -1)
|
2016-06-16 07:45:57 +00:00
|
|
|
return (0);
|
2012-08-05 14:48:28 +00:00
|
|
|
ret = zfs_probe(pa.fd, ppa->pool_guid);
|
|
|
|
if (ret == 0)
|
2016-06-16 07:45:57 +00:00
|
|
|
return (0);
|
2012-08-05 14:48:28 +00:00
|
|
|
/* Do we have BSD label here? */
|
|
|
|
if (part->type == PART_FREEBSD) {
|
|
|
|
pa.devname = devname;
|
|
|
|
pa.pool_guid = ppa->pool_guid;
|
|
|
|
pa.secsz = ppa->secsz;
|
|
|
|
table = ptable_open(&pa, part->end - part->start + 1,
|
|
|
|
ppa->secsz, zfs_diskread);
|
|
|
|
if (table != NULL) {
|
2016-06-16 07:45:57 +00:00
|
|
|
ptable_iterate(table, &pa, zfs_probe_partition);
|
2012-08-05 14:48:28 +00:00
|
|
|
ptable_close(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(pa.fd);
|
2016-06-16 07:45:57 +00:00
|
|
|
return (0);
|
2012-08-05 14:48:28 +00:00
|
|
|
}
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
/*
|
|
|
|
* Return bootenv nvlist from pool label.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_get_bootenv(void *vdev, nvlist_t **benvp)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
nvlist_t *benv = NULL;
|
|
|
|
vdev_t *vd;
|
|
|
|
spa_t *spa;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (spa->spa_bootenv == NULL) {
|
|
|
|
STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children,
|
|
|
|
v_childlink) {
|
|
|
|
benv = vdev_read_bootenv(vd);
|
|
|
|
|
|
|
|
if (benv != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spa->spa_bootenv = benv;
|
|
|
|
} else {
|
|
|
|
benv = spa->spa_bootenv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (benv == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
*benvp = benv;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store nvlist to pool label bootenv area. Also updates cached pointer in spa.
|
|
|
|
*/
|
2020-06-20 06:23:31 +00:00
|
|
|
int
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
zfs_set_bootenv(void *vdev, nvlist_t *benv)
|
2020-06-20 06:23:31 +00:00
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
vdev_t *vd;
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children, v_childlink) {
|
|
|
|
vdev_write_bootenv(vd, benv);
|
|
|
|
}
|
|
|
|
|
|
|
|
spa->spa_bootenv = benv;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get bootonce value by key. The bootonce <key, value> pair is removed
|
|
|
|
* from the bootenv nvlist and the remaining nvlist is committed back to disk.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zfs_get_bootonce(void *vdev, const char *key, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
nvlist_t *benv;
|
2020-06-20 06:23:31 +00:00
|
|
|
char *result = NULL;
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
int result_size, rv;
|
|
|
|
|
|
|
|
if ((rv = zfs_get_bootenv(vdev, &benv)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
if ((rv = nvlist_find(benv, key, DATA_TYPE_STRING, NULL,
|
|
|
|
&result, &result_size)) == 0) {
|
|
|
|
if (result_size == 0) {
|
|
|
|
/* ignore empty string */
|
|
|
|
rv = ENOENT;
|
|
|
|
} else {
|
|
|
|
size = MIN((size_t)result_size + 1, size);
|
|
|
|
strlcpy(buf, result, size);
|
|
|
|
}
|
|
|
|
(void) nvlist_remove(benv, key, DATA_TYPE_STRING);
|
|
|
|
(void) zfs_set_bootenv(vdev, benv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nvstore backend.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int zfs_nvstore_setter(void *, int, const char *,
|
|
|
|
const void *, size_t);
|
|
|
|
static int zfs_nvstore_setter_str(void *, const char *, const char *,
|
|
|
|
const char *);
|
|
|
|
static int zfs_nvstore_unset_impl(void *, const char *, bool);
|
|
|
|
static int zfs_nvstore_setenv(void *, void *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nvstore is only present for current rootfs pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_nvstore_sethook(struct env_var *ev, int flags __unused, const void *value)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
archsw.arch_getdev((void **)&dev, NULL, NULL);
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter_str(dev, NULL, ev->ev_name, value);
|
|
|
|
|
|
|
|
free(dev);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nvstore is only present for current rootfs pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_nvstore_unsethook(struct env_var *ev)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
archsw.arch_getdev((void **)&dev, NULL, NULL);
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
rv = zfs_nvstore_unset_impl(dev, ev->ev_name, false);
|
|
|
|
|
|
|
|
free(dev);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_nvstore_getter(void *vdev, const char *name, void **data)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
nvlist_t *nv;
|
|
|
|
char *str, **ptr;
|
|
|
|
int size;
|
|
|
|
int rv;
|
2020-06-20 06:23:31 +00:00
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
return (ENOTSUP);
|
2020-06-20 06:23:31 +00:00
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
2020-06-20 06:23:31 +00:00
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if (spa->spa_bootenv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (nvlist_find(spa->spa_bootenv, OS_NVSTORE, DATA_TYPE_NVLIST,
|
|
|
|
NULL, &nv, NULL) != 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
rv = nvlist_find(nv, name, DATA_TYPE_STRING, NULL, &str, &size);
|
|
|
|
if (rv == 0) {
|
|
|
|
ptr = (char **)data;
|
|
|
|
asprintf(ptr, "%.*s", size, str);
|
|
|
|
if (*data == NULL)
|
|
|
|
rv = ENOMEM;
|
2020-06-20 06:23:31 +00:00
|
|
|
}
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
nvlist_destroy(nv);
|
|
|
|
return (rv);
|
|
|
|
}
|
2020-06-20 06:23:31 +00:00
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
static int
|
|
|
|
zfs_nvstore_setter(void *vdev, int type, const char *name,
|
|
|
|
const void *data, size_t size)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
nvlist_t *nv;
|
|
|
|
int rv;
|
|
|
|
bool env_set = true;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (spa->spa_bootenv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (nvlist_find(spa->spa_bootenv, OS_NVSTORE, DATA_TYPE_NVLIST,
|
|
|
|
NULL, &nv, NULL) != 0) {
|
|
|
|
nv = nvlist_create(NV_UNIQUE_NAME);
|
|
|
|
if (nv == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
switch (type) {
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
if (size != sizeof (int8_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_int8(nv, name, *(int8_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
if (size != sizeof (int16_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_int16(nv, name, *(int16_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
if (size != sizeof (int32_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_int32(nv, name, *(int32_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
if (size != sizeof (int64_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_int64(nv, name, *(int64_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
if (size != sizeof (uint8_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_byte(nv, name, *(int8_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
if (size != sizeof (uint8_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_uint8(nv, name, *(int8_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
if (size != sizeof (uint16_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-06-20 06:23:31 +00:00
|
|
|
}
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
rv = nvlist_add_uint16(nv, name, *(uint16_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
if (size != sizeof (uint32_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_uint32(nv, name, *(uint32_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
if (size != sizeof (uint64_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-06-20 06:23:31 +00:00
|
|
|
}
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
rv = nvlist_add_uint64(nv, name, *(uint64_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
rv = nvlist_add_string(nv, name, data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
if (size != sizeof (boolean_t)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = nvlist_add_boolean_value(nv, name, *(boolean_t *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-06-20 06:23:31 +00:00
|
|
|
}
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if (rv == 0) {
|
|
|
|
rv = nvlist_add_nvlist(spa->spa_bootenv, OS_NVSTORE, nv);
|
|
|
|
if (rv == 0) {
|
|
|
|
rv = zfs_set_bootenv(vdev, spa->spa_bootenv);
|
|
|
|
}
|
|
|
|
if (rv == 0) {
|
|
|
|
if (env_set) {
|
|
|
|
rv = zfs_nvstore_setenv(vdev,
|
|
|
|
nvpair_find(nv, name));
|
|
|
|
} else {
|
|
|
|
env_discard(env_getenv(name));
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-06-20 06:23:31 +00:00
|
|
|
}
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
nvlist_destroy(nv);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_int64(const char *data, int64_t *ip)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
int64_t val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoll(data, &end, 0);
|
|
|
|
if (errno != 0 || *data == '\0' || *end != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
*ip = val;
|
2020-06-20 06:23:31 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
static int
|
|
|
|
get_uint64(const char *data, uint64_t *ip)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
uint64_t val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoull(data, &end, 0);
|
|
|
|
if (errno != 0 || *data == '\0' || *end != '\0')
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
*ip = val;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate textual data to data type. If type is not set, and we are
|
|
|
|
* creating new pair, use DATA_TYPE_STRING.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_nvstore_setter_str(void *vdev, const char *type, const char *name,
|
|
|
|
const char *data)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
nvlist_t *nv;
|
|
|
|
int rv;
|
|
|
|
data_type_t dt;
|
|
|
|
int64_t val;
|
|
|
|
uint64_t uval;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (spa->spa_bootenv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (nvlist_find(spa->spa_bootenv, OS_NVSTORE, DATA_TYPE_NVLIST,
|
|
|
|
NULL, &nv, NULL) != 0) {
|
|
|
|
nv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == NULL) {
|
|
|
|
nvp_header_t *nvh;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if there is no existing pair, default to string.
|
|
|
|
* Otherwise, use type from existing pair.
|
|
|
|
*/
|
|
|
|
nvh = nvpair_find(nv, name);
|
|
|
|
if (nvh == NULL) {
|
|
|
|
dt = DATA_TYPE_STRING;
|
|
|
|
} else {
|
|
|
|
nv_string_t *nvp_name;
|
|
|
|
nv_pair_data_t *nvp_data;
|
|
|
|
|
|
|
|
nvp_name = (nv_string_t *)(nvh + 1);
|
|
|
|
nvp_data = (nv_pair_data_t *)(&nvp_name->nv_data[0] +
|
|
|
|
NV_ALIGN4(nvp_name->nv_size));
|
|
|
|
dt = nvp_data->nv_type;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dt = nvpair_type_from_name(type);
|
|
|
|
}
|
|
|
|
nvlist_destroy(nv);
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
switch (dt) {
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
rv = get_int64(data, &val);
|
|
|
|
if (rv == 0) {
|
|
|
|
int8_t v = val;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
rv = get_int64(data, &val);
|
|
|
|
if (rv == 0) {
|
|
|
|
int16_t v = val;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
rv = get_int64(data, &val);
|
|
|
|
if (rv == 0) {
|
|
|
|
int32_t v = val;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
rv = get_int64(data, &val);
|
|
|
|
if (rv == 0) {
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &val,
|
|
|
|
sizeof (val));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
rv = get_uint64(data, &uval);
|
|
|
|
if (rv == 0) {
|
|
|
|
uint8_t v = uval;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
rv = get_uint64(data, &uval);
|
|
|
|
if (rv == 0) {
|
|
|
|
uint8_t v = uval;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
rv = get_uint64(data, &uval);
|
|
|
|
if (rv == 0) {
|
|
|
|
uint16_t v = uval;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
rv = get_uint64(data, &uval);
|
|
|
|
if (rv == 0) {
|
|
|
|
uint32_t v = uval;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
rv = get_uint64(data, &uval);
|
|
|
|
if (rv == 0) {
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &uval,
|
|
|
|
sizeof (uval));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, data, strlen(data) + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
rv = get_int64(data, &val);
|
|
|
|
if (rv == 0) {
|
|
|
|
boolean_t v = val;
|
|
|
|
|
|
|
|
rv = zfs_nvstore_setter(vdev, dt, name, &v, sizeof (v));
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = EINVAL;
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_nvstore_unset_impl(void *vdev, const char *name, bool unset_env)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
nvlist_t *nv;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (spa->spa_bootenv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (nvlist_find(spa->spa_bootenv, OS_NVSTORE, DATA_TYPE_NVLIST,
|
|
|
|
NULL, &nv, NULL) != 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
rv = nvlist_remove(nv, name, DATA_TYPE_UNKNOWN);
|
|
|
|
if (rv == 0) {
|
|
|
|
if (nvlist_next_nvpair(nv, NULL) == NULL) {
|
|
|
|
rv = nvlist_remove(spa->spa_bootenv, OS_NVSTORE,
|
|
|
|
DATA_TYPE_NVLIST);
|
|
|
|
} else {
|
|
|
|
rv = nvlist_add_nvlist(spa->spa_bootenv,
|
|
|
|
OS_NVSTORE, nv);
|
|
|
|
}
|
|
|
|
if (rv == 0)
|
|
|
|
rv = zfs_set_bootenv(vdev, spa->spa_bootenv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unset_env)
|
|
|
|
env_discard(env_getenv(name));
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_nvstore_unset(void *vdev, const char *name)
|
|
|
|
{
|
|
|
|
return (zfs_nvstore_unset_impl(vdev, name, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_nvstore_print(void *vdev __unused, void *ptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
nvpair_print(ptr, 0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create environment variable from nvpair.
|
|
|
|
* set hook will update nvstore with new value, unset hook will remove
|
|
|
|
* variable from nvstore.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
zfs_nvstore_setenv(void *vdev __unused, void *ptr)
|
|
|
|
{
|
|
|
|
nvp_header_t *nvh = ptr;
|
|
|
|
nv_string_t *nvp_name, *nvp_value;
|
|
|
|
nv_pair_data_t *nvp_data;
|
|
|
|
char *name, *value;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (nvh == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
nvp_name = (nv_string_t *)(nvh + 1);
|
|
|
|
nvp_data = (nv_pair_data_t *)(&nvp_name->nv_data[0] +
|
|
|
|
NV_ALIGN4(nvp_name->nv_size));
|
|
|
|
|
|
|
|
if ((name = nvstring_get(nvp_name)) == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
value = NULL;
|
|
|
|
switch (nvp_data->nv_type) {
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
(void) asprintf(&value, "%uc",
|
|
|
|
*(unsigned *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
(void) asprintf(&value, "%c", *(int *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
(void) asprintf(&value, "%hd", *(short *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
(void) asprintf(&value, "%hu",
|
|
|
|
*(unsigned short *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
(void) asprintf(&value, "%d", *(int *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
(void) asprintf(&value, "%u",
|
|
|
|
*(unsigned *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
(void) asprintf(&value, "%jd",
|
|
|
|
(intmax_t)*(int64_t *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
(void) asprintf(&value, "%ju",
|
|
|
|
(uintmax_t)*(uint64_t *)&nvp_data->nv_data[0]);
|
|
|
|
if (value == NULL)
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
nvp_value = (nv_string_t *)&nvp_data->nv_data[0];
|
|
|
|
if ((value = nvstring_get(nvp_value)) == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
rv = env_setenv(name, EV_VOLATILE | EV_NOHOOK, value,
|
|
|
|
zfs_nvstore_sethook, zfs_nvstore_unsethook);
|
|
|
|
free(value);
|
|
|
|
}
|
|
|
|
free(name);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zfs_nvstore_iterate(void *vdev, int (*cb)(void *, void *))
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
nvlist_t *nv;
|
|
|
|
nvp_header_t *nvh;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (spa->spa_bootenv == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (nvlist_find(spa->spa_bootenv, OS_NVSTORE, DATA_TYPE_NVLIST,
|
|
|
|
NULL, &nv, NULL) != 0)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
nvh = NULL;
|
|
|
|
while ((nvh = nvlist_next_nvpair(nv, nvh)) != NULL) {
|
|
|
|
rv = cb(vdev, nvh);
|
|
|
|
if (rv != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nvs_callbacks_t nvstore_zfs_cb = {
|
|
|
|
.nvs_getter = zfs_nvstore_getter,
|
|
|
|
.nvs_setter = zfs_nvstore_setter,
|
|
|
|
.nvs_setter_str = zfs_nvstore_setter_str,
|
|
|
|
.nvs_unset = zfs_nvstore_unset,
|
|
|
|
.nvs_print = zfs_nvstore_print,
|
|
|
|
.nvs_iterate = zfs_nvstore_iterate
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_attach_nvstore(void *vdev)
|
|
|
|
{
|
|
|
|
struct zfs_devdesc *dev = vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
uint64_t version;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
|
|
|
return (ENOTSUP);
|
|
|
|
|
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
rv = nvlist_find(spa->spa_bootenv, BOOTENV_VERSION, DATA_TYPE_UINT64,
|
|
|
|
NULL, &version, NULL);
|
|
|
|
|
|
|
|
if (rv != 0 || version != VB_NVLIST) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = malloc(sizeof (*dev));
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
memcpy(dev, vdev, sizeof (*dev));
|
|
|
|
|
|
|
|
rv = nvstore_init(spa->spa_name, &nvstore_zfs_cb, dev);
|
|
|
|
if (rv != 0)
|
|
|
|
free(dev);
|
|
|
|
else
|
|
|
|
rv = zfs_nvstore_iterate(dev, zfs_nvstore_setenv);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2012-08-05 14:48:28 +00:00
|
|
|
int
|
|
|
|
zfs_probe_dev(const char *devname, uint64_t *pool_guid)
|
|
|
|
{
|
|
|
|
struct ptable *table;
|
|
|
|
struct zfs_probe_args pa;
|
2017-02-06 08:26:45 +00:00
|
|
|
uint64_t mediasz;
|
2012-08-05 14:48:28 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-02-06 09:18:47 +00:00
|
|
|
if (pool_guid)
|
|
|
|
*pool_guid = 0;
|
2020-06-20 06:23:31 +00:00
|
|
|
pa.fd = open(devname, O_RDWR);
|
2012-08-05 14:48:28 +00:00
|
|
|
if (pa.fd == -1)
|
|
|
|
return (ENXIO);
|
2020-10-22 20:02:02 +00:00
|
|
|
/* Probe the whole disk */
|
|
|
|
ret = zfs_probe(pa.fd, pool_guid);
|
|
|
|
if (ret == 0)
|
|
|
|
return (0);
|
2017-02-06 09:18:47 +00:00
|
|
|
|
2012-08-05 14:48:28 +00:00
|
|
|
/* Probe each partition */
|
|
|
|
ret = ioctl(pa.fd, DIOCGMEDIASIZE, &mediasz);
|
|
|
|
if (ret == 0)
|
|
|
|
ret = ioctl(pa.fd, DIOCGSECTORSIZE, &pa.secsz);
|
|
|
|
if (ret == 0) {
|
|
|
|
pa.devname = devname;
|
|
|
|
pa.pool_guid = pool_guid;
|
|
|
|
table = ptable_open(&pa, mediasz / pa.secsz, pa.secsz,
|
|
|
|
zfs_diskread);
|
|
|
|
if (table != NULL) {
|
|
|
|
ptable_iterate(table, &pa, zfs_probe_partition);
|
|
|
|
ptable_close(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(pa.fd);
|
2017-02-06 09:18:47 +00:00
|
|
|
if (pool_guid && *pool_guid == 0)
|
|
|
|
ret = ENXIO;
|
2016-01-06 20:25:41 +00:00
|
|
|
return (ret);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print information about ZFS pools
|
|
|
|
*/
|
2016-11-08 06:50:18 +00:00
|
|
|
static int
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
zfs_dev_print(int verbose)
|
|
|
|
{
|
|
|
|
spa_t *spa;
|
|
|
|
char line[80];
|
2016-11-08 06:50:18 +00:00
|
|
|
int ret = 0;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
|
2016-11-19 08:54:21 +00:00
|
|
|
if (STAILQ_EMPTY(&zfs_pools))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
printf("%s devices:", zfs_dev.dv_name);
|
|
|
|
if ((ret = pager_output("\n")) != 0)
|
|
|
|
return (ret);
|
|
|
|
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
if (verbose) {
|
2016-11-08 06:50:18 +00:00
|
|
|
return (spa_all_status());
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
|
2016-11-08 06:50:18 +00:00
|
|
|
snprintf(line, sizeof(line), " zfs:%s\n", spa->spa_name);
|
|
|
|
ret = pager_output(line);
|
|
|
|
if (ret != 0)
|
|
|
|
break;
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
2016-11-08 06:50:18 +00:00
|
|
|
return (ret);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to open the pool described by (dev) for use by (f).
|
|
|
|
*/
|
2012-05-12 09:03:30 +00:00
|
|
|
static int
|
2012-05-12 20:27:33 +00:00
|
|
|
zfs_dev_open(struct open_file *f, ...)
|
2012-05-12 09:03:30 +00:00
|
|
|
{
|
2012-05-12 20:27:33 +00:00
|
|
|
va_list args;
|
|
|
|
struct zfs_devdesc *dev;
|
2012-05-12 09:03:30 +00:00
|
|
|
struct zfsmount *mount;
|
2012-05-12 20:27:33 +00:00
|
|
|
spa_t *spa;
|
2012-05-12 09:03:30 +00:00
|
|
|
int rv;
|
|
|
|
|
2012-05-12 20:27:33 +00:00
|
|
|
va_start(args, f);
|
|
|
|
dev = va_arg(args, struct zfs_devdesc *);
|
|
|
|
va_end(args);
|
|
|
|
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
if ((spa = spa_find_by_dev(dev)) == NULL)
|
2012-05-12 20:27:33 +00:00
|
|
|
return (ENXIO);
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
mount = malloc(sizeof(*mount));
|
2019-11-03 13:03:47 +00:00
|
|
|
if (mount == NULL)
|
2019-11-03 14:36:16 +00:00
|
|
|
rv = ENOMEM;
|
|
|
|
else
|
|
|
|
rv = zfs_mount(spa, dev->root_guid, mount);
|
2012-05-12 09:03:30 +00:00
|
|
|
if (rv != 0) {
|
|
|
|
free(mount);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
if (mount->objset.os_type != DMU_OST_ZFS) {
|
2012-05-12 20:23:30 +00:00
|
|
|
printf("Unexpected object set type %ju\n",
|
|
|
|
(uintmax_t)mount->objset.os_type);
|
2012-05-12 09:03:30 +00:00
|
|
|
free(mount);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
f->f_devdata = mount;
|
2008-12-11 16:48:35 +00:00
|
|
|
free(dev);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-10-06 19:41:11 +00:00
|
|
|
static int
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
zfs_dev_close(struct open_file *f)
|
|
|
|
{
|
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
free(f->f_devdata);
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
f->f_devdata = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-10-06 19:41:11 +00:00
|
|
|
static int
|
2016-12-30 19:06:29 +00:00
|
|
|
zfs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct devsw zfs_dev = {
|
2012-05-12 09:03:30 +00:00
|
|
|
.dv_name = "zfs",
|
|
|
|
.dv_type = DEVT_ZFS,
|
|
|
|
.dv_init = zfs_dev_init,
|
|
|
|
.dv_strategy = zfs_dev_strategy,
|
|
|
|
.dv_open = zfs_dev_open,
|
|
|
|
.dv_close = zfs_dev_close,
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
.dv_ioctl = noioctl,
|
|
|
|
.dv_print = zfs_dev_print,
|
|
|
|
.dv_cleanup = NULL
|
|
|
|
};
|
2012-05-12 09:03:30 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
zfs_parsedev(struct zfs_devdesc *dev, const char *devspec, const char **path)
|
|
|
|
{
|
|
|
|
static char rootname[ZFS_MAXNAMELEN];
|
|
|
|
static char poolname[ZFS_MAXNAMELEN];
|
|
|
|
spa_t *spa;
|
|
|
|
const char *end;
|
|
|
|
const char *np;
|
|
|
|
const char *sep;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
np = devspec;
|
|
|
|
if (*np != ':')
|
|
|
|
return (EINVAL);
|
|
|
|
np++;
|
2018-07-02 20:56:17 +00:00
|
|
|
end = strrchr(np, ':');
|
2012-05-12 09:03:30 +00:00
|
|
|
if (end == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
sep = strchr(np, '/');
|
|
|
|
if (sep == NULL || sep >= end)
|
|
|
|
sep = end;
|
|
|
|
memcpy(poolname, np, sep - np);
|
|
|
|
poolname[sep - np] = '\0';
|
|
|
|
if (sep < end) {
|
|
|
|
sep++;
|
|
|
|
memcpy(rootname, sep, end - sep);
|
|
|
|
rootname[end - sep] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rootname[0] = '\0';
|
|
|
|
|
|
|
|
spa = spa_find_by_name(poolname);
|
|
|
|
if (!spa)
|
|
|
|
return (ENXIO);
|
|
|
|
dev->pool_guid = spa->spa_guid;
|
2012-10-06 19:42:50 +00:00
|
|
|
rv = zfs_lookup_dataset(spa, rootname, &dev->root_guid);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
2012-05-12 09:03:30 +00:00
|
|
|
if (path != NULL)
|
|
|
|
*path = (*end == '\0') ? end : end + 1;
|
2018-03-12 21:39:49 +00:00
|
|
|
dev->dd.d_dev = &zfs_dev;
|
2012-05-12 09:03:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
zfs_fmtdev(void *vdev)
|
|
|
|
{
|
|
|
|
static char rootname[ZFS_MAXNAMELEN];
|
|
|
|
static char buf[2 * ZFS_MAXNAMELEN + 8];
|
|
|
|
struct zfs_devdesc *dev = (struct zfs_devdesc *)vdev;
|
|
|
|
spa_t *spa;
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
2018-03-12 21:39:59 +00:00
|
|
|
if (dev->dd.d_dev->dv_type != DEVT_ZFS)
|
2012-05-12 09:03:30 +00:00
|
|
|
return (buf);
|
|
|
|
|
2019-10-19 08:08:06 +00:00
|
|
|
/* Do we have any pools? */
|
|
|
|
spa = STAILQ_FIRST(&zfs_pools);
|
|
|
|
if (spa == NULL)
|
|
|
|
return (buf);
|
|
|
|
|
|
|
|
if (dev->pool_guid == 0)
|
2012-10-06 19:42:50 +00:00
|
|
|
dev->pool_guid = spa->spa_guid;
|
2019-10-19 08:08:06 +00:00
|
|
|
else
|
2012-10-06 19:25:40 +00:00
|
|
|
spa = spa_find_by_guid(dev->pool_guid);
|
2019-10-19 08:08:06 +00:00
|
|
|
|
2012-05-12 09:03:30 +00:00
|
|
|
if (spa == NULL) {
|
|
|
|
printf("ZFS: can't find pool by guid\n");
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
if (dev->root_guid == 0 && zfs_get_root(spa, &dev->root_guid)) {
|
|
|
|
printf("ZFS: can't find root filesystem\n");
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
if (zfs_rlookup(spa, dev->root_guid, rootname)) {
|
|
|
|
printf("ZFS: can't find filesystem by guid\n");
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootname[0] == '\0')
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s:%s:", dev->dd.d_dev->dv_name,
|
|
|
|
spa->spa_name);
|
2012-05-12 09:03:30 +00:00
|
|
|
else
|
loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.
By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.
By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.
bootonce dataset name is recorded in boot pool labels, bootenv area.
in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.
bootonce and nextboot features are usable in both UEFI and BIOS boot.
To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).
At this time, only lua loader is updated.
Sponsored by: Netflix, Klara Inc.
Differential Revision: https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s:%s/%s:", dev->dd.d_dev->dv_name,
|
|
|
|
spa->spa_name, rootname);
|
2012-05-12 09:03:30 +00:00
|
|
|
return (buf);
|
|
|
|
}
|
2012-10-06 19:27:04 +00:00
|
|
|
|
2020-08-18 19:48:04 +00:00
|
|
|
static int
|
|
|
|
split_devname(const char *name, char *poolname, size_t size,
|
|
|
|
const char **dsnamep)
|
2012-10-06 19:27:04 +00:00
|
|
|
{
|
2020-08-18 19:48:04 +00:00
|
|
|
const char *dsname;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
ASSERT(name != NULL);
|
|
|
|
ASSERT(poolname != NULL);
|
2012-10-06 19:27:04 +00:00
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
dsname = strchr(name, '/');
|
|
|
|
if (dsname != NULL) {
|
|
|
|
len = dsname - name;
|
|
|
|
dsname++;
|
2012-10-06 19:42:50 +00:00
|
|
|
} else
|
|
|
|
dsname = "";
|
2020-08-18 19:48:04 +00:00
|
|
|
|
|
|
|
if (len + 1 > size)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
strlcpy(poolname, name, len + 1);
|
|
|
|
|
|
|
|
if (dsnamep != NULL)
|
|
|
|
*dsnamep = dsname;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_list(const char *name)
|
|
|
|
{
|
|
|
|
static char poolname[ZFS_MAXNAMELEN];
|
|
|
|
uint64_t objid;
|
|
|
|
spa_t *spa;
|
|
|
|
const char *dsname;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (split_devname(name, poolname, sizeof(poolname), &dsname) != 0)
|
|
|
|
return (EINVAL);
|
2012-10-06 19:27:04 +00:00
|
|
|
|
|
|
|
spa = spa_find_by_name(poolname);
|
|
|
|
if (!spa)
|
|
|
|
return (ENXIO);
|
2012-10-06 19:42:50 +00:00
|
|
|
rv = zfs_lookup_dataset(spa, dsname, &objid);
|
2012-10-06 19:27:04 +00:00
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
2015-12-31 20:00:53 +00:00
|
|
|
|
|
|
|
return (zfs_list_dataset(spa, objid));
|
|
|
|
}
|
|
|
|
|
2016-01-15 05:45:10 +00:00
|
|
|
void
|
2020-08-18 19:48:04 +00:00
|
|
|
init_zfs_boot_options(const char *currdev_in)
|
2016-01-15 05:45:10 +00:00
|
|
|
{
|
2020-08-18 19:48:04 +00:00
|
|
|
char poolname[ZFS_MAXNAMELEN];
|
2018-02-21 16:26:16 +00:00
|
|
|
char *beroot, *currdev;
|
2020-08-18 19:48:04 +00:00
|
|
|
spa_t *spa;
|
2018-02-21 16:26:16 +00:00
|
|
|
int currdev_len;
|
2020-08-18 19:48:04 +00:00
|
|
|
const char *dsname;
|
2016-01-15 05:45:10 +00:00
|
|
|
|
2018-02-21 16:26:16 +00:00
|
|
|
currdev = NULL;
|
|
|
|
currdev_len = strlen(currdev_in);
|
|
|
|
if (currdev_len == 0)
|
|
|
|
return;
|
|
|
|
if (strncmp(currdev_in, "zfs:", 4) != 0)
|
2016-01-15 05:45:10 +00:00
|
|
|
return;
|
2018-02-21 16:26:16 +00:00
|
|
|
currdev = strdup(currdev_in);
|
|
|
|
if (currdev == NULL)
|
2016-01-15 05:45:10 +00:00
|
|
|
return;
|
|
|
|
/* Remove the trailing : */
|
2018-02-21 16:26:16 +00:00
|
|
|
currdev[currdev_len - 1] = '\0';
|
2020-08-18 19:48:04 +00:00
|
|
|
|
2016-01-15 05:45:10 +00:00
|
|
|
setenv("zfs_be_active", currdev, 1);
|
|
|
|
setenv("zfs_be_currpage", "1", 1);
|
|
|
|
/* Remove the last element (current bootenv) */
|
|
|
|
beroot = strrchr(currdev, '/');
|
|
|
|
if (beroot != NULL)
|
|
|
|
beroot[0] = '\0';
|
2018-02-21 16:26:16 +00:00
|
|
|
beroot = strchr(currdev, ':') + 1;
|
2016-01-15 05:45:10 +00:00
|
|
|
setenv("zfs_be_root", beroot, 1);
|
2020-08-18 19:48:04 +00:00
|
|
|
|
|
|
|
if (split_devname(beroot, poolname, sizeof(poolname), &dsname) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
spa = spa_find_by_name(poolname);
|
|
|
|
if (spa == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
zfs_bootenv_initial("bootenvs", spa, beroot, dsname, 0);
|
|
|
|
zfs_checkpoints_initial(spa, beroot, dsname);
|
|
|
|
|
2018-02-21 16:26:16 +00:00
|
|
|
free(currdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-08-18 19:48:04 +00:00
|
|
|
zfs_checkpoints_initial(spa_t *spa, const char *name, const char *dsname)
|
2018-02-21 16:26:16 +00:00
|
|
|
{
|
2020-08-18 19:48:04 +00:00
|
|
|
char envname[32];
|
|
|
|
|
|
|
|
if (spa->spa_uberblock_checkpoint.ub_checkpoint_txg != 0) {
|
|
|
|
snprintf(envname, sizeof(envname), "zpool_checkpoint");
|
|
|
|
setenv(envname, name, 1);
|
|
|
|
|
|
|
|
spa->spa_uberblock = &spa->spa_uberblock_checkpoint;
|
|
|
|
spa->spa_mos = &spa->spa_mos_checkpoint;
|
|
|
|
|
|
|
|
zfs_bootenv_initial("bootenvs_check", spa, name, dsname, 1);
|
|
|
|
|
|
|
|
spa->spa_uberblock = &spa->spa_uberblock_master;
|
|
|
|
spa->spa_mos = &spa->spa_mos_master;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zfs_bootenv_initial(const char *envprefix, spa_t *spa, const char *rootname,
|
|
|
|
const char *dsname, int checkpoint)
|
|
|
|
{
|
|
|
|
char envname[32], envval[256];
|
2018-02-21 16:26:16 +00:00
|
|
|
uint64_t objid;
|
2020-08-18 19:48:04 +00:00
|
|
|
int bootenvs_idx, rv;
|
2018-02-21 16:26:16 +00:00
|
|
|
|
|
|
|
SLIST_INIT(&zfs_be_head);
|
|
|
|
zfs_env_count = 0;
|
2020-08-18 19:48:04 +00:00
|
|
|
|
2018-02-21 16:26:16 +00:00
|
|
|
rv = zfs_lookup_dataset(spa, dsname, &objid);
|
|
|
|
if (rv != 0)
|
|
|
|
return;
|
2020-08-18 19:48:04 +00:00
|
|
|
|
2018-02-21 16:26:16 +00:00
|
|
|
rv = zfs_callback_dataset(spa, objid, zfs_belist_add);
|
|
|
|
bootenvs_idx = 0;
|
|
|
|
/* Populate the initial environment variables */
|
|
|
|
SLIST_FOREACH_SAFE(zfs_be, &zfs_be_head, entries, zfs_be_tmp) {
|
|
|
|
/* Enumerate all bootenvs for general usage */
|
2020-08-18 19:48:04 +00:00
|
|
|
snprintf(envname, sizeof(envname), "%s[%d]",
|
|
|
|
envprefix, bootenvs_idx);
|
|
|
|
snprintf(envval, sizeof(envval), "zfs:%s%s/%s",
|
|
|
|
checkpoint ? "!" : "", rootname, zfs_be->name);
|
2018-02-21 16:26:16 +00:00
|
|
|
rv = setenv(envname, envval, 1);
|
|
|
|
if (rv != 0)
|
|
|
|
break;
|
|
|
|
bootenvs_idx++;
|
|
|
|
}
|
2020-08-18 19:48:04 +00:00
|
|
|
snprintf(envname, sizeof(envname), "%s_count", envprefix);
|
2018-02-21 16:26:16 +00:00
|
|
|
snprintf(envval, sizeof(envval), "%d", bootenvs_idx);
|
2020-08-18 19:48:04 +00:00
|
|
|
setenv(envname, envval, 1);
|
2018-02-21 16:26:16 +00:00
|
|
|
|
|
|
|
/* Clean up the SLIST of ZFS BEs */
|
|
|
|
while (!SLIST_EMPTY(&zfs_be_head)) {
|
|
|
|
zfs_be = SLIST_FIRST(&zfs_be_head);
|
|
|
|
SLIST_REMOVE_HEAD(&zfs_be_head, entries);
|
2020-03-28 21:50:27 +00:00
|
|
|
free(zfs_be->name);
|
2018-02-21 16:26:16 +00:00
|
|
|
free(zfs_be);
|
|
|
|
}
|
2016-01-15 05:45:10 +00:00
|
|
|
}
|
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
int
|
|
|
|
zfs_bootenv(const char *name)
|
|
|
|
{
|
2020-08-18 19:48:04 +00:00
|
|
|
char poolname[ZFS_MAXNAMELEN], *root;
|
|
|
|
const char *dsname;
|
2015-12-31 20:00:53 +00:00
|
|
|
char becount[4];
|
|
|
|
uint64_t objid;
|
|
|
|
spa_t *spa;
|
2020-08-18 19:48:04 +00:00
|
|
|
int rv, pages, perpage, currpage;
|
2015-12-31 20:00:53 +00:00
|
|
|
|
2016-01-09 00:54:08 +00:00
|
|
|
if (name == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
if ((root = getenv("zfs_be_root")) == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (strcmp(name, root) != 0) {
|
2015-12-31 20:00:53 +00:00
|
|
|
if (setenv("zfs_be_root", name, 1) != 0)
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST_INIT(&zfs_be_head);
|
|
|
|
zfs_env_count = 0;
|
2020-08-18 19:48:04 +00:00
|
|
|
|
|
|
|
if (split_devname(name, poolname, sizeof(poolname), &dsname) != 0)
|
|
|
|
return (EINVAL);
|
2015-12-31 20:00:53 +00:00
|
|
|
|
|
|
|
spa = spa_find_by_name(poolname);
|
|
|
|
if (!spa)
|
|
|
|
return (ENXIO);
|
|
|
|
rv = zfs_lookup_dataset(spa, dsname, &objid);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
rv = zfs_callback_dataset(spa, objid, zfs_belist_add);
|
|
|
|
|
|
|
|
/* Calculate and store the number of pages of BEs */
|
|
|
|
perpage = (ZFS_BE_LAST - ZFS_BE_FIRST + 1);
|
|
|
|
pages = (zfs_env_count / perpage) + ((zfs_env_count % perpage) > 0 ? 1 : 0);
|
|
|
|
snprintf(becount, 4, "%d", pages);
|
|
|
|
if (setenv("zfs_be_pages", becount, 1) != 0)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
/* Roll over the page counter if it has exceeded the maximum */
|
|
|
|
currpage = strtol(getenv("zfs_be_currpage"), NULL, 10);
|
|
|
|
if (currpage > pages) {
|
|
|
|
if (setenv("zfs_be_currpage", "1", 1) != 0)
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Populate the menu environment variables */
|
|
|
|
zfs_set_env();
|
|
|
|
|
|
|
|
/* Clean up the SLIST of ZFS BEs */
|
|
|
|
while (!SLIST_EMPTY(&zfs_be_head)) {
|
|
|
|
zfs_be = SLIST_FIRST(&zfs_be_head);
|
|
|
|
SLIST_REMOVE_HEAD(&zfs_be_head, entries);
|
2020-03-28 21:50:27 +00:00
|
|
|
free(zfs_be->name);
|
2015-12-31 20:00:53 +00:00
|
|
|
free(zfs_be);
|
|
|
|
}
|
|
|
|
|
2012-10-06 19:42:50 +00:00
|
|
|
return (rv);
|
2012-10-06 19:27:04 +00:00
|
|
|
}
|
2015-12-31 20:00:53 +00:00
|
|
|
|
|
|
|
int
|
2016-08-01 19:37:43 +00:00
|
|
|
zfs_belist_add(const char *name, uint64_t value __unused)
|
2015-12-31 20:00:53 +00:00
|
|
|
{
|
|
|
|
|
2016-01-15 05:45:10 +00:00
|
|
|
/* Skip special datasets that start with a $ character */
|
|
|
|
if (strncmp(name, "$", 1) == 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
2015-12-31 20:00:53 +00:00
|
|
|
/* Add the boot environment to the head of the SLIST */
|
|
|
|
zfs_be = malloc(sizeof(struct zfs_be_entry));
|
2016-01-15 05:45:10 +00:00
|
|
|
if (zfs_be == NULL) {
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2020-03-28 21:50:27 +00:00
|
|
|
zfs_be->name = strdup(name);
|
|
|
|
if (zfs_be->name == NULL) {
|
|
|
|
free(zfs_be);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2015-12-31 20:00:53 +00:00
|
|
|
SLIST_INSERT_HEAD(&zfs_be_head, zfs_be, entries);
|
|
|
|
zfs_env_count++;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zfs_set_env(void)
|
|
|
|
{
|
|
|
|
char envname[32], envval[256];
|
|
|
|
char *beroot, *pagenum;
|
|
|
|
int rv, page, ctr;
|
|
|
|
|
|
|
|
beroot = getenv("zfs_be_root");
|
|
|
|
if (beroot == NULL) {
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pagenum = getenv("zfs_be_currpage");
|
|
|
|
if (pagenum != NULL) {
|
|
|
|
page = strtol(pagenum, NULL, 10);
|
|
|
|
} else {
|
|
|
|
page = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctr = 1;
|
|
|
|
rv = 0;
|
|
|
|
zfs_env_index = ZFS_BE_FIRST;
|
|
|
|
SLIST_FOREACH_SAFE(zfs_be, &zfs_be_head, entries, zfs_be_tmp) {
|
|
|
|
/* Skip to the requested page number */
|
|
|
|
if (ctr <= ((ZFS_BE_LAST - ZFS_BE_FIRST + 1) * (page - 1))) {
|
|
|
|
ctr++;
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-18 19:48:04 +00:00
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
snprintf(envname, sizeof(envname), "bootenvmenu_caption[%d]", zfs_env_index);
|
|
|
|
snprintf(envval, sizeof(envval), "%s", zfs_be->name);
|
|
|
|
rv = setenv(envname, envval, 1);
|
|
|
|
if (rv != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(envname, sizeof(envname), "bootenvansi_caption[%d]", zfs_env_index);
|
|
|
|
rv = setenv(envname, envval, 1);
|
|
|
|
if (rv != 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(envname, sizeof(envname), "bootenvmenu_command[%d]", zfs_env_index);
|
|
|
|
rv = setenv(envname, "set_bootenv", 1);
|
|
|
|
if (rv != 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(envname, sizeof(envname), "bootenv_root[%d]", zfs_env_index);
|
|
|
|
snprintf(envval, sizeof(envval), "zfs:%s/%s", beroot, zfs_be->name);
|
|
|
|
rv = setenv(envname, envval, 1);
|
|
|
|
if (rv != 0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_env_index++;
|
|
|
|
if (zfs_env_index > ZFS_BE_LAST) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 19:48:04 +00:00
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
for (; zfs_env_index <= ZFS_BE_LAST; zfs_env_index++) {
|
|
|
|
snprintf(envname, sizeof(envname), "bootenvmenu_caption[%d]", zfs_env_index);
|
|
|
|
(void)unsetenv(envname);
|
|
|
|
snprintf(envname, sizeof(envname), "bootenvansi_caption[%d]", zfs_env_index);
|
|
|
|
(void)unsetenv(envname);
|
|
|
|
snprintf(envname, sizeof(envname), "bootenvmenu_command[%d]", zfs_env_index);
|
|
|
|
(void)unsetenv(envname);
|
|
|
|
snprintf(envname, sizeof(envname), "bootenv_root[%d]", zfs_env_index);
|
|
|
|
(void)unsetenv(envname);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
2016-05-18 05:59:05 +00:00
|
|
|
}
|