Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


 137         iPath = shl ? shl->shl_path : strlen(sh->sh_path);
 138         iHash = pkp_tab_hash(sh->sh_path, strlen(sh->sh_path));
 139 
 140         /*
 141          * Now walk down the hash table and find the entry to free!
 142          */
 143         for (p = NULL, s = sht->s_buckets[iHash].ssh_sh;
 144             s != NULL; s = s->sh_next) {
 145                 /*
 146                  * We need exact matches.
 147                  */
 148                 if (strcmp(sh->sh_path, s->sh_path) == 0 &&
 149                     strlen(s->sh_path) == iPath) {
 150                         if (p) {
 151                                 p->sh_next = s->sh_next;
 152                         } else {
 153                                 sht->s_buckets[iHash].ssh_sh = s->sh_next;
 154                         }
 155 
 156                         ASSERT(sht->s_buckets[iHash].ssh_count != 0);
 157                         atomic_add_32(&sht->s_buckets[iHash].ssh_count, -1);
 158                         atomic_add_32(&sht->s_count, -1);
 159                         atomic_add_32(&sharetab_count, -1);
 160 
 161                         ASSERT(sharetab_size >= s->sh_size);
 162                         sharetab_size -= s->sh_size;
 163 
 164                         gethrestime(&sharetab_mtime);
 165                         atomic_add_32(&sharetab_generation, 1);
 166 
 167                         break;
 168                 }
 169 
 170                 p = s;
 171         }
 172 
 173         rw_exit(&sharetab_lock);
 174 
 175         if (!s) {
 176                 return (ENOENT);
 177         }
 178 
 179         s->sh_next = NULL;
 180         sharefree(s, NULL);
 181 
 182         /*
 183          * We need to free the share for the caller.
 184          */
 185         sharefree(sh, shl);


 264                 if (strcmp(sh->sh_path, s->sh_path) == 0 &&
 265                     strlen(s->sh_path) == iPath) {
 266                         if (p) {
 267                                 p->sh_next = sh;
 268                         } else {
 269                                 sht->s_buckets[iHash].ssh_sh = sh;
 270                         }
 271 
 272                         sh->sh_next = s->sh_next;
 273 
 274                         ASSERT(sharetab_size >= s->sh_size);
 275                         sharetab_size -= s->sh_size;
 276                         sharetab_size += sh->sh_size;
 277 
 278                         /*
 279                          * Get rid of the old node.
 280                          */
 281                         sharefree(s, NULL);
 282 
 283                         gethrestime(&sharetab_mtime);
 284                         atomic_add_32(&sharetab_generation, 1);
 285 
 286                         ASSERT(sht->s_buckets[iHash].ssh_count != 0);
 287                         rw_exit(&sharetab_lock);
 288 
 289                         return (0);
 290                 }
 291 
 292                 p = s;
 293         }
 294 
 295         /*
 296          * Okay, we have gone through the entire hash chain and not
 297          * found a match. We just need to add this node.
 298          */
 299         sh->sh_next = sht->s_buckets[iHash].ssh_sh;
 300         sht->s_buckets[iHash].ssh_sh = sh;
 301         atomic_add_32(&sht->s_buckets[iHash].ssh_count, 1);
 302         atomic_add_32(&sht->s_count, 1);
 303         atomic_add_32(&sharetab_count, 1);
 304         sharetab_size += sh->sh_size;
 305 
 306         gethrestime(&sharetab_mtime);
 307         atomic_add_32(&sharetab_generation, 1);
 308 
 309         rw_exit(&sharetab_lock);
 310 
 311         return (0);
 312 }
 313 
 314 void
 315 sharefs_sharetab_init(void)
 316 {
 317         rw_init(&sharetab_lock, NULL, RW_DEFAULT, NULL);
 318         rw_init(&sharefs_lock, NULL, RW_DEFAULT, NULL);
 319 
 320         sharetab_size = 0;
 321         sharetab_count = 0;
 322         sharetab_generation = 1;
 323 
 324         gethrestime(&sharetab_mtime);
 325         gethrestime(&sharetab_snap_time);
 326 }
 327 




 137         iPath = shl ? shl->shl_path : strlen(sh->sh_path);
 138         iHash = pkp_tab_hash(sh->sh_path, strlen(sh->sh_path));
 139 
 140         /*
 141          * Now walk down the hash table and find the entry to free!
 142          */
 143         for (p = NULL, s = sht->s_buckets[iHash].ssh_sh;
 144             s != NULL; s = s->sh_next) {
 145                 /*
 146                  * We need exact matches.
 147                  */
 148                 if (strcmp(sh->sh_path, s->sh_path) == 0 &&
 149                     strlen(s->sh_path) == iPath) {
 150                         if (p) {
 151                                 p->sh_next = s->sh_next;
 152                         } else {
 153                                 sht->s_buckets[iHash].ssh_sh = s->sh_next;
 154                         }
 155 
 156                         ASSERT(sht->s_buckets[iHash].ssh_count != 0);
 157                         atomic_dec_32(&sht->s_buckets[iHash].ssh_count);
 158                         atomic_dec_32(&sht->s_count);
 159                         atomic_dec_32(&sharetab_count);
 160 
 161                         ASSERT(sharetab_size >= s->sh_size);
 162                         sharetab_size -= s->sh_size;
 163 
 164                         gethrestime(&sharetab_mtime);
 165                         atomic_inc_32(&sharetab_generation);
 166 
 167                         break;
 168                 }
 169 
 170                 p = s;
 171         }
 172 
 173         rw_exit(&sharetab_lock);
 174 
 175         if (!s) {
 176                 return (ENOENT);
 177         }
 178 
 179         s->sh_next = NULL;
 180         sharefree(s, NULL);
 181 
 182         /*
 183          * We need to free the share for the caller.
 184          */
 185         sharefree(sh, shl);


 264                 if (strcmp(sh->sh_path, s->sh_path) == 0 &&
 265                     strlen(s->sh_path) == iPath) {
 266                         if (p) {
 267                                 p->sh_next = sh;
 268                         } else {
 269                                 sht->s_buckets[iHash].ssh_sh = sh;
 270                         }
 271 
 272                         sh->sh_next = s->sh_next;
 273 
 274                         ASSERT(sharetab_size >= s->sh_size);
 275                         sharetab_size -= s->sh_size;
 276                         sharetab_size += sh->sh_size;
 277 
 278                         /*
 279                          * Get rid of the old node.
 280                          */
 281                         sharefree(s, NULL);
 282 
 283                         gethrestime(&sharetab_mtime);
 284                         atomic_inc_32(&sharetab_generation);
 285 
 286                         ASSERT(sht->s_buckets[iHash].ssh_count != 0);
 287                         rw_exit(&sharetab_lock);
 288 
 289                         return (0);
 290                 }
 291 
 292                 p = s;
 293         }
 294 
 295         /*
 296          * Okay, we have gone through the entire hash chain and not
 297          * found a match. We just need to add this node.
 298          */
 299         sh->sh_next = sht->s_buckets[iHash].ssh_sh;
 300         sht->s_buckets[iHash].ssh_sh = sh;
 301         atomic_inc_32(&sht->s_buckets[iHash].ssh_count);
 302         atomic_inc_32(&sht->s_count);
 303         atomic_inc_32(&sharetab_count);
 304         sharetab_size += sh->sh_size;
 305 
 306         gethrestime(&sharetab_mtime);
 307         atomic_inc_32(&sharetab_generation);
 308 
 309         rw_exit(&sharetab_lock);
 310 
 311         return (0);
 312 }
 313 
 314 void
 315 sharefs_sharetab_init(void)
 316 {
 317         rw_init(&sharetab_lock, NULL, RW_DEFAULT, NULL);
 318         rw_init(&sharefs_lock, NULL, RW_DEFAULT, NULL);
 319 
 320         sharetab_size = 0;
 321         sharetab_count = 0;
 322         sharetab_generation = 1;
 323 
 324         gethrestime(&sharetab_mtime);
 325         gethrestime(&sharetab_snap_time);
 326 }
 327