Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split "shared" userspace & kernel code into separate files #16492

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/sys/zfs_znode.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ extern "C" {
#define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48)

extern int zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len);
extern int zfs_obj_to_pobj(objset_t *osp, sa_handle_t *hdl,
sa_attr_type_t *sa_table, uint64_t *pobjp, int *is_xattrdir);
extern int zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value);

#ifdef _KERNEL
Expand Down
13 changes: 6 additions & 7 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ CPPCHECKTARGETS += libzpool.la

dist_libzpool_la_SOURCES = \
%D%/abd_os.c \
%D%/arc_os.c \
%D%/kernel.c \
%D%/taskq.c \
%D%/util.c
%D%/util.c \
%D%/vdev_label_os.c \
%D%/zfs_racct.c \
%D%/zfs_debug.c

nodist_libzpool_la_SOURCES = \
module/lua/lapi.c \
Expand Down Expand Up @@ -42,13 +46,7 @@ nodist_libzpool_la_SOURCES = \
module/lua/lvm.c \
module/lua/lzio.c \
\
module/os/linux/zfs/arc_os.c \
module/os/linux/zfs/trace.c \
module/os/linux/zfs/vdev_file.c \
module/os/linux/zfs/vdev_label_os.c \
module/os/linux/zfs/zfs_debug.c \
module/os/linux/zfs/zfs_racct.c \
module/os/linux/zfs/zfs_znode.c \
module/os/linux/zfs/zio_crypt.c \
\
module/zcommon/cityhash.c \
Expand Down Expand Up @@ -184,6 +182,7 @@ nodist_libzpool_la_SOURCES = \
module/zfs/zfs_ratelimit.c \
module/zfs/zfs_rlock.c \
module/zfs/zfs_sa.c \
module/zfs/zfs_znode.c \
module/zfs/zil.c \
module/zfs/zio.c \
module/zfs/zio_checksum.c \
Expand Down
87 changes: 87 additions & 0 deletions lib/libzpool/arc_os.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, Joyent, Inc.
* Copyright (c) 2011, 2019 by Delphix. All rights reserved.
* Copyright (c) 2014 by Saso Kiselkov. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/

#include <sys/zfs_context.h>
#include <sys/arc_impl.h>

/*
* Return a default max arc size based on the amount of physical memory.
* This may be overridden by tuning the zfs_arc_max module parameter.
*/
uint64_t
arc_default_max(uint64_t min, uint64_t allmem)
{
uint64_t size;

if (allmem >= 1 << 30)
size = allmem - (1 << 30);
else
size = min;
return (MAX(allmem * 5 / 8, size));
}

int64_t
arc_available_memory(void)
{
int64_t lowest = INT64_MAX;

/* Every 100 calls, free a small amount */
if (random_in_range(100) == 0)
lowest = -1024;

return (lowest);
}

int
arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg)
{
(void) spa, (void) reserve, (void) txg;
return (0);
}

uint64_t
arc_all_memory(void)
{
return (ptob(physmem) / 2);
}

uint64_t
arc_free_memory(void)
{
return (random_in_range(arc_all_memory() * 20 / 100));
}

void
arc_register_hotplug(void)
{
}

void
arc_unregister_hotplug(void)
{
}
51 changes: 51 additions & 0 deletions lib/libzpool/vdev_label_os.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2023 by iXsystems, Inc.
*/

#include <sys/zfs_context.h>
#include <sys/spa.h>
#include <sys/spa_impl.h>
#include <sys/vdev.h>
#include <sys/vdev_impl.h>

/*
* Check if the reserved boot area is in-use. This is called from
* spa_vdev_attach() when adding a device to a raidz vdev, to ensure that the
* reserved area is available as scratch space for raidz expansion.
*
* This function currently always returns 0. On Linux, there are no known
* external uses of the reserved area. On FreeBSD, the reserved boot area is
* used when booting to a ZFS root from an MBR partition.
*
* Currently nothing using libzpool can add a disk to a pool, so this does
* nothing.
*/
int
vdev_check_boot_reserve(spa_t *spa, vdev_t *childvd)
{
(void) spa;
(void) childvd;

return (0);
}
106 changes: 106 additions & 0 deletions lib/libzpool/zfs_debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
* Copyright (c) 2024, Rob Norris <[email protected]>
*/

