Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.

  24  * Copyright 2016 Argo Technologie SA.
  25  * Copyright (c) 2016-2017, Chris Fraire <cfraire@me.com>.
  26  */
  27 
  28 /*
  29  * Contains DB walker functions, which are of type `db_wfunc_t';
  30  *
  31  * typedef boolean_t db_wfunc_t(void *cbarg, nvlist_t *db_nvl, char *buf,
  32  *                              size_t bufsize, int *errp);
  33  *
  34  * ipadm_rw_db() walks through the data store, one line at a time and calls
  35  * these call back functions with:
  36  *      `cbarg'  - callback argument
  37  *      `db_nvl' - representing a line from DB in nvlist_t form
  38  *      `buf'    - character buffer to hold modified line
  39  *      `bufsize'- size of the buffer
  40  *      `errp' - captures any error inside the walker function.
  41  *
  42  * All the 'write' callback functions modify `db_nvl' based on `cbarg' and
  43  * copy string representation of `db_nvl' (using ipadm_nvlist2str()) into `buf'.


 440         if (!ipmgmt_rdonly_root) {
 441                 err = ipadm_rw_db(db_walk_func, db_warg, IPADM_DB_FILE,
 442                     mode, db_op);
 443                 if (err != EROFS)
 444                         goto done;
 445         }
 446 
 447         /*
 448          * If we haven't already copied the file to the volatile
 449          * file system, do so. This should only happen on a failed
 450          * writeop(i.e., we have acquired the write lock above).
 451          */
 452         if (access(IPADM_VOL_DB_FILE, F_OK) != 0) {
 453                 assert(writeop);
 454                 err = ipmgmt_cpfile(IPADM_DB_FILE, IPADM_VOL_DB_FILE, B_TRUE);
 455                 if (err != 0)
 456                         goto done;
 457                 (void) pthread_attr_init(&attr);
 458                 (void) pthread_attr_setdetachstate(&attr,
 459                     PTHREAD_CREATE_DETACHED);

 460                 err = pthread_create(&tid, &attr, ipmgmt_db_restore_thread,
 461                     NULL);
 462                 (void) pthread_attr_destroy(&attr);
 463                 if (err != 0) {
 464                         (void) unlink(IPADM_VOL_DB_FILE);
 465                         goto done;
 466                 }
 467                 ipmgmt_rdonly_root = B_TRUE;
 468         }
 469 
 470         /*
 471          * Read/write from the volatile copy.
 472          */
 473         err = ipadm_rw_db(db_walk_func, db_warg, IPADM_VOL_DB_FILE,
 474             mode, db_op);
 475 done:
 476         (void) pthread_rwlock_unlock(&ipmgmt_dbconf_lock);
 477         return (err);
 478 }
 479 




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2018 Joyent, Inc.
  25  * Copyright 2016 Argo Technologie SA.
  26  * Copyright (c) 2016-2017, Chris Fraire <cfraire@me.com>.
  27  */
  28 
  29 /*
  30  * Contains DB walker functions, which are of type `db_wfunc_t';
  31  *
  32  * typedef boolean_t db_wfunc_t(void *cbarg, nvlist_t *db_nvl, char *buf,
  33  *                              size_t bufsize, int *errp);
  34  *
  35  * ipadm_rw_db() walks through the data store, one line at a time and calls
  36  * these call back functions with:
  37  *      `cbarg'  - callback argument
  38  *      `db_nvl' - representing a line from DB in nvlist_t form
  39  *      `buf'    - character buffer to hold modified line
  40  *      `bufsize'- size of the buffer
  41  *      `errp' - captures any error inside the walker function.
  42  *
  43  * All the 'write' callback functions modify `db_nvl' based on `cbarg' and
  44  * copy string representation of `db_nvl' (using ipadm_nvlist2str()) into `buf'.


 441         if (!ipmgmt_rdonly_root) {
 442                 err = ipadm_rw_db(db_walk_func, db_warg, IPADM_DB_FILE,
 443                     mode, db_op);
 444                 if (err != EROFS)
 445                         goto done;
 446         }
 447 
 448         /*
 449          * If we haven't already copied the file to the volatile
 450          * file system, do so. This should only happen on a failed
 451          * writeop(i.e., we have acquired the write lock above).
 452          */
 453         if (access(IPADM_VOL_DB_FILE, F_OK) != 0) {
 454                 assert(writeop);
 455                 err = ipmgmt_cpfile(IPADM_DB_FILE, IPADM_VOL_DB_FILE, B_TRUE);
 456                 if (err != 0)
 457                         goto done;
 458                 (void) pthread_attr_init(&attr);
 459                 (void) pthread_attr_setdetachstate(&attr,
 460                     PTHREAD_CREATE_DETACHED);
 461                 (void) pthread_attr_setname_np(&attr, "db_restore");
 462                 err = pthread_create(&tid, &attr, ipmgmt_db_restore_thread,
 463                     NULL);
 464                 (void) pthread_attr_destroy(&attr);
 465                 if (err != 0) {
 466                         (void) unlink(IPADM_VOL_DB_FILE);
 467                         goto done;
 468                 }
 469                 ipmgmt_rdonly_root = B_TRUE;
 470         }
 471 
 472         /*
 473          * Read/write from the volatile copy.
 474          */
 475         err = ipadm_rw_db(db_walk_func, db_warg, IPADM_VOL_DB_FILE,
 476             mode, db_op);
 477 done:
 478         (void) pthread_rwlock_unlock(&ipmgmt_dbconf_lock);
 479         return (err);
 480 }
 481