cfs/src/FsPageCache.cc
// common functions for both client and server to use
// refers to shmipc.cc
common functions for both client and server to use
refers to shmipc.cc
common functions for both client and server to use refers to shmipc . cc
void *attachPageCacheShm(bool isServer, int &shmFd) {
  void *shmPtr = nullptr;
  mode_t tmp_mask, old_mask;
  old_mask = umask((mode_t)0);
  int shmprot = PROT_READ;
  if (isServer) {
    shmFd = shm_open(gPageCacheShmName, O_RDWR | O_CREAT, 0666);
  } else {
    shmFd = shm_open(gPageCacheShmName, O_RDONLY, 0666);
  }
  tmp_mask = umask(old_mask);
  (void)(tmp_mask);
  if (shmFd < 0) goto error;
  if (isServer) {
    if (ftruncate(shmFd, sizeof(PageCacheLayout)) != 0) goto error;
  }
  if (isServer) shmprot |= PROT_WRITE;
  shmPtr = mmap(0, sizeof(PageCacheLayout), shmprot, MAP_SHARED, shmFd, 0);
  if (shmPtr == MAP_FAILED) goto error;
  if (isServer) memset(shmPtr, 0, sizeof(PageCacheLayout));
  fprintf(stdout, "========> attachPageCacheShm server?:%d=========>\n",
          isServer);
  return shmPtr;
error:
  fprintf(stderr, "attachPageCacheShm Fail. server?:%d\n", isServer);
  detachPageCacheShm(isServer, shmFd, shmPtr);
  return nullptr;
}
void * attachPageCacheShm ( bool isServer , int & shmFd ) { void * shmPtr = nullptr ; mode_t tmp_mask , old_mask ; old_mask = umask ( ( mode_t ) 0 ) ; int shmprot = PROT_READ ; if ( isServer ) { shmFd = shm_open ( gPageCacheShmName , O_RDWR | O_CREAT , 0666 ) ; } else { shmFd = shm_open ( gPageCacheShmName , O_RDONLY , 0666 ) ; } tmp_mask = umask ( old_mask ) ; ( void ) ( tmp_mask ) ; if ( shmFd < 0 ) goto error ; if ( isServer ) { if ( ftruncate ( shmFd , sizeof ( PageCacheLayout ) ) != 0 ) goto error ; } if ( isServer ) shmprot |= PROT_WRITE ; shmPtr = mmap ( 0 , sizeof ( PageCacheLayout ) , shmprot , MAP_SHARED , shmFd , 0 ) ; if ( shmPtr == MAP_FAILED ) goto error ; if ( isServer ) memset ( shmPtr , 0 , sizeof ( PageCacheLayout ) ) ; fprintf ( stdout , " \n " , isServer ) ; return shmPtr ; error : fprintf ( stderr , " \n " , isServer ) ; detachPageCacheShm ( isServer , shmFd , shmPtr ) ; return nullptr ; }
common functions for both client and server to use
refers to shmipc.cc
common functions for both client and server to use refers to shmipc . cc
// shmFd = shm_open(gPageCacheShmName, O_RDWR, 0666); // simply avoid warning