X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fsvm.c;h=7d98fbe936d74d72a89f422dae92b4bc8c5306ed;hb=4bc1796b346efd10f3fb19b176ff089179263a24;hp=f187fbfcab2c290f07d712e6cbabd67f9a09f7dd;hpb=aec8f8984771cabc79a8ed64f56afcf61465d00a;p=vpp.git diff --git a/src/svm/svm.c b/src/svm/svm.c index f187fbfcab2..7d98fbe936d 100644 --- a/src/svm/svm.c +++ b/src/svm/svm.c @@ -76,19 +76,19 @@ svm_get_global_region_base_va () unformat_init_clib_file (&input, fd); while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) { - unformat (&input, "%llx-%llx", &start, &end); + if (unformat (&input, "%llx-%llx", &start, &end)) + end--; unformat_skip_line (&input); } + unformat_free (&input); + close (fd); - count_leading_zeros (bits, end); + bits = count_leading_zeros (end); bits = 64 - bits; if (bits >= 36 && bits <= 48) return ((1ul << bits) / 4) - (2 * SVM_GLOBAL_REGION_SIZE); else clib_unix_error ("unexpected va bits '%u'", bits); - - unformat_free (&input); - close (fd); #endif /* default value */ @@ -652,6 +652,10 @@ svm_map_region (svm_map_region_args_t * a) return (0); } + /* Reset ownership in case the client started first */ + if (fchown (svm_fd, a->uid, a->gid) < 0) + clib_unix_warning ("segment chown [ok if client starts first]"); + time_left = 20; while (1) { @@ -721,6 +725,8 @@ svm_map_region (svm_map_region_args_t * a) return (0); } + close (svm_fd); + if ((uword) rp != rp->virtual_base) { clib_warning ("mmap botch"); @@ -1034,7 +1040,7 @@ svm_region_unlink (svm_region_t * rp) * a new region client showing up at the wrong moment. */ void -svm_region_unmap (void *rp_arg) +svm_region_unmap_internal (void *rp_arg, u8 is_client) { int i, mypid = getpid (); int nclients_left; @@ -1134,7 +1140,12 @@ found: vec_free (name); region_unlock (rp); - svm_region_unlink (rp); + + /* If a client asks for the cleanup, don't unlink the backing + * file since we can't tell if it has been recreated. */ + if (!is_client) + svm_region_unlink (rp); + munmap ((void *) virtual_base, virtual_size); region_unlock (root_rp); svm_pop_heap (oldheap); @@ -1147,11 +1158,23 @@ found: munmap ((void *) virtual_base, virtual_size); } +void +svm_region_unmap (void *rp_arg) +{ + svm_region_unmap_internal (rp_arg, 0 /* is_client */ ); +} + +void +svm_region_unmap_client (void *rp_arg) +{ + svm_region_unmap_internal (rp_arg, 1 /* is_client */ ); +} + /* * svm_region_exit */ -void -svm_region_exit () +static void +svm_region_exit_internal (u8 is_client) { void *oldheap; int i, mypid = getpid (); @@ -1191,7 +1214,7 @@ svm_region_exit () found: - if (vec_len (root_rp->client_pids) == 0) + if (!is_client && vec_len (root_rp->client_pids) == 0) svm_region_unlink (root_rp); region_unlock (root_rp); @@ -1201,6 +1224,18 @@ found: munmap ((void *) virtual_base, virtual_size); } +void +svm_region_exit (void) +{ + svm_region_exit_internal (0 /* is_client */ ); +} + +void +svm_region_exit_client (void) +{ + svm_region_exit_internal (1 /* is_client */ ); +} + void svm_client_scan_this_region_nolock (svm_region_t * rp) {