diff options
author | Robert Mustacchi <rm@joyent.com> | 2014-06-10 05:45:07 +0000 |
---|---|---|
committer | Andy Fiddaman <omnios@citrus-it.co.uk> | 2021-11-06 14:59:12 +0000 |
commit | 01aad2697e36a09a93fa18833b39bcc0486de567 (patch) | |
tree | b87045e9fcb6393272aaf61e8663e79e04213f6b /usr/src | |
parent | 1e8d79d21400b4e47d64ce367181e7e5ce992649 (diff) | |
download | illumos-gate-01aad2697e36a09a93fa18833b39bcc0486de567.tar.gz |
14197 Implement id_space as a library
Reviewed by: Yuri Pankov <ypankov@tintri.com>
Reviewed by: Andy Fiddaman <andy@omnios.org>
Approved by: Rich Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/common/idspace/id_space.c (renamed from usr/src/uts/common/os/id_space.c) | 35 | ||||
-rw-r--r-- | usr/src/lib/Makefile | 3 | ||||
-rw-r--r-- | usr/src/lib/libidspace/Makefile | 44 | ||||
-rw-r--r-- | usr/src/lib/libidspace/Makefile.com | 37 | ||||
-rw-r--r-- | usr/src/lib/libidspace/amd64/Makefile | 19 | ||||
-rw-r--r-- | usr/src/lib/libidspace/common/libidspace.c | 25 | ||||
-rw-r--r-- | usr/src/lib/libidspace/common/libidspace.h | 42 | ||||
-rw-r--r-- | usr/src/lib/libidspace/common/mapfile-vers | 43 | ||||
-rw-r--r-- | usr/src/lib/libidspace/i386/Makefile | 18 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-library.mf | 2 | ||||
-rw-r--r-- | usr/src/uts/common/Makefile.rules | 6 | ||||
-rw-r--r-- | usr/src/uts/common/sys/id_space.h | 5 |
12 files changed, 269 insertions, 10 deletions
diff --git a/usr/src/uts/common/os/id_space.c b/usr/src/common/idspace/id_space.c index 2dad0cb940..7d28a8f533 100644 --- a/usr/src/uts/common/os/id_space.c +++ b/usr/src/common/idspace/id_space.c @@ -53,6 +53,10 @@ * reservation, in which an ID is allocated but placed in a internal * dictionary for later use, should be added when a consuming subsystem * arrives.) + * + * This code is also shared with userland. In userland, we don't have the same + * ability to have sleeping variants, so we effectively turn the normal + * versions without _nosleep into _nosleep. */ #define ID_TO_ADDR(id) ((void *)(uintptr_t)(id + 1)) @@ -60,16 +64,22 @@ /* * Create an arena to represent the range [low, high). - * Caller must be in a context in which VM_SLEEP is legal. + * Caller must be in a context in which VM_SLEEP is legal, + * for the kernel. Always VM_NOSLEEP in userland. */ id_space_t * id_space_create(const char *name, id_t low, id_t high) { +#ifdef _KERNEL + int flag = VM_SLEEP; +#else + int flag = VM_NOSLEEP; +#endif ASSERT(low >= 0); ASSERT(low < high); return (vmem_create(name, ID_TO_ADDR(low), high - low, 1, - NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER)); + NULL, NULL, NULL, 0, flag | VMC_IDENTIFIER)); } /* @@ -85,7 +95,12 @@ id_space_destroy(id_space_t *isp) void id_space_extend(id_space_t *isp, id_t low, id_t high) { - (void) vmem_add(isp, ID_TO_ADDR(low), high - low, VM_SLEEP); +#ifdef _KERNEL + int flag = VM_SLEEP; +#else + int flag = VM_NOSLEEP; +#endif + (void) vmem_add(isp, ID_TO_ADDR(low), high - low, flag); } /* @@ -95,7 +110,12 @@ id_space_extend(id_space_t *isp, id_t low, id_t high) id_t id_alloc(id_space_t *isp) { - return (ADDR_TO_ID(vmem_alloc(isp, 1, VM_SLEEP | VM_NEXTFIT))); +#ifdef _KERNEL + int flag = VM_SLEEP; +#else + int flag = VM_NOSLEEP; +#endif + return (ADDR_TO_ID(vmem_alloc(isp, 1, flag | VM_NEXTFIT))); } /* @@ -116,7 +136,12 @@ id_alloc_nosleep(id_space_t *isp) id_t id_allocff(id_space_t *isp) { - return (ADDR_TO_ID(vmem_alloc(isp, 1, VM_SLEEP | VM_FIRSTFIT))); +#ifdef _KERNEL + int flag = VM_SLEEP; +#else + int flag = VM_NOSLEEP; +#endif + return (ADDR_TO_ID(vmem_alloc(isp, 1, flag | VM_FIRSTFIT))); } /* diff --git a/usr/src/lib/Makefile b/usr/src/lib/Makefile index 5fb3375db8..f1e6b21158 100644 --- a/usr/src/lib/Makefile +++ b/usr/src/lib/Makefile @@ -140,6 +140,7 @@ SUBDIRS += \ libgss \ libhotplug \ libidmap \ + libidspace \ libilb \ libima \ libinetsvc \ @@ -403,6 +404,7 @@ HDRSUBDIRS= \ libgen \ libgrubmgmt \ libidmap \ + libidspace \ libilb \ libima \ libinetsvc \ @@ -625,6 +627,7 @@ libfsmgt: libkstat libgrubmgmt: libdevinfo libzfs libfstyp libefi $(INTEL_BLD)libgrubmgmt: libfdisk libidmap: libavl libuutil +libidspace: libumem libinetsvc: libscf libinetutil: libsocket libinstzones: libzonecfg libcontract diff --git a/usr/src/lib/libidspace/Makefile b/usr/src/lib/libidspace/Makefile new file mode 100644 index 0000000000..feeca43d3a --- /dev/null +++ b/usr/src/lib/libidspace/Makefile @@ -0,0 +1,44 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014 Joyent, Inc. All rights reserved. +# + +include ../Makefile.lib + +HDRS = libidspace.h +HDRDIR = common + +SUBDIRS = $(MACH) +$(BUILD64)SUBDIRS += $(MACH64) + +all := TARGET = all +clean := TARGET = clean +clobber := TARGET = clobber +install := TARGET = install + +.KEEP_STATE: + +all clean clobber install: $(SUBDIRS) + +install: install_h $(SUBDIRS) + +install_h: $(ROOTHDRS) + +check: $(CHECKHDRS) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: + +include ../Makefile.targ diff --git a/usr/src/lib/libidspace/Makefile.com b/usr/src/lib/libidspace/Makefile.com new file mode 100644 index 0000000000..b7314fc37b --- /dev/null +++ b/usr/src/lib/libidspace/Makefile.com @@ -0,0 +1,37 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2020 Joyent, Inc. +# + +LIBRARY = libidspace.a +VERS = .1 +OBJECTS = id_space.o \ + libidspace.o +COMDIR = $(SRC)/common/idspace + +include ../../Makefile.lib + +SRCDIR = ../common +LIBS = $(DYNLIB) + +LDLIBS += -lumem + +.KEEP_STATE: + +all: $(LIBS) + +include ../../Makefile.targ + +objs/%.o pics/%.o: $(COMDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) diff --git a/usr/src/lib/libidspace/amd64/Makefile b/usr/src/lib/libidspace/amd64/Makefile new file mode 100644 index 0000000000..e03ee6aac6 --- /dev/null +++ b/usr/src/lib/libidspace/amd64/Makefile @@ -0,0 +1,19 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014 Joyent, Inc. All rights reserved. +# + +include ../Makefile.com +include ../../Makefile.lib.64 + +install: all $(ROOTLIBS64) $(ROOTLINKS64) diff --git a/usr/src/lib/libidspace/common/libidspace.c b/usr/src/lib/libidspace/common/libidspace.c new file mode 100644 index 0000000000..7a9f8acd67 --- /dev/null +++ b/usr/src/lib/libidspace/common/libidspace.c @@ -0,0 +1,25 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2014, Joyent, Inc. + */ + +/* + * Wrappers around the common id_space code, for userland. + */ +#include <sys/id_space.h> + +id_t +id_alloc_specific(id_space_t *idp, id_t id) +{ + return (id_alloc_specific_nosleep(idp, id)); +} diff --git a/usr/src/lib/libidspace/common/libidspace.h b/usr/src/lib/libidspace/common/libidspace.h new file mode 100644 index 0000000000..bb8690f19c --- /dev/null +++ b/usr/src/lib/libidspace/common/libidspace.h @@ -0,0 +1,42 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2014 Joyent, Inc. All rights reserved. + */ + +#ifndef _LIBIDSPACE_H +#define _LIBIDSPACE_H + +/* + * libidspace public header + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/types.h> + +typedef struct id_space id_space_t; + +extern id_space_t *id_space_create(const char *, id_t, id_t); +extern void id_space_destroy(id_space_t *); +extern void id_space_extend(id_space_t *, id_t, id_t); +extern id_t id_alloc(id_space_t *); +extern id_t id_alloc_specific(id_space_t *, id_t); +extern void id_free(id_space_t *, id_t); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBIDSPACE_H */ diff --git a/usr/src/lib/libidspace/common/mapfile-vers b/usr/src/lib/libidspace/common/mapfile-vers new file mode 100644 index 0000000000..a536d2490d --- /dev/null +++ b/usr/src/lib/libidspace/common/mapfile-vers @@ -0,0 +1,43 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014 Joyent, Inc. All rights reserved. +# + +# +# MAPFILE HEADER START +# +# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. +# Object versioning must comply with the rules detailed in +# +# usr/src/lib/README.mapfiles +# +# You should not be making modifications here until you've read the most current +# copy of that file. If you need help, contact a gatekeeper for guidance. +# +# MAPFILE HEADER END +# + +$mapfile_version 2 + +SYMBOL_VERSION ILLUMOSprivate { + global: + id_alloc; + id_alloc_specific; + id_free; + id_space_create; + id_space_destroy; + id_space_extend; + local: + *; +}; + diff --git a/usr/src/lib/libidspace/i386/Makefile b/usr/src/lib/libidspace/i386/Makefile new file mode 100644 index 0000000000..73fc6a2070 --- /dev/null +++ b/usr/src/lib/libidspace/i386/Makefile @@ -0,0 +1,18 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014 Joyent, Inc. All rights reserved. +# + +include ../Makefile.com + +install: all $(ROOTLIBS) $(ROOTLINKS) diff --git a/usr/src/pkg/manifests/system-library.mf b/usr/src/pkg/manifests/system-library.mf index d7abc4228b..4c50a4dd9c 100644 --- a/usr/src/pkg/manifests/system-library.mf +++ b/usr/src/pkg/manifests/system-library.mf @@ -357,6 +357,7 @@ file path=usr/lib/$(ARCH64)/libform.so.1 file path=usr/lib/$(ARCH64)/libfstyp.so.1 file path=usr/lib/$(ARCH64)/libhotplug.so.1 file path=usr/lib/$(ARCH64)/libidmap.so.1 +file path=usr/lib/$(ARCH64)/libidspace.so.1 file path=usr/lib/$(ARCH64)/libike.so.1 file path=usr/lib/$(ARCH64)/libipmi.so.1 file path=usr/lib/$(ARCH64)/libipp.so.1 @@ -430,6 +431,7 @@ file path=usr/lib/libform.so.1 file path=usr/lib/libfstyp.so.1 file path=usr/lib/libhotplug.so.1 file path=usr/lib/libidmap.so.1 +file path=usr/lib/libidspace.so.1 file path=usr/lib/libike.so.1 file path=usr/lib/libinetsvc.so.1 file path=usr/lib/libipmi.so.1 diff --git a/usr/src/uts/common/Makefile.rules b/usr/src/uts/common/Makefile.rules index 4e3221ac23..6bbede41f4 100644 --- a/usr/src/uts/common/Makefile.rules +++ b/usr/src/uts/common/Makefile.rules @@ -1503,6 +1503,11 @@ $(OBJS_DIR)/%.o: $(UTSBASE)/common/io/vioblk/%.c $(OBJS_DIR)/%.o: $(UTSBASE)/common/io/vioif/%.c $(COMPILE.c) -o $@ $< $(CTFCONVERT_O) + +$(OBJS_DIR)/%.o: $(COMMONBASE)/idspace/%.c + $(COMPILE.c) -o $@ $< + $(CTFCONVERT_O) + # # krtld must refer to its own bzero/bcopy until the kernel is fully linked # @@ -1657,4 +1662,3 @@ $(OBJS_DIR)/%.o: $(UTSBASE)/common/io/tpm/%.s $(OBJS_DIR)/bz2%.o: $(COMMONBASE)/bzip2/%.c $(COMPILE.c) -o $@ -I$(COMMONBASE)/bzip2 $< $(CTFCONVERT_O) - diff --git a/usr/src/uts/common/sys/id_space.h b/usr/src/uts/common/sys/id_space.h index d56fcceb5a..46d25f207f 100644 --- a/usr/src/uts/common/sys/id_space.h +++ b/usr/src/uts/common/sys/id_space.h @@ -20,6 +20,7 @@ */ /* * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, Joyent, Inc. All Rights reserved. */ #ifndef _ID_SPACE_H @@ -34,8 +35,6 @@ extern "C" { #include <sys/mutex.h> #include <sys/vmem.h> -#ifdef _KERNEL - typedef vmem_t id_space_t; id_space_t *id_space_create(const char *, id_t, id_t); @@ -48,8 +47,6 @@ id_t id_allocff_nosleep(id_space_t *); id_t id_alloc_specific_nosleep(id_space_t *, id_t); void id_free(id_space_t *, id_t); -#endif /* _KERNEL */ - #ifdef __cplusplus } #endif |