Print this page
Plug sharefs zone-shutdown leaks


   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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2018 Nexenta Systems, Inc.

  28  */
  29 
  30 #include <sys/types.h>
  31 #include <sys/types32.h>
  32 #include <sys/param.h>
  33 #include <sys/systm.h>
  34 #include <rpc/types.h>
  35 #include <sys/vfs.h>
  36 #include <sys/siginfo.h>
  37 #include <sys/proc.h>             /* for exit() declaration */
  38 #include <sys/kmem.h>
  39 #include <sys/pathname.h>
  40 #include <sys/debug.h>
  41 #include <sys/vtrace.h>
  42 #include <sys/cmn_err.h>
  43 #include <sys/atomic.h>
  44 #include <sys/policy.h>
  45 
  46 #include <sharefs/sharefs.h>
  47 


 292 
 293         sg->sharetab_size = 0;
 294         sg->sharetab_count = 0;
 295         sg->sharetab_generation = 1;
 296 
 297         gethrestime(&sg->sharetab_mtime);
 298         gethrestime(&sg->sharetab_snap_time);
 299 
 300         return (sg);
 301 }
 302 
 303 /* ARGSUSED */
 304 static void
 305 sharetab_zone_fini(zoneid_t zoneid, void *data)
 306 {
 307         sharetab_globals_t *sg = data;
 308 
 309         rw_destroy(&sg->sharefs_lock);
 310         rw_destroy(&sg->sharetab_lock);
 311 





















 312         kmem_free(sg, sizeof (*sg));
 313 }
 314 
 315 void
 316 sharefs_sharetab_init(void)
 317 {
 318         zone_key_create(&sharetab_zone_key, sharetab_zone_init,
 319             NULL, sharetab_zone_fini);
 320 }
 321 
 322 sharetab_globals_t *
 323 sharetab_get_globals(zone_t *zone)
 324 {
 325         return (zone_getspecific(sharetab_zone_key, zone));
 326 }
 327 
 328 int
 329 sharefs_impl(enum sharefs_sys_op opcode, share_t *sh_in, uint32_t iMaxLen)
 330 {
 331         int             error = 0;




   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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2018 Nexenta Systems, Inc.
  28  * Copyright 2019 Joyent, Inc.
  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/types32.h>
  33 #include <sys/param.h>
  34 #include <sys/systm.h>
  35 #include <rpc/types.h>
  36 #include <sys/vfs.h>
  37 #include <sys/siginfo.h>
  38 #include <sys/proc.h>             /* for exit() declaration */
  39 #include <sys/kmem.h>
  40 #include <sys/pathname.h>
  41 #include <sys/debug.h>
  42 #include <sys/vtrace.h>
  43 #include <sys/cmn_err.h>
  44 #include <sys/atomic.h>
  45 #include <sys/policy.h>
  46 
  47 #include <sharefs/sharefs.h>
  48 


 293 
 294         sg->sharetab_size = 0;
 295         sg->sharetab_count = 0;
 296         sg->sharetab_generation = 1;
 297 
 298         gethrestime(&sg->sharetab_mtime);
 299         gethrestime(&sg->sharetab_snap_time);
 300 
 301         return (sg);
 302 }
 303 
 304 /* ARGSUSED */
 305 static void
 306 sharetab_zone_fini(zoneid_t zoneid, void *data)
 307 {
 308         sharetab_globals_t *sg = data;
 309 
 310         rw_destroy(&sg->sharefs_lock);
 311         rw_destroy(&sg->sharetab_lock);
 312 
 313         /* ALL of the allocated things must be cleaned before we free sg. */
 314         while (sg->sharefs_sharetab != NULL) {
 315                 int i;
 316                 sharetab_t *freeing = sg->sharefs_sharetab;
 317 
 318                 sg->sharefs_sharetab = freeing->s_next;
 319                 kmem_free(freeing->s_fstype, strlen(freeing->s_fstype) + 1);
 320                 for (i = 0; i < PKP_HASH_SIZE; i++) {
 321                         sharefs_hash_head_t *bucket;
 322 
 323                         bucket = &(freeing->s_buckets[i]);
 324                         while (bucket->ssh_sh != NULL) {
 325                                 share_t *share = bucket->ssh_sh;
 326 
 327                                 bucket->ssh_sh = share->sh_next;
 328                                 sharefree(share, NULL);
 329                         }
 330                 }
 331                 kmem_free(freeing, sizeof (*freeing));
 332         }
 333 
 334         kmem_free(sg, sizeof (*sg));
 335 }
 336 
 337 void
 338 sharefs_sharetab_init(void)
 339 {
 340         zone_key_create(&sharetab_zone_key, sharetab_zone_init,
 341             NULL, sharetab_zone_fini);
 342 }
 343 
 344 sharetab_globals_t *
 345 sharetab_get_globals(zone_t *zone)
 346 {
 347         return (zone_getspecific(sharetab_zone_key, zone));
 348 }
 349 
 350 int
 351 sharefs_impl(enum sharefs_sys_op opcode, share_t *sh_in, uint32_t iMaxLen)
 352 {
 353         int             error = 0;