Skip to content

Commit

Permalink
git subrepo pull --force sys/contrib/subrepo-openzfs
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "sys/contrib/subrepo-openzfs"
  merged:   "fb4d45df99fa"
upstream:
  origin:   "https://github.com/CTSRD-CHERI/zfs.git"
  branch:   "cheri-hybrid"
  commit:   "fb4d45df99fa"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
  • Loading branch information
bsdjhb committed Mar 15, 2024
1 parent 179fd0a commit 0a0f7f5
Show file tree
Hide file tree
Showing 42 changed files with 811 additions and 122 deletions.
4 changes: 2 additions & 2 deletions sys/contrib/subrepo-openzfs/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/CTSRD-CHERI/zfs.git
branch = cheri-hybrid
commit = 64e6835be758b36ef129a1ee548a501e93a27dd0
parent = b421b291504ade31a8ab0e240af5ca04af401e47
commit = fb4d45df99faf34df8c8d4afd25441e71ef0e4e2
parent = 179fd0a21cd2ae87e75dc0b4f00b00bf9c6ab0f9
method = merge
cmdver = 0.4.3
104 changes: 68 additions & 36 deletions sys/contrib/subrepo-openzfs/cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ static void
snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen,
const blkptr_t *bp)
{
abd_t *pabd;
static abd_t *pabd = NULL;
void *buf;
zio_t *zio;
zfs_zstdhdr_t zstd_hdr;
Expand Down Expand Up @@ -2391,7 +2391,8 @@ snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen,
return;
}

pabd = abd_alloc_for_io(SPA_MAXBLOCKSIZE, B_FALSE);
if (!pabd)
pabd = abd_alloc_for_io(SPA_MAXBLOCKSIZE, B_FALSE);
zio = zio_root(spa, NULL, NULL, 0);

/* Decrypt but don't decompress so we can read the compression header */
Expand Down Expand Up @@ -8487,11 +8488,45 @@ zdb_parse_block_sizes(char *sizes, uint64_t *lsize, uint64_t *psize)
#define ZIO_COMPRESS_MASK(alg) (1ULL << (ZIO_COMPRESS_##alg))

static boolean_t
try_decompress_block(abd_t *pabd, uint64_t lsize, uint64_t psize,
int flags, int cfunc, void *lbuf, void *lbuf2)
{
if (flags & ZDB_FLAG_VERBOSE) {
(void) fprintf(stderr,
"Trying %05llx -> %05llx (%s)\n",
(u_longlong_t)psize,
(u_longlong_t)lsize,
zio_compress_table[cfunc].ci_name);
}

/*
* We set lbuf to all zeros and lbuf2 to all
* ones, then decompress to both buffers and
* compare their contents. This way we can
* know if decompression filled exactly to
* lsize or if it left some bytes unwritten.
*/

memset(lbuf, 0x00, lsize);
memset(lbuf2, 0xff, lsize);

if (zio_decompress_data(cfunc, pabd,
lbuf, psize, lsize, NULL) == 0 &&
zio_decompress_data(cfunc, pabd,
lbuf2, psize, lsize, NULL) == 0 &&
memcmp(lbuf, lbuf2, lsize) == 0)
return (B_TRUE);
return (B_FALSE);
}