#include <sys/zfs_context.h>

typedef struct zfs_dbgmsg {
list_node_t zdm_node;
uint64_t zdm_timestamp;
uint_t zdm_size;
char zdm_msg[]; /* variable length allocation */
} zfs_dbgmsg_t;

static list_t zfs_dbgmsgs;
static kmutex_t zfs_dbgmsgs_lock;

int zfs_dbgmsg_enable = B_TRUE;

void
zfs_dbgmsg_init(void)
{
list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
offsetof(zfs_dbgmsg_t, zdm_node));
mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
}

void
zfs_dbgmsg_fini(void)
{
zfs_dbgmsg_t *zdm;
while ((zdm = list_remove_head(&zfs_dbgmsgs)))
umem_free(zdm, zdm->zdm_size);
mutex_destroy(&zfs_dbgmsgs_lock);
}

void
__set_error(const char *file, const char *func, int line, int err)
{
if (zfs_flags & ZFS_DEBUG_SET_ERROR)
__dprintf(B_FALSE, file, func, line, "error %lu",
(ulong_t)err);
}

void
__zfs_dbgmsg(char *buf)
{
uint_t size = sizeof (zfs_dbgmsg_t) + strlen(buf) + 1;
zfs_dbgmsg_t *zdm = umem_zalloc(size, KM_SLEEP);
zdm->zdm_size = size;
zdm->zdm_timestamp = gethrestime_sec();
strcpy(zdm->zdm_msg, buf);

mutex_enter(&zfs_dbgmsgs_lock);
list_insert_tail(&zfs_dbgmsgs, zdm);
mutex_exit(&zfs_dbgmsgs_lock);
}

void
zfs_dbgmsg_print(int fd, const char *tag)
{
ssize_t ret __attribute__((unused));

mutex_enter(&zfs_dbgmsgs_lock);

/*
* We use write() in this function instead of printf()
* so it is safe to call from a signal handler.
*/
ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(fd, tag, strlen(tag));
ret = write(fd, ") START:\n", 9);

for (zfs_dbgmsg_t *zdm = list_head(&zfs_dbgmsgs); zdm != NULL;
zdm = list_next(&zfs_dbgmsgs, zdm)) {
ret = write(fd, zdm->zdm_msg, strlen(zdm->zdm_msg));
ret = write(fd, "\n", 1);
}

ret = write(fd, "ZFS_DBGMSG(", 11);
ret = write(fd, tag, strlen(tag));
ret = write(fd, ") END\n", 6);

mutex_exit(&zfs_dbgmsgs_lock);
}
38 changes: 38 additions & 0 deletions lib/libzpool/zfs_racct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021 iXsystems, Inc.
*
* 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 AUTHORS 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 AUTHORS 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.
*/

#include <sys/zfs_racct.h>

void
zfs_racct_read(spa_t *spa, uint64_t size, uint64_t iops, uint32_t flags)
{
(void) spa, (void) size, (void) iops, (void) flags;
}

void
zfs_racct_write(spa_t *spa, uint64_t size, uint64_t iops, uint32_t flags)
{
(void) spa, (void) size, (void) iops, (void) flags;
}
3 changes: 2 additions & 1 deletion module/Kbuild.in
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ ZFS_OBJS := \
zfs_rlock.o \
zfs_sa.o \
zfs_vnops.o \
zfs_znode.o \
zil.o \
zio.o \
zio_checksum.o \
Expand Down Expand Up @@ -458,7 +459,7 @@ ZFS_OBJS_OS := \
zfs_uio.o \
zfs_vfsops.o \
zfs_vnops_os.o \
zfs_znode.o \
zfs_znode_os.o \
zio_crypt.o \
zpl_ctldir.o \
zpl_export.o \
Expand Down
3 changes: 2 additions & 1 deletion module/Makefile.bsd
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ SRCS+= abd_os.c \
zfs_racct.c \
zfs_vfsops.c \
zfs_vnops_os.c \
zfs_znode.c \
zfs_znode_os.c \
zio_crypt.c \
zvol_os.c

Expand Down Expand Up @@ -358,6 +358,7 @@ SRCS+= abd.c \
zfs_rlock.c \
zfs_sa.c \
zfs_vnops.c \
zfs_znode.c \
zil.c \
zio.c \
zio_checksum.c \
Expand Down
Loading
Loading