/*{ ** Name: CS_map_sys_segment() - Map the system control segment to this process ** ** Description: ** Maps the system control block to this process. This must happen before ** any other action can be taken on shared memory (with the exception of ** CS_create_sys_segment()). ** ** Upon successful exectution of this routine CS may manipulate the system ** control data structure CS_SMCNTRL (taking care to use proper semaphore ** techniques which take into account that the data structure is shared ** across processes). ** ** This call is internal to CS is meant only to be called by CS, and may ** only exist on unix systems supporting shared memory. ** ** Inputs: ** none. ** ** Outputs: ** cssm_segment ptr to the CS_SMCNTRL data structure. ** err_code system dependent error information. ** ** Returns: ** E_DB_OK ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 08-Sep-88 (mmm) ** First Version ** 12-jun-89 (rogerk) ** Added allocated_pages argument to MEget_pages calls. ** Changed shared memory key from a LOCATIONN pointer to a character ** string. ** 26-aug-89 (rexl) ** Added calls to protect page allocator. ** 18-oct-1993 (bryanp) ** Issue trace messages in failure cases. Simply returning FAIL doesnt ** help the diagnosis process very much, while the trace messages ** can help (if the caller has done a TRset_file by this point). ** 14-Oct-1998 (jenjo02) ** CS_map_sys_segment(): Don't initialize css_spinlock. That was done ** when the shared segment was created. Reinitializing it may ** effectively destroy a holding process's lock! ** 21-May-2004 (wanfr01) ** INGSRV2835, Bug 112371 ** As per the Jon Jensen's last update, removed the invalid initialize ** of css_spinlock. ** 5-Apr-2006 (kschendel) ** Use generated css version instead of constant. ** 12-aug-2008 (stephenb) ** previous change is too strict if programs not shipped with Ingres ** try to connect to the system segment because the checked version ** goes right down to the build number. allow some latitude using ** II_SYSSEG_VERS. If this is set to the current major Ingres ** version we will allow the connection. This is an interim ** solution to Golden Gate's issue. */ STATUS CS_map_sys_segment(CL_ERR_DESC *err_code) { STATUS status = OK; PTR address; SIZE_TYPE alloc_pages; /* map segment into first available address and then initialize it */ /* Use "sysseg.mem" as shared memory key. */ address = 0; status = MEget_pages(ME_SSHARED_MASK, 0, "sysseg.mem", &address, &alloc_pages, err_code); if (status) { #ifdef xDEBUG TRdisplay("CS_map_sys_segment: unable to attach to sysseg.mem (%x)\n", status); #endif /* Unable to attach allocated shared memory segment. */ /* status = FAIL; This isn't a useful error return code! */ } else { char *segvers; i4 segint; Cs_sm_cb = (CS_SMCNTRL *) address; /* ** check if segment version has been provided, if so we'll ** deem it O.K. if it matches the current major version */ NMgtAt("II_SYSSEG_VERS", &segvers); if (segvers != (char *)NULL && *segvers != EOS && CVal(segvers, &segint) == OK && segint == GV_MAJOR) status = OK; else { i4 id = make_css_version(); if (Cs_sm_cb->css_version != id) { TRdisplay( "CS_map_sys_segment: sysseg.mem is version %x (%d). We need version %x (%d)\n", Cs_sm_cb->css_version, Cs_sm_cb->css_version, id, id); SETCLERR(err_code, 0, 0); status = FAIL; } } } return(status); }
/*{ ** Name: CS_map_sys_segment() - Map the system control segment to this process ** ** Description: ** Maps the system control block to this process. This must happen before ** any other action can be taken on shared memory (with the exception of ** CS_create_sys_segment()). ** ** Upon successful exectution of this routine CS may manipulate the system ** control data structure CS_SMCNTRL (taking care to use proper semaphore ** techniques which take into account that the data structure is shared ** across processes). ** ** This call is internal to CS is meant only to be called by CS, and may ** only exist on unix systems supporting shared memory. ** ** Inputs: ** none. ** ** Outputs: ** cssm_segment ptr to the CS_SMCNTRL data structure. ** err_code system dependent error information. ** ** Returns: ** E_DB_OK ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 08-Sep-88 (mmm) ** First Version ** 12-jun-89 (rogerk) ** Added allocated_pages argument to MEget_pages calls. ** Changed shared memory key from a LOCATIONN pointer to a character ** string. ** 26-aug-89 (rexl) ** Added calls to protect page allocator. ** 18-oct-1993 (bryanp) ** Issue trace messages in failure cases. Simply returning FAIL doesnt ** help the diagnosis process very much, while the trace messages ** can help (if the caller has done a TRset_file by this point). ** 14-Oct-1998 (jenjo02) ** CS_map_sys_segment(): Don't initialize css_spinlock. That was done ** when the shared segment was created. Reinitializing it may ** effectively destroy a holding process's lock! ** 21-May-2004 (wanfr01) ** INGSRV2835, Bug 112371 ** As per the Jon Jensen's last update, removed the invalid initialize ** of css_spinlock. ** 5-Apr-2006 (kschendel) ** Use generated css version instead of constant. */ STATUS CS_map_sys_segment(CL_ERR_DESC *err_code) { STATUS status = OK; PTR address; SIZE_TYPE alloc_pages; /* map segment into first available address and then initialize it */ /* Use "sysseg.mem" as shared memory key. */ address = 0; status = MEget_pages(ME_SSHARED_MASK, 0, "sysseg.mem", &address, &alloc_pages, err_code); if (status) { #ifdef xDEBUG TRdisplay("CS_map_sys_segment: unable to attach to sysseg.mem (%x)\n", status); #endif /* Unable to attach allocated shared memory segment. */ /* status = FAIL; This isn't a useful error return code! */ } else { i4 id = make_css_version(); Cs_sm_cb = (CS_SMCNTRL *) address; if (Cs_sm_cb->css_version != id) { TRdisplay( "CS_map_sys_segment: sysseg.mem is version %x (%d). We need version %x (%d)\n", Cs_sm_cb->css_version, Cs_sm_cb->css_version, id, id); SETCLERR(err_code, 0, 0); status = FAIL; } } return(status); }
/*{ ** Name: CS_create_sys_segment() - Create system shared mem segment. ** ** Description: ** Create system control block. Only caller should be the system ** initialization program. Other users of the system shared memory ** segment should only map an already created shared memory segment. ** ** This procedure creates a shared memory segment. It then maps it into ** the current process and initializes it. It then unmaps it from the ** current process (so that the CS_map_sys_segment() can be used without ** any special casing). ** ** Currently the already created shared memory segment is destroyed ** before the new one is created. We may add a destroy procedure ** once the system installation program is fleshed out. ** ** Inputs: ** num_of_servers number of servers this installation ** should support. ** num_of_wakeups number of wakeupblocks this installation ** should support. ** Outputs: ** err_code system dependent error. ** ** Returns: ** OK successfully created the segment. ** FAIL failure to create shared mem segment. ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 01-jan-88 (mmm) ** Created. ** 21-jan-89 (mikem) ** set correct value in the CS_SMCNTRL for the LG/LK shared memory id. ** also add support for dynamic LGLK segment. ** 12-jun-89 (rogerk) ** Integrated Terminator changes. Changed args to MEget_pages calls. ** Changed shared memory key to character string, not LOCATION pointer. ** Changed ME_loctokey call to ME_getkey. ** 21-Jul-89 (anton) ** Don't need a sys V semaphore per server any more. ** 26-aug-89 (rexl) ** Added calls to protect page allocator. ** 28-Dec-89 (fredp) ** Add TRdisplay error message on failure of semget. ** 16-feb-90 (greg) ** NMgtAt is a VOID. ** 16-mar-90 (fredp) ** Added support for system-wide II_LG_MAP_ADDR variable. If it ** is set, it contains the hex address of where the lock segment ** should be mapped into memory (instead of the default LG_MAP_ADDR). ** If the system segment attach fails on Sun3, retry with a 1MB ** lower attach address since the start of the user stack dropped ** 1MB from that of SunOS 4.0.x. ** 3-jul-1992 (bryanp) ** We don't need to call LG/LK initialize anymore. ** Added num_of_wakeups argument and used it to set css_wakeups_off. ** 26-jul-1993 (bryanp) ** Removed the 5 extra semaphores that no-one needed nor used. This ** leaves a few unused variables in various control blocks, which ** eventually I'll get around to removing, as well. For now, ** removing the unneeded semaphores reduces the system resource ** usage of Ingres, which is a Good Thing. ** 31-jan-94 (mikem) ** bug #58298 ** Changed CS_handle_wakeup_events() to maintain a high-water mark ** for events in use to limit the scanning necessary to find ** cross process events outstanding. Previous to this each call to ** the routine would scan the entire array, which in the default ** configuration was 4k elements long. Changed CS_create_sys_segment() ** to initalize the new fields. ** 20-apr-94 (mikem) ** Bug #57043 ** Added a call to CS_clockinit() to CS_create_sys_segment(). This ** call is responsible for initializing new control information stored ** in the shared memory system segment which is used to manipulate ** the pseudo-quantum clock. This clock is used to maintain both ** quantum and timeout queues in CS. See csclock.c for more ** information. ** 19-sep-2002 (devjo01) ** Allocate shared memory from local RAD if Running NUMA. ** 5-Apr-2006 (kschendel) ** Use generated css version instead of constant. */ STATUS CS_create_sys_segment(i4 num_of_servers, i4 num_of_wakeups, CL_ERR_DESC *err_code) { SIZE_TYPE size; STATUS status; PTR address; SIZE_TYPE alloc_pages; char *string; char *addr_string; STATUS cv_status = OK; i4 meflags; /* the system shared memory control block looks as follows: ** ** ------------------------------ ** | control block | ** |----------------------------- ** | array of server info | ** | ... | ** | ... | ** |----------------------------- ** | array of wakeup blocks | ** | ... | ** | ... | ** ------------------------------ */ size = sizeof(CS_SMCNTRL) + ((num_of_servers + 1) * sizeof(CS_SERV_INFO)); size += (num_of_wakeups * sizeof(CS_SM_WAKEUP_CB)); /* round to ME_MPAGESIZE */ size = (size + ME_MPAGESIZE - 1) & ~(ME_MPAGESIZE - 1); /* ** Create shared segment for sysseg. ** Use SYSSEG.MEM as shared memory key. */ meflags = ME_MZERO_MASK|ME_SSHARED_MASK|ME_CREATE_MASK|ME_NOTPERM_MASK; address = (PTR) 0; if (CXnuma_user_rad()) meflags |= ME_LOCAL_RAD; status = MEget_pages(meflags, size/ME_MPAGESIZE, "sysseg.mem", &address, &alloc_pages, err_code); /* FIX ME - initialize all the server control blocks */ if (!status) { /* initialize the shared memory data base */ Cs_sm_cb = (CS_SMCNTRL *) address; Cs_sm_cb->css_css_desc.cssm_addr = (PTR) 0; Cs_sm_cb->css_css_desc.cssm_size = size; #ifdef __vms /* there's no such thing as a shared mem id in VMS */ Cs_sm_cb->css_css_desc.cssm_id = 0; #else Cs_sm_cb->css_css_desc.cssm_id = ME_getkey("sysseg.mem"); #endif Cs_sm_cb->css_numservers = num_of_servers; Cs_sm_cb->css_wakeup.css_numwakeups = num_of_wakeups; Cs_sm_cb->css_wakeup.css_minfree = 0; Cs_sm_cb->css_wakeup.css_maxused = 0; CS_clockinit(Cs_sm_cb); Cs_sm_cb->css_version = make_css_version(); CS_SPININIT(&Cs_sm_cb->css_spinlock); /* now allocate cross process semaphores */ # ifdef xCL_075_SYS_V_IPC_EXISTS Cs_sm_cb->css_semid = semget(Cs_sm_cb->css_css_desc.cssm_id, CSCP_NUM, 0600|IPC_CREAT); if (Cs_sm_cb->css_semid < 0) { TRdisplay("semget of %d semaphores failed\n", CSCP_NUM); TRdisplay("errno = %d\n",errno); SETCLERR(err_code, 0, 0); status = FAIL; } # endif } if (!status) { Cs_sm_cb->css_wakeups_off = (char *)&Cs_sm_cb->css_servinfo[num_of_servers] - (char *)Cs_sm_cb; /* initialize the server-server event structures */ Cs_sm_cb->css_events_off = Cs_sm_cb->css_wakeups_off + (num_of_wakeups * sizeof(CS_SM_WAKEUP_CB)); Cs_sm_cb->css_events_end = Cs_sm_cb->css_css_desc.cssm_size; Cs_sm_cb->css_nsem = 0; Cs_sm_cb->css_usem = 0; } /* FIX ME - initialize all the server control blocks */ #ifdef xCL_NEED_SEM_CLEANUP /* Init Shared Memory mutex chain mutex */ if (!status) { CS_cp_synch_init(&Cs_sm_cb->css_shm_mutex, &status); } #endif return(status); }