static uint64_t
zdb_decompress_block(abd_t *pabd, void *buf, void *lbuf, uint64_t lsize,
uint64_t psize, int flags)
{
(void) buf;
boolean_t exceeded = B_FALSE;
uint64_t orig_lsize = lsize;
boolean_t tryzle = ((getenv("ZDB_NO_ZLE") == NULL));
boolean_t found = B_FALSE;
/*
* We don't know how the data was compressed, so just try
* every decompress function at every inflated blocksize.
Expand All @@ -8502,10 +8537,18 @@ zdb_decompress_block(abd_t *pabd, void *buf, void *lbuf, uint64_t lsize,
uint64_t maxlsize = SPA_MAXBLOCKSIZE;
uint64_t mask = ZIO_COMPRESS_MASK(ON) | ZIO_COMPRESS_MASK(OFF) |
ZIO_COMPRESS_MASK(INHERIT) | ZIO_COMPRESS_MASK(EMPTY) |
(getenv("ZDB_NO_ZLE") ? ZIO_COMPRESS_MASK(ZLE) : 0);
ZIO_COMPRESS_MASK(ZLE);
*cfuncp++ = ZIO_COMPRESS_LZ4;
*cfuncp++ = ZIO_COMPRESS_LZJB;
mask |= ZIO_COMPRESS_MASK(LZ4) | ZIO_COMPRESS_MASK(LZJB);
/*
* Every gzip level has the same decompressor, no need to
* run it 9 times per bruteforce attempt.
*/
mask |= ZIO_COMPRESS_MASK(GZIP_2) | ZIO_COMPRESS_MASK(GZIP_3);
mask |= ZIO_COMPRESS_MASK(GZIP_4) | ZIO_COMPRESS_MASK(GZIP_5);
mask |= ZIO_COMPRESS_MASK(GZIP_6) | ZIO_COMPRESS_MASK(GZIP_7);
mask |= ZIO_COMPRESS_MASK(GZIP_8) | ZIO_COMPRESS_MASK(GZIP_9);
for (int c = 0; c < ZIO_COMPRESS_FUNCTIONS; c++)
if (((1ULL << c) & mask) == 0)
*cfuncp++ = c;
Expand All @@ -8521,49 +8564,38 @@ zdb_decompress_block(abd_t *pabd, void *buf, void *lbuf, uint64_t lsize,
lsize += SPA_MINBLOCKSIZE;
else
maxlsize = lsize;

for (; lsize <= maxlsize; lsize += SPA_MINBLOCKSIZE) {
for (cfuncp = cfuncs; *cfuncp; cfuncp++) {
if (flags & ZDB_FLAG_VERBOSE) {
(void) fprintf(stderr,
"Trying %05llx -> %05llx (%s)\n",
(u_longlong_t)psize,
(u_longlong_t)lsize,
zio_compress_table[*cfuncp].\
ci_name);
}

/*
* We set lbuf to all zeros and lbuf2 to all
* ones, then decompress to both buffers and
* compare their contents. This way we can
* know if decompression filled exactly to
* lsize or if it left some bytes unwritten.
*/
memset(lbuf, 0x00, lsize);
memset(lbuf2, 0xff, lsize);

if (zio_decompress_data(*cfuncp, pabd,
lbuf, psize, lsize, NULL) == 0 &&
zio_decompress_data(*cfuncp, pabd,
lbuf2, psize, lsize, NULL) == 0 &&
memcmp(lbuf, lbuf2, lsize) == 0)
if (try_decompress_block(pabd, lsize, psize, flags,
*cfuncp, lbuf, lbuf2)) {
found = B_TRUE;
break;
}
}
if (*cfuncp != 0)
break;
}
if (!found && tryzle) {
for (lsize = orig_lsize; lsize <= maxlsize;
lsize += SPA_MINBLOCKSIZE) {
if (try_decompress_block(pabd, lsize, psize, flags,
ZIO_COMPRESS_ZLE, lbuf, lbuf2)) {
*cfuncp = ZIO_COMPRESS_ZLE;
found = B_TRUE;
break;
}
}
}
umem_free(lbuf2, SPA_MAXBLOCKSIZE);

if (lsize > maxlsize) {
exceeded = B_TRUE;
}
if (*cfuncp == ZIO_COMPRESS_ZLE) {
printf("\nZLE decompression was selected. If you "
"suspect the results are wrong,\ntry avoiding ZLE "
"by setting and exporting ZDB_NO_ZLE=\"true\"\n");
}

return (exceeded);
return (lsize > maxlsize ? -1 : lsize);
}

/*
Expand Down Expand Up @@ -8742,9 +8774,9 @@ zdb_read_block(char *thing, spa_t *spa)
uint64_t orig_lsize = lsize;
buf = lbuf;
if (flags & ZDB_FLAG_DECOMPRESS) {
boolean_t failed = zdb_decompress_block(pabd, buf, lbuf,
lsize = zdb_decompress_block(pabd, buf, lbuf,
lsize, psize, flags);
if (failed) {
if (lsize == -1) {
(void) printf("Decompress of %s failed\n", thing);
goto out;
}
Expand All @@ -8765,11 +8797,11 @@ zdb_read_block(char *thing, spa_t *spa)
abd_return_buf_copy(pabd, buf, lsize);
borrowed = B_FALSE;
buf = lbuf;
boolean_t failed = zdb_decompress_block(pabd, buf,
lsize = zdb_decompress_block(pabd, buf,
lbuf, lsize, psize, flags);
b = (const blkptr_t *)(void *)
((uintptr_t)buf + (uintptr_t)blkptr_offset);
if (failed || zfs_blkptr_verify(spa, b,
if (lsize == -1 || zfs_blkptr_verify(spa, b,
BLK_CONFIG_NEEDED, BLK_VERIFY_LOG) == B_FALSE) {
printf("invalid block pointer at this DVA\n");
goto out;
Expand Down
3 changes: 2 additions & 1 deletion sys/contrib/subrepo-openzfs/cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7234,7 +7234,8 @@ share_mount(int op, int argc, char **argv)
pthread_mutex_init(&share_mount_state.sm_lock, NULL);

/* For a 'zfs share -a' operation start with a clean slate. */
zfs_truncate_shares(NULL);
if (op == OP_SHARE)
zfs_truncate_shares(NULL);

/*
* libshare isn't mt-safe, so only do the operation in parallel
Expand Down
10 changes: 10 additions & 0 deletions sys/contrib/subrepo-openzfs/config/rpm.am
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ srpm-common:
rpm-local || exit 1; \
LANG=C $(RPMBUILD) \
--define "_tmppath $$rpmbuild/TMP" \
--define "_builddir $$rpmbuild/BUILD" \
--define "_rpmdir $$rpmbuild/RPMS" \
--define "_srcrpmdir $$rpmbuild/SRPMS" \
--define "_specdir $$rpmbuild/SPECS" \
--define "_sourcedir $$rpmbuild/SOURCES" \
--define "_topdir $$rpmbuild" \
$(def) -bs $$rpmbuild/SPECS/$$rpmspec || exit 1; \
cp $$rpmbuild/SRPMS/$$rpmpkg . || exit 1; \
Expand All @@ -99,6 +104,11 @@ rpm-common:
rpm-local || exit 1; \
LANG=C ${RPMBUILD} \
--define "_tmppath $$rpmbuild/TMP" \
--define "_builddir $$rpmbuild/BUILD" \
--define "_rpmdir $$rpmbuild/RPMS" \
--define "_srcrpmdir $$rpmbuild/SRPMS" \
--define "_specdir $$rpmbuild/SPECS" \
--define "_sourcedir $$rpmbuild/SOURCES" \
--define "_topdir $$rpmbuild" \
$(def) --rebuild $$rpmpkg || exit 1; \
cp $$rpmbuild/RPMS/*/* . || exit 1; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum symfollow { NO_FOLLOW = NOFOLLOW };
#include <sys/syscallsubr.h>
#include <sys/vm.h>
#include <vm/vm_object.h>
#include <vm/vnode_pager.h>

typedef struct vop_vector vnodeops_t;
#define VOP_FID VOP_VPTOFH
Expand Down Expand Up @@ -100,11 +101,11 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync)
#else
if (vp->v_object->flags & OBJ_MIGHTBEDIRTY) {
#endif
int flags = sync ? OBJPC_SYNC : 0;
vn_lock(vp, LK_SHARED | LK_RETRY);
zfs_vmobject_wlock(vp->v_object);
vm_object_page_clean(vp->v_object, 0, 0, flags);
zfs_vmobject_wunlock(vp->v_object);
if (sync)
vnode_pager_clean_sync(vp);
else
vnode_pager_clean_async(vp);
VOP_UNLOCK1(vp);
}
}
Expand Down
1 change: 1 addition & 0 deletions sys/contrib/subrepo-openzfs/include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ struct spa {

spa_aux_vdev_t spa_spares; /* hot spares */
spa_aux_vdev_t spa_l2cache; /* L2ARC cache devices */
boolean_t spa_aux_sync_uber; /* need to sync aux uber */
nvlist_t *spa_label_features; /* Features for reading MOS */
uint64_t spa_config_object; /* MOS object for pool config */
uint64_t spa_config_generation; /* config generation number */
Expand Down
4 changes: 1 addition & 3 deletions sys/contrib/subrepo-openzfs/lib/libzfs/libzfs_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,

*inuse = B_FALSE;

if (zpool_read_label(fd, &config, NULL) != 0) {
(void) no_memory(hdl);
if (zpool_read_label(fd, &config, NULL) != 0)
return (-1);
}

if (config == NULL)
return (0);
Expand Down
32 changes: 28 additions & 4 deletions sys/contrib/subrepo-openzfs/lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,21 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
case EINVAL:
break;
case EINPROGRESS:
// This shouldn't be possible to
// encounter, die if we do.
/*
* This shouldn't be possible to
* encounter, die if we do.
*/
ASSERT(B_FALSE);
zfs_fallthrough;
case EREMOTEIO:
/*
* May be returned by an NVMe device
* which is visible in /dev/ but due
* to a low-level format change, or
* other error, needs to be rescanned.
* Try the slow method.
*/
zfs_fallthrough;
case EOPNOTSUPP:
case ENOSYS:
do_slow = B_TRUE;
Expand Down Expand Up @@ -1210,13 +1221,26 @@ label_paths(libpc_handle_t *hdl, nvlist_t *label, const char **path,
nvlist_t *nvroot;
uint64_t pool_guid;
uint64_t vdev_guid;
uint64_t state;

*path = NULL;
*devid = NULL;
if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &vdev_guid) != 0)
return (ENOENT);

