dlmgmt_db.c revision 6ba597c56d749c61b4f783157f63196d7b2445f0
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * CDDL HEADER START
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * The contents of this file are subject to the terms of the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Common Development and Distribution License (the "License").
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * You may not use this file except in compliance with the License.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * See the License for the specific language governing permissions
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * and limitations under the License.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * When distributing Covered Code, include this CDDL HEADER in each
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * If applicable, add the following below this CDDL HEADER, with the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * fields enclosed by brackets "[]" replaced with your own identifying
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * information: Portions Copyright [yyyy] [name of copyright owner]
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * CDDL HEADER END
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Use is subject to license terms.
d62bc4badc1c1f1549c961cfb8b420e650e1272byztypedef enum dlmgmt_db_op {
d62bc4badc1c1f1549c961cfb8b420e650e1272byztypedef struct dlmgmt_db_req_s {
d62bc4badc1c1f1549c961cfb8b420e650e1272byz /* DLMGMT_PERSIST, not both. */
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * List of pending db updates (e.g., because of a read-only filesystem).
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * rewrite_needed is set to B_TRUE by process_link_line() if it encounters a
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * line with an old format. This will cause the file being read to be
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * re-written with the current format.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roystatic int dlmgmt_db_update(dlmgmt_db_op_t, const char *,
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic int dlmgmt_process_db_onereq(dlmgmt_db_req_t *, boolean_t);
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic void *dlmgmt_db_update_thread(void *);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roystatic boolean_t process_link_line(char *, dlmgmt_link_t *);
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic int process_db_write(dlmgmt_db_req_t *, FILE *, FILE *);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roystatic int process_db_read(dlmgmt_db_req_t *, FILE *);
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic void generate_link_line(dlmgmt_link_t *, boolean_t, char *);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#define BUFLEN(lim, ptr) (((lim) > (ptr)) ? ((lim) - (ptr)) : 0)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Translator functions to go from dladm_datatype_t to character strings.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Each function takes a pointer to a buffer, the size of the buffer,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * the name of the attribute, and the value to be written. The functions
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * return the number of bytes written to the buffer. If the buffer is not big
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * enough to hold the string representing the value, then nothing is written
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * and 0 is returned.
d62bc4badc1c1f1549c961cfb8b420e650e1272byztypedef size_t write_func_t(char *, size_t, char *, void *);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Translator functions to read from a NULL terminated string buffer into
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * something of the given DLADM_TYPE_*. The functions each return the number
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * of bytes read from the string buffer. If there is an error reading data
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * from the buffer, then 0 is returned. It is the caller's responsibility
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * to free the data allocated by these functions.
d62bc4badc1c1f1549c961cfb8b420e650e1272byztypedef struct translator_s {
d62bc4badc1c1f1549c961cfb8b420e650e1272byz const char *type_name;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Translator functions, defined later but declared here so that
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * the translator table can be defined.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic write_func_t write_str, write_boolean, write_uint64;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Translator table, indexed by dladm_datatype_t.
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic size_t ntranslators = sizeof (translators) / sizeof (translator_t);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#define BASE_PROPERTY_LENGTH(t, n) (strlen(translators[(t)].type_name) +\
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#define GENERATE_PROPERTY_STRING(buf, length, conv, name, type, val) \
d62bc4badc1c1f1549c961cfb8b420e650e1272byz (snprintf((buf), (length), "%s=%s%s" conv "%s", (name), \
d62bc4badc1c1f1549c961cfb8b420e650e1272byz LINK_PROPERTY_TYPE_VALUE_SEP, (val), LINK_PROPERTY_DELIMINATOR))
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Name of the cache file to keep the active <link name, linkid> mapping
d62bc4badc1c1f1549c961cfb8b420e650e1272byz#define DLMGMT_PERSISTENT_DB_PATH "/etc/dladm/datalink.conf"
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roytypedef struct zopen_arg {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roytypedef struct zrename_arg {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roytypedef union zfoparg {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roytypedef struct zfcbarg {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy boolean_t zfarg_inglobalzone; /* is callback in global zone? */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy zoneid_t zfarg_finglobalzone; /* is file in global zone? */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy#define zfarg_openarg zfarg_oparg->zfop_openarg
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy#define zfarg_renamearg zfarg_oparg->zfop_renamearg
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy/* zone file callback */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Execute an operation on filename relative to zoneid's zone root. If the
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * file is in the global zone, then the zfcb() callback will simply be called
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * directly. If the file is in a non-global zone, then zfcb() will be called
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * both from the global zone's context, and from the non-global zone's context
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * (from a fork()'ed child that has entered the non-global zone). This is
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * done to allow the callback to communicate with itself if needed (e.g. to
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * pass back the file descriptor of an opened file).
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_zfop(const char *filename, zoneid_t zoneid, zfcb_t *zfcb,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * We need to access a file that isn't in the global zone.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Accessing non-global zone files from the global zone is
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * unsafe (due to symlink attacks), we'll need to fork a child
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * that enters the zone in question and executes the callback
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * that will operate on the file.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Before we proceed with this zone tango, we need to create a
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * new process contract for the child, as required by
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * zone_enter().
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy ctfd = open64("/system/contract/process/template", O_RDWR);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((err = ct_tmpl_set_critical(ctfd, 0)) != 0 ||
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (err = ct_tmpl_set_informative(ctfd, 0)) != 0 ||
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (err = ct_pr_tmpl_set_fatal(ctfd, CT_PR_EV_HWERR)) != 0 ||
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (err = ct_pr_tmpl_set_param(ctfd, CT_PR_PGRPONLY)) != 0 ||
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Elevate our privileges as zone_enter() requires all
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * privileges.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (waitid(P_PID, childpid, &info, WEXITED) == -1)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy zfarg.zfarg_inglobalzone = (zoneid == GLOBAL_ZONEID || childpid != 0);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy zfarg.zfarg_finglobalzone = (zoneid == GLOBAL_ZONEID);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy boolean_t inglobalzone = zfarg->zfarg_inglobalzone;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy zoneid_t finglobalzone = zfarg->zfarg_finglobalzone;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy const char *modestr = zfarg->zfarg_openarg.zopen_modestr;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy /* We only ever open a file for reading or writing, not both. */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy oflags = (modestr[0] == 'r') ? O_RDONLY : O_WRONLY | O_CREAT | O_TRUNC;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy mode = (modestr[0] == 'r') ? 0 : S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy /* Open the file if we're in the same zone as the file. */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * First determine if we will be creating the file as part of
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * opening it. If so, then we'll need to ensure that it has
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the proper ownership after having opened it.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((fd = open(filename, oflags, mode)) == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (chown(filename, UID_DLADM, GID_NETADM) == -1) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * If we're not in the global zone, send the file-descriptor back to
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * our parent in the global zone.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy return (ioctl(p[1], I_SENDFD, fd) == -1 ? errno : 0);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * At this point, we know we're in the global zone. If the file was
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * in a non-global zone, receive the file-descriptor from our child in
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the non-global zone.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (zfarg->zfarg_inglobalzone != zfarg->zfarg_finglobalzone)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy return (unlink(zfarg->zfarg_filename) == 0 ? 0 : errno);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (zfarg->zfarg_inglobalzone != zfarg->zfarg_finglobalzone)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy zfarg->zfarg_renamearg.zrename_newname) == 0 ? 0 : errno);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Same as fopen(3C), except that it opens the file relative to zoneid's zone
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_zfopen(const char *filename, const char *modestr, zoneid_t zoneid,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (zoneid != GLOBAL_ZONEID && pipe(p) == -1) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy *err = dlmgmt_zfop(filename, zoneid, dlmgmt_zopen_cb, &zfoparg);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) close(p[0]);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (*err == 0) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy fp = fdopen(zfoparg.zfop_openarg.zopen_fd, modestr);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Same as rename(2), except that old and new are relative to zoneid's zone
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_zrename(const char *old, const char *new, zoneid_t zoneid)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy return (dlmgmt_zfop(old, zoneid, dlmgmt_zrename_cb, &zfoparg));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Same as unlink(2), except that filename is relative to zoneid's zone root.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_zunlink(const char *filename, zoneid_t zoneid)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy return (dlmgmt_zfop(filename, zoneid, dlmgmt_zunlink_cb, NULL));
d62bc4badc1c1f1549c961cfb8b420e650e1272byzwrite_str(char *buffer, size_t buffer_length, char *name, void *value)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Strings are assumed to be NULL terminated. In order to fit in
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * the buffer, the string's length must be less then buffer_length.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * If the value is empty, there's no point in writing it, in fact,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * we shouldn't even see that case.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if (data_length + BASE_PROPERTY_LENGTH(DLADM_TYPE_STR, name) ==
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Since we know the string will fit in the buffer, snprintf will
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * always return less than buffer_length, so we can just return
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * whatever snprintf returns.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (GENERATE_PROPERTY_STRING(buffer, buffer_length, "%s",
d62bc4badc1c1f1549c961cfb8b420e650e1272byzwrite_boolean(char *buffer, size_t buffer_length, char *name, void *value)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Booleans are either zero or one, so we only need room for two
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * characters in the buffer.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if (buffer_length <= 1 + BASE_PROPERTY_LENGTH(DLADM_TYPE_BOOLEAN, name))
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (GENERATE_PROPERTY_STRING(buffer, buffer_length, "%d",
d62bc4badc1c1f1549c961cfb8b420e650e1272byzwrite_uint64(char *buffer, size_t buffer_length, char *name, void *value)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Limit checking for uint64_t is a little trickier.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz BASE_PROPERTY_LENGTH(DLADM_TYPE_UINT64, name) >= buffer_length)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (GENERATE_PROPERTY_STRING(buffer, buffer_length, "%lld",
024b0a258461f282a92b1b1283c3b8b083f9f33fseb if (ptr == NULL || (len = strlcpy(ptr, buffer, MAXLINKATTRVALLEN))
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz /* Account for NULL terminator */
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (sizeof (boolean_t));
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (sizeof (int64_t));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_db_req_alloc(dlmgmt_db_op_t op, const char *linkname,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy datalink_id_t linkid, zoneid_t zoneid, uint32_t flags, int *err)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((req = calloc(1, sizeof (dlmgmt_db_req_t))) == NULL) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) strlcpy(req->ls_link, linkname, MAXLINKNAMELEN);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Update the db entry with name "entryname" using information from "linkp".
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_db_update(dlmgmt_db_op_t op, const char *entryname, dlmgmt_link_t *linkp,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy /* It is either a persistent request or an active request, not both. */
d62bc4badc1c1f1549c961cfb8b420e650e1272byz assert((flags == DLMGMT_PERSIST) || (flags == DLMGMT_ACTIVE));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((req = dlmgmt_db_req_alloc(op, entryname, linkp->ll_linkid,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * If the return error is EINPROGRESS, this request is handled
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * asynchronously; return success.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * If there are already pending "write" requests, queue this request in
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * the pending list. Note that this function is called while the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * dlmgmt_rw_lock is held, so it is safe to access the global variables.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (err != EINPROGRESS && err != 0 && err != ENOENT) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Log the error unless the request processing is still in
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * progress or if the configuration file hasn't been created
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * yet (ENOENT).
d62bc4badc1c1f1549c961cfb8b420e650e1272byz "operation on %s configuration failed: %s",
d62bc4badc1c1f1549c961cfb8b420e650e1272byz err = pthread_create(&tid, NULL, dlmgmt_db_update_thread, NULL);
d62bc4badc1c1f1549c961cfb8b420e650e1272byzdlmgmt_process_db_onereq(dlmgmt_db_req_t *req, boolean_t writeop)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz DLMGMT_MAKE_FILE_DB_PATH(file, (req->ls_flags == DLMGMT_PERSIST));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy fp = dlmgmt_zfopen(file, "r", req->ls_zoneid, &err);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Note that it is not an error if the file doesn't exist. If we're
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * reading, we treat this case the same way as an empty file. If
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * we're writing, the file will be created when we open the file for
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * writing below.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy nfp = dlmgmt_zfopen(newfile, "w", req->ls_zoneid, &err);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * EROFS can happen at boot when the file system is
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * read-only. Return EINPROGRESS so that the caller
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * can add this request to the pending request list
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * and start a retry thread.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((err = process_db_write(req, fp, nfp)) == 0)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy err = dlmgmt_zrename(newfile, file, req->ls_zoneid);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) dlmgmt_zunlink(newfile, req->ls_zoneid);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz/*ARGSUSED*/
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic void *
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (dlmgmt_process_db_onereq(req, B_TRUE) == EINPROGRESS) {
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * The filesystem is still read only. Go to sleep and
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * try again.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * The filesystem is no longer read only. Continue processing
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * and remove the request from the pending list.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz char c = buf[i];
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Move to the next character if there is no match and
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * if we have not reached the last character.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * NUL-terminate the string pointed to by 'curr'.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * We get here after we have processed the "<prop>="
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * pattern. The pattern we are now interested in is
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * "<val>;".
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if (c == '=')
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Non-zero length attr_name and found_type of false
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * indicates that we have not found the type for this
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * attribute. The pattern now is "<type>,<val>;", we
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * want the <type> part of the pattern.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * A zero length attr_name indicates we are looking
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * at the beginning of a link attribute.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if (c != '=')
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (-1);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Royprocess_link_line(char *buf, dlmgmt_link_t *linkp)
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Use a copy of buf for parsing so that we can do whatever we want.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Skip leading spaces, blank lines, and comments.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz for (i = 0; i < len; i++) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Find the link name and assign it to the link structure.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Note that a previous version of the persistent datalink.conf file
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * stored the linkid as the first field. In that case, the name will
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * be obtained through parse_linkprops from a property with the format
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * "name=<linkname>". If we encounter such a format, we set
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * rewrite_needed so that dlmgmt_db_init() can rewrite the file with
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the new format after it's done reading in the data.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (strlcpy(linkp->ll_link, str, sizeof (linkp->ll_link)) >=
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Now find the list of link properties.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Delete corrupted line.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Find any properties in linkp that refer to "old", and rename to "new".
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Return B_TRUE if any renaming occurred.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_attr_rename(dlmgmt_link_t *linkp, const char *old, const char *new,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((attrp = linkattr_find(linkp->ll_head, "linkover")) != NULL ||
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (attrp = linkattr_find(linkp->ll_head, "simnetpeer")) != NULL) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (strcmp(old, (char *)attrp->lp_val) == 0) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((attrp = linkattr_find(linkp->ll_head, "portnames")) == NULL)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy /* <linkname>:[<linkname>:]... */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((newval = calloc(MAXLINKATTRVALLEN, sizeof (char))) == NULL)
d62bc4badc1c1f1549c961cfb8b420e650e1272byzprocess_db_write(dlmgmt_db_req_t *req, FILE *fp, FILE *nfp)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy dlmgmt_link_t link_in_file, *linkp = NULL, *dblinkp;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy boolean_t persist = (req->ls_flags == DLMGMT_PERSIST);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy writeall = (req->ls_linkid == DATALINK_ALL_LINKID);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (req->ls_op == DLMGMT_DB_OP_WRITE && !writeall) {
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * find the link in the avl tree with the given linkid.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy linkp = link_by_id(req->ls_linkid, req->ls_zoneid);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if (linkp == NULL || (linkp->ll_flags & req->ls_flags) == 0) {
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * This link has already been changed. This could
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * happen if the request is pending because of
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * read-only file-system. If so, we are done.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * In the case of a rename, linkp's name has been updated to
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the new name, and req->ls_link is the old link name.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy rename = (strcmp(req->ls_link, linkp->ll_link) != 0);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * fp can be NULL if the file didn't initially exist and we're
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * creating it as part of this write operation.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz while (err == 0 && fgets(buf, sizeof (buf), fp) != NULL &&
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (link_in_file.ll_link[0] == '\0' || done) {
0dc974a9a2e66d676505db23524ebff105fb36a9Cathy Zhou * this is a comment line or we are done updating the
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * line for the specified link, write the rest of
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * For write operations, we generate a new output line
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * if we're either writing all links (writeall) or if
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the name of the link in the file matches the one
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * we're looking for. Otherwise, we write out the
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * buffer as-is.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * If we're doing a rename operation, ensure that any
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * references to the link being renamed in link
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * properties are also updated before we write
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy err = dlmgmt_attr_rename(dblinkp, req->ls_link,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Delete is simple. If buf does not represent the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * link we're deleting, write it out.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (strcmp(req->ls_link, link_in_file.ll_link) != 0) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * If we get to the end of the file and have not seen what linkid
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * points to, write it out then.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (req->ls_op == DLMGMT_DB_OP_WRITE && !writeall && !rename && !done) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Royprocess_db_read(dlmgmt_db_req_t *req, FILE *fp)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy dlmgmt_link_t link_in_file, *newlink, *link_in_db;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * This loop processes each line of the configuration file.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Skip the comment line.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy link_in_file.ll_linkid == DATALINK_INVALID_LINKID)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy link_in_db = avl_find(&dlmgmt_name_avl, &link_in_file,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * If the link in the database already has the flag
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * for this request set, then the entry is a
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * duplicate. If it's not a duplicate, then simply
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * turn on the appropriate flag on the existing link.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy "in the repository: %s",
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Save the newly read properties into
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * the existing link.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * This is a new link. Allocate a new dlmgmt_link_t
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * and add it to the trees.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy "memory to create new link %s",
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy bcopy(&link_in_file, newlink, sizeof (*newlink));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (newlink->ll_linkid == DATALINK_INVALID_LINKID)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (avl_find(&dlmgmt_id_avl, newlink, &id_where) !=
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy dlmgmt_log(LOG_WARNING, "Unable to activate %s",
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy avl_insert(&dlmgmt_name_avl, newlink, name_where);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy avl_insert(&dlmgmt_id_avl, newlink, id_where);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Generate an entry in the link database.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Each entry has this format:
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * <link name> <prop0>=<type>,<val>;...;<propn>=<type>,<val>;
d62bc4badc1c1f1549c961cfb8b420e650e1272byzstatic void
d62bc4badc1c1f1549c961cfb8b420e650e1272byzgenerate_link_line(dlmgmt_link_t *linkp, boolean_t persist, char *buf)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy ptr += snprintf(ptr, BUFLEN(lim, ptr), "%s\t", linkp->ll_link);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * We store the linkid in the active database so that dlmgmtd
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * can recover in the event that it is restarted.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy ptr += write_uint64(ptr, BUFLEN(lim, ptr), "linkid", &u64);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz ptr += write_uint64(ptr, BUFLEN(lim, ptr), "class", &u64);
d62bc4badc1c1f1549c961cfb8b420e650e1272byz ptr += write_uint64(ptr, BUFLEN(lim, ptr), "media", &u64);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * The daemon does not keep any active link attribute. Only store the
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * attributes if this request is for persistent configuration,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy ptr += translators[cur_p->lp_type].write_func(ptr,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy BUFLEN(lim, ptr), cur_p->lp_name, cur_p->lp_val);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) snprintf(buf, MAXLINELEN, "%s\n", tmpbuf);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_delete_db_entry(dlmgmt_link_t *linkp, uint32_t flags)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy return (dlmgmt_db_update(DLMGMT_DB_OP_DELETE, linkp->ll_link, linkp,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_write_db_entry(const char *entryname, dlmgmt_link_t *linkp,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((err = dlmgmt_db_update(DLMGMT_DB_OP_WRITE, entryname,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (((err = dlmgmt_db_update(DLMGMT_DB_OP_WRITE, entryname,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy linkp, DLMGMT_ACTIVE)) != 0) && (flags & DLMGMT_PERSIST)) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) dlmgmt_db_update(DLMGMT_DB_OP_DELETE, entryname,
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return (0);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Upgrade properties that have link IDs as values to link names. Because '.'
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * is a valid linkname character, the port separater for link aggregations
d501bbfebe95a313ee5e78368177b1667a71c628Sebastien Roy * must be changed to ':'.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (strcmp(attrp->lp_name, "linkover") == 0 ||
d501bbfebe95a313ee5e78368177b1667a71c628Sebastien Roy linkid = (datalink_id_t)*(uint64_t *)attrp->lp_val;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((linkp = link_by_id(linkid, GLOBAL_ZONEID)) == NULL)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((new_attr_val = malloc(new_attr_sz)) == NULL)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy } else if (strcmp(attrp->lp_name, "portnames") == 0) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * The old format for "portnames" was
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * "<linkid>.[<linkid>.]...". The new format is
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * "<linkname>:[<linkname>:]...".
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy new_attr_val = calloc(MAXLINKATTRVALLEN, sizeof (char));
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (linkp = link_by_id(linkid, GLOBAL_ZONEID)) ==
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) snprintf(portname, sizeof (portname), "%s:",
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy /* skip the '.' delimiter */
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy for (attrp = linkp->ll_head; attrp != NULL; attrp = attrp->lp_next)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy (void) dlmgmt_write_db_entry(linkp->ll_link, linkp, DLMGMT_ACTIVE);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roydlmgmt_db_walk(zoneid_t zoneid, datalink_class_t class, db_walk_func_t *func)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy for (linkp = avl_first(&dlmgmt_id_avl); linkp != NULL;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if (linkp->ll_zoneid == zoneid && (linkp->ll_class & class))
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * Initialize the datalink <link name, linkid> mapping and the link's
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * attributes list based on the configuration file /etc/dladm/datalink.conf
d62bc4badc1c1f1549c961cfb8b420e650e1272byz * and the active configuration cache file
b9e076dcc05b713d74073c0d692dfbb0f6f2c594yz * /etc/svc/volatile/dladm/datalink-management:default.cache.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((req = dlmgmt_db_req_alloc(DLMGMT_DB_OP_READ, NULL,
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy DATALINK_INVALID_LINKID, zoneid, DLMGMT_ACTIVE, &err)) == NULL)
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((err = dlmgmt_process_db_req(req)) != 0) {
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * If we get back ENOENT, that means that the active
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * configuration file doesn't exist yet, and is not an error.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * We'll create it down below after we've loaded the
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * persistent configuration.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * First update links in memory, then dump the entire db to
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy dlmgmt_db_walk(zoneid, DATALINK_CLASS_ALL, dlmgmt_db_upgrade);
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy if ((err = dlmgmt_process_db_req(req)) != 0 &&
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy * Remove all links in the given zoneid.
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy dlmgmt_link_t *linkp = avl_first(&dlmgmt_name_avl), *next_linkp;