/*
* In case of spare or l2cache, we directly return path/devid from the
* label.
*/
if (!(nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state)) &&
(state == POOL_STATE_SPARE || state == POOL_STATE_L2CACHE)) {
(void) nvlist_lookup_string(label, ZPOOL_CONFIG_PATH, path);
(void) nvlist_lookup_string(label, ZPOOL_CONFIG_DEVID, devid);
return (0);
}

if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvroot) ||
nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_GUID, &pool_guid) ||
nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &vdev_guid))
nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_GUID, &pool_guid))
return (ENOENT);

return (label_paths_impl(hdl, nvroot, pool_guid, vdev_guid, path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License along
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
*
* Solaris Porting Layer (SPL) Credential Implementation.
* Solaris Porting Layer (SPL) Condition Variables Implementation.
*/

#include <sys/condvar.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ MODULE_PARM_DESC(spl_kmem_cache_max_size, "Maximum size of slab in MB");
* of 16K was determined to be optimal for architectures using 4K pages and
* to also work well on architecutres using larger 64K page sizes.
*/
static unsigned int spl_kmem_cache_slab_limit = 16384;
static unsigned int spl_kmem_cache_slab_limit =
SPL_MAX_KMEM_ORDER_NR_PAGES * PAGE_SIZE;
module_param(spl_kmem_cache_slab_limit, uint, 0644);
MODULE_PARM_DESC(spl_kmem_cache_slab_limit,
"Objects less than N bytes use the Linux slab");
Expand Down Expand Up @@ -783,7 +784,7 @@ spl_kmem_cache_create(const char *name, size_t size, size_t align,
} else {
unsigned long slabflags = 0;

if (size > (SPL_MAX_KMEM_ORDER_NR_PAGES * PAGE_SIZE))
if (size > spl_kmem_cache_slab_limit)
goto out;

#if defined(SLAB_USERCOPY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)
{
struct inode *ip;
zfsvfs_t *zfsvfs = ZTOZSB(zp);
objset_t *os = zfsvfs->z_os;
objset_t *os;
zilog_t *zilog;
dmu_tx_t *tx;
vattr_t oldva;
Expand Down Expand Up @@ -1888,6 +1888,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)
if ((err = zfs_enter_verify_zp(zfsvfs, zp, FTAG)) != 0)
return (err);
ip = ZTOI(zp);
os = zfsvfs->z_os;

/*
* If this is a xvattr_t, then get a pointer to the structure of
Expand Down Expand Up @@ -2438,9 +2439,8 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr, zidmap_t *mnt_ns)

if ((mask & ATTR_ATIME) || zp->z_atime_dirty) {
zp->z_atime_dirty = B_FALSE;
inode_timespec_t tmp_atime;
inode_timespec_t tmp_atime = zpl_inode_get_atime(ip);
ZFS_TIME_ENCODE(&tmp_atime, atime);
zpl_inode_set_atime_to_ts(ZTOI(zp), tmp_atime);
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
&atime, sizeof (atime));
}
Expand Down
Loading

0 comments on commit 0a0f7f5

Please sign in to comment.