static int kvs_cursor_reset(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DBC *dbc; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; /* Close and re-open the Berkeley DB cursor */ if ((dbc = cursor->dbc) != NULL) { cursor->dbc = NULL; if ((ret = dbc->close(dbc)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.close: %s", db_strerror(ret)); if ((ret = cursor->db->cursor(cursor->db, NULL, &dbc, 0)) != 0) ERET(wt_api, session, WT_ERROR, "Db.cursor: %s", db_strerror(ret)); cursor->dbc = dbc; } return (0); }
/* * kvs_call -- * Call a KVS function. */ static INLINE int kvs_call(WT_CURSOR *wt_cursor, const char *fname, int (*f)(kvs_t, struct kvs_record *, unsigned long, unsigned long)) { CURSOR *cursor; WT_SESSION *session; kvs_t kvs; int ret; char *p; cursor = (CURSOR *)wt_cursor; session = cursor->session; kvs = cursor->data_source->kvs; ret = 0; cursor->record.val = cursor->val; restart: if ((ret = f(kvs, &cursor->record, (unsigned long)0, (unsigned long)cursor->val_len)) != 0) { if (ret == KVS_E_KEY_NOT_FOUND) return (WT_NOTFOUND); ERET(session, WT_ERROR, "%s: %s", fname, kvs_strerror(ret)); } /* * If the returned length is larger than our passed-in length, we didn't * get the complete value. Grow the buffer and use kvs_get to complete * the retrieval (kvs_get because the call succeeded and the key was * copied out, so calling kvs_next/kvs_prev again would skip key/value * pairs). * * We have to loop, another thread of control might change the length of * the value, requiring we grow our buffer multiple times. * * We have to potentially restart the entire call in case the underlying * key/value disappears. */ for (;;) { if (cursor->val_len >= cursor->record.val_len) return (0); /* Grow the value buffer. */ if ((p = realloc( cursor->val, cursor->record.val_len + 32)) == NULL) return (os_errno()); cursor->val = cursor->record.val = p; cursor->val_len = cursor->record.val_len + 32; if ((ret = kvs_get(kvs, &cursor->record, (unsigned long)0, (unsigned long)cursor->val_len)) != 0) { if (ret == KVS_E_KEY_NOT_FOUND) goto restart; ERET(session, WT_ERROR, "kvs_get: %s", kvs_strerror(ret)); } } /* NOTREACHED */ }
static int kvs_cursor_search(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; dbc = cursor->dbc; key = &cursor->key; value = &cursor->value; if ((ret = copyin_key(wtcursor)) != 0) return (ret); if ((ret = dbc->get(dbc, key, value, DB_SET)) == 0) { copyout_key(wtcursor); copyout_value(wtcursor); return (0); } if (ret == DB_NOTFOUND || ret == DB_KEYEMPTY) return (WT_NOTFOUND); ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); }
static int kvs_cursor_update(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; dbc = cursor->dbc; key = &cursor->key; value = &cursor->value; if ((ret = copyin_key(wtcursor)) != 0) return (ret); copyin_value(wtcursor); if ((ret = dbc->put(dbc, key, value, DB_KEYFIRST)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.put: %s", db_strerror(ret)); return (0); }
/* * kvs_cursor_remove -- * WT_CURSOR::remove method. */ static int kvs_cursor_remove(WT_CURSOR *wt_cursor) { CURSOR *cursor; WT_SESSION *session; int ret; cursor = (CURSOR *)wt_cursor; session = cursor->session; ret = 0; /* * WiredTiger's "remove" of a bitfield is really an update with a value * of a single byte of zero. */ if (cursor->config_bitfield) { wt_cursor->value.size = 1; wt_cursor->value.data = "\0"; return (kvs_cursor_update(wt_cursor)); } if ((ret = copyin_key(wt_cursor)) != 0) return (ret); if ((ret = kvs_del(cursor->data_source->kvs, &cursor->record)) == 0) return (0); if (ret == KVS_E_KEY_NOT_FOUND) return (WT_NOTFOUND); ERET(session, WT_ERROR, "kvs_del: %s", kvs_strerror(ret)); }
/* * kvs_config_read -- * Read KVS configuration. */ static int kvs_config_read(WT_SESSION *session, WT_CONFIG_ARG *config, char ***devices, struct kvs_config *kvs_config, int *flagsp) { const KVS_OPTIONS *p; WT_CONFIG_ITEM v; int ret; char *t, name[128]; *flagsp = 0; /* Clear return values */ memset(kvs_config, 0, sizeof(*kvs_config)); ret = 0; for (p = kvs_options; p->name != NULL; ++p) { /* Truncate the name, discarding the trailing value. */ (void)snprintf(name, sizeof(name), "%s", p->name); if ((t = strchr(name, '=')) != NULL) *t = '\0'; if ((ret = wt_ext->config_get(wt_ext, session, config, name, &v)) != 0) ERET(session, ret, "WT_EXTENSION_API.config: %s: %s", name, wt_ext->strerror(ret)); if (strcmp(name, "kvs_devices") == 0) { if ((ret = kvs_config_devices(session, &v, devices)) != 0) return (ret); continue; } #define KVS_CONFIG_SET(n, f) \ if (strcmp(name, n) == 0) { \ kvs_config->f = (unsigned long)v.val; \ continue; \ } KVS_CONFIG_SET("kvs_parallelism", parallelism); KVS_CONFIG_SET("kvs_granularity", granularity); KVS_CONFIG_SET("kvs_avg_key_len", avg_key_len); KVS_CONFIG_SET("kvs_avg_val_len", avg_val_len); KVS_CONFIG_SET("kvs_write_bufs", write_bufs); KVS_CONFIG_SET("kvs_read_bufs", read_bufs); KVS_CONFIG_SET("kvs_commit_timeout", commit_timeout); KVS_CONFIG_SET("kvs_reclaim_threshold", reclaim_threshold); #define KVS_FLAG_SET(n, f) \ if (strcmp(name, n) == 0) { \ if (v.val != 0) \ *flagsp |= f; \ continue; \ } KVS_FLAG_SET("kvs_open_o_debug", KVS_O_DEBUG); KVS_FLAG_SET("kvs_open_o_reclaim", KVS_O_SCAN); KVS_FLAG_SET("kvs_open_o_scan", KVS_O_RECLAIM); } return (0); }
/* * writelock -- * Acquire a write lock. */ static INLINE int writelock(WT_SESSION *session, pthread_rwlock_t *lockp) { int ret; if ((ret = pthread_rwlock_wrlock(lockp)) != 0) ERET(session, WT_PANIC, "lock: %s", strerror(ret)); return (ret); }
/* * lock_destroy -- * Destroy an object's lock. */ static int lock_destroy(WT_SESSION *session, pthread_rwlock_t *lockp) { int ret; if ((ret = pthread_rwlock_destroy(lockp)) != 0) ERET(session, WT_PANIC, "lock destroy: %s", strerror(ret)); return (0); }
/* * unlock -- * Release an object's lock. */ static INLINE int unlock(WT_EXTENSION_API *wt_api, WT_SESSION *session, pthread_rwlock_t *lockp) { int ret = 0; if ((ret = pthread_rwlock_unlock(lockp)) != 0) ERET(wt_api, session, WT_PANIC, "unlock: %s", strerror(ret)); return (0); }
/* * lock_init -- * Initialize an object's lock. */ static int lock_init(WT_SESSION *session, pthread_rwlock_t *lockp) { int ret; if ((ret = pthread_rwlock_init(lockp, NULL)) != 0) ERET(session, WT_PANIC, "lock init: %s", strerror(ret)); return (ret); }
/* * kvs_session_verify -- * WT_SESSION::verify method. */ static int kvs_session_verify(WT_DATA_SOURCE *dsrc, WT_SESSION *session, const char *uri, WT_CONFIG_ARG *config) { (void)dsrc; /* Unused parameters */ (void)uri; (void)config; ERET(session, ENOTSUP, "verify: %s", strerror(ENOTSUP)); }
static int kvs_cursor_remove(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; dbc = cursor->dbc; key = &cursor->key; value = &cursor->value; /* * WiredTiger's "remove" of a bitfield is really an update with a value * of a single byte of zero. */ if (cursor->config_bitfield) { wtcursor->value.size = 1; wtcursor->value.data = "\0"; return (kvs_cursor_update(wtcursor)); } if ((ret = copyin_key(wtcursor)) != 0) return (ret); if ((ret = dbc->get(dbc, key, value, DB_SET)) != 0) { if (ret == DB_NOTFOUND || ret == DB_KEYEMPTY) return (WT_NOTFOUND); ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); } if ((ret = dbc->del(dbc, 0)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.del: %s", db_strerror(ret)); return (0); }
/* * lock_init -- * Initialize an object's lock. */ static int lock_init( WT_EXTENSION_API *wt_api, WT_SESSION *session, pthread_rwlock_t *lockp) { int ret = 0; if ((ret = pthread_rwlock_init(lockp, NULL)) != 0) ERET(wt_api, session, WT_PANIC, "lock init: %s", strerror(ret)); return (0); }
/* * wiredtiger_extension_init -- * Initialize the KVS connector code. */ int wiredtiger_extension_init(WT_CONNECTION *connection, WT_CONFIG_ARG *config) { static WT_DATA_SOURCE data_source; /* Enclosing data source */ int ret; (void)config; /* Unused parameters */ ret = 0; /* Acquire the extension API */ wt_ext = connection->get_extension_api(connection); /* Check the library version */ #if KVS_VERSION_MAJOR != 2 || KVS_VERSION_MINOR != 8 ERET(NULL, EINVAL, "unsupported KVS library version %d.%d", KVS_VERSION_MAJOR, KVS_VERSION_MINOR); #endif /* Initialize the WT_DATA_SOURCE structure. */ memset(&data_source, 0, sizeof(data_source)); data_source.create = kvs_session_create; data_source.compact = NULL; /* No compaction */ data_source.drop = kvs_session_drop; data_source.open_cursor = kvs_session_open_cursor; data_source.rename = kvs_session_rename; data_source.salvage = NULL; /* No salvage */ data_source.truncate = kvs_session_truncate; data_source.verify = kvs_session_verify; if ((ret = connection->add_data_source( connection, "memrata:", &data_source, NULL)) != 0) ERET(NULL, ret, "WT_CONNECTION.add_data_source: %s", wt_ext->strerror(ret)); /* Add the KVS-specific configuration options. */ if ((ret = kvs_config_add(connection)) != 0) return (ret); if ((ret = lock_init(NULL, &global_lock)) != 0) return (ret); return (0); }
/* * kvs_cursor_insert -- * WT_CURSOR::insert method. */ static int kvs_cursor_insert(WT_CURSOR *wt_cursor) { CURSOR *cursor; WT_SESSION *session; int ret; cursor = (CURSOR *)wt_cursor; session = cursor->session; ret = 0; /* Allocate a new record for append operations. */ if (cursor->config_append && (ret = kvs_recno_alloc(wt_cursor)) != 0) return (ret); if ((ret = copyin_key(wt_cursor)) != 0) return (ret); if ((ret = copyin_val(wt_cursor)) != 0) return (ret); /* * WT_CURSOR::insert with overwrite set (create the record if it does * not exist, update the record if it does exist), maps to kvs_set. * * WT_CURSOR::insert without overwrite set (create the record if it * does not exist, fail if it does exist), maps to kvs_add. */ if (cursor->config_overwrite) { if ((ret = kvs_set( cursor->data_source->kvs, &cursor->record)) != 0) ERET(session, WT_ERROR, "kvs_set: %s", kvs_strerror(ret)); } else if ((ret = kvs_add( cursor->data_source->kvs, &cursor->record)) != 0) { if (ret == KVS_E_KEY_EXISTS) return (WT_DUPLICATE_KEY); ERET(session, WT_ERROR, "kvs_add: %s", kvs_strerror(ret)); } return (0); }
static int uri2name(WT_EXTENSION_API *wt_api, WT_SESSION *session, const char *uri, const char **namep) { const char *name; if ((name = strchr(uri, ':')) == NULL || *++name == '\0') ERET(wt_api, session, EINVAL, "unsupported object: %s", uri); *namep = name; return (0); }
static int kvs_cursor_close(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DATA_SOURCE *ds; DB *db; DBC *dbc; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; ds = cursor->ds; wt_api = cursor->wt_api; dbc = cursor->dbc; cursor->dbc = NULL; if (dbc != NULL && (ret = dbc->close(dbc)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.close: %s", db_strerror(ret)); db = cursor->db; cursor->db = NULL; if (db != NULL && (ret = db->close(db, 0)) != 0) ERET(wt_api, session, WT_ERROR, "Db.close: %s", db_strerror(ret)); free(wtcursor); if ((ret = writelock(wt_api, session, &ds->rwlock)) != 0) return (ret); --ds->open_cursors; if ((ret = unlock(wt_api, session, &ds->rwlock)) != 0) return (ret); return (0); }
static int kvs_session_create(WT_DATA_SOURCE *wtds, WT_SESSION *session, const char *uri, WT_CONFIG_ARG *config) { DATA_SOURCE *ds; DB *db; DBTYPE type; WT_CONFIG_ITEM v; WT_EXTENSION_API *wt_api; int ret = 0; const char *name; ds = (DATA_SOURCE *)wtds; wt_api = ds->wt_api; /* Get the object name */ if ((ret = uri2name(wt_api, session, uri, &name)) != 0) return (ret); /* Check key/value formats */ if ((ret = wt_api->config_get(wt_api, session, config, "key_format", &v)) != 0) ERET(wt_api, session, ret, "key_format configuration: %s", wt_api->strerror(wt_api, session, ret)); type = v.len == 1 && v.str[0] == 'r' ? DB_RECNO : DB_BTREE; /* Create the Berkeley DB table */ if ((ret = db_create(&db, ds->dbenv, 0)) != 0) ERET(wt_api, session, WT_ERROR, "db_create: %s", db_strerror(ret)); if ((ret = db->open(db, NULL, name, NULL, type, DB_CREATE, 0)) != 0) ERET(wt_api, session, WT_ERROR, "Db.open: %s", uri, db_strerror(ret)); if ((ret = db->close(db, 0)) != 0) ERET(wt_api, session, WT_ERROR, "Db.close", db_strerror(ret)); return (0); }
static int bdb_dump(WT_CURSOR *wtcursor, WT_SESSION *session, const char *tag) { CURSOR_SOURCE *cursor; DB *db; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; int ret = 0; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; db = cursor->db; key = &cursor->key; value = &cursor->value; if ((ret = db->cursor(db, NULL, &dbc, 0)) != 0) ERET(wt_api, session, WT_ERROR, "Db.cursor: %s", db_strerror(ret)); printf("==> %s\n", tag); while ((ret = dbc->get(dbc, key, value, DB_NEXT)) == 0) if (cursor->config_recno) printf("\t%llu/%.*s\n", (unsigned long long)*(db_recno_t *)key->data, (int)value->size, (char *)value->data); else printf("\t%.*s/%.*s\n", (int)key->size, (char *)key->data, (int)value->size, (char *)value->data); if (ret != DB_NOTFOUND) ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); return (0); }
static INLINE int recno_convert(WT_CURSOR *wtcursor, db_recno_t *recnop) { CURSOR_SOURCE *cursor; WT_EXTENSION_API *wt_api; WT_SESSION *session; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; if (wtcursor->recno > UINT32_MAX) ERET(wt_api, session, ERANGE, "record number %" PRIuMAX ": %s", (uintmax_t)wtcursor->recno, strerror(ERANGE)); *recnop = (uint32_t)wtcursor->recno; return (0); }
/* * copy_key -- * Copy the key for methods where the underlying KVS call returns a key. */ static INLINE int copy_key(WT_CURSOR *wt_cursor) { struct kvs_record *r; CURSOR *cursor; WT_SESSION *session; cursor = (CURSOR *)wt_cursor; session = cursor->session; r = &cursor->record; if (cursor->key == r->key) return (0); if (r->key_len > sizeof(cursor->key)) ERET(session, ERANGE, "key too large, maximum is %" PRIuMAX, (uintmax_t)sizeof(cursor->key)); memcpy(cursor->key, r->key, r->key_len); r->key = cursor->key; return (0); }
/* * kvs_config_add -- * Add the KVS configuration options to the WiredTiger configuration * process. */ static int kvs_config_add(WT_CONNECTION *conn) { const KVS_OPTIONS *p; int ret; ret = 0; /* * KVS options are currently only allowed on session.create, which means * they cannot be modified for each run, the object create configuration * is permanent. */ for (p = kvs_options; p->name != NULL; ++p) if ((ret = conn->configure_method(conn, "session.create", "memrata:", p->name, p->type, p->checks)) != 0) ERET(NULL, ret, "WT_CONNECTION.configure_method: session.create: " "{%s, %s, %s}", p->name, p->type, p->checks, wt_ext->strerror(ret)); return (0); }
/* * kvs_cursor_update -- * WT_CURSOR::update method. */ static int kvs_cursor_update(WT_CURSOR *wt_cursor) { CURSOR *cursor; WT_SESSION *session; int ret; cursor = (CURSOR *)wt_cursor; session = cursor->session; if ((ret = copyin_key(wt_cursor)) != 0) return (ret); if ((ret = copyin_val(wt_cursor)) != 0) return (ret); /* * WT_CURSOR::update (update the record if it does exist, fail if it * does not exist), maps to kvs_replace. */ if ((ret = kvs_replace(cursor->data_source->kvs, &cursor->record)) != 0) ERET(session, WT_ERROR, "kvs_replace: %s", kvs_strerror(ret)); return (0); }
// get_player_information() int ModApiServer::l_get_player_information(lua_State *L) { NO_MAP_LOCK_REQUIRED; const char * name = luaL_checkstring(L, 1); Player *player = getEnv(L)->getPlayer(name); if(player == NULL) { lua_pushnil(L); // no such player return 1; } Address addr; try { addr = getServer(L)->getPeerAddress(player->peer_id); } catch(con::PeerNotFoundException) // unlikely { dstream << FUNCTION_NAME << ": peer was not found" << std::endl; lua_pushnil(L); // error return 1; } float min_rtt,max_rtt,avg_rtt,min_jitter,max_jitter,avg_jitter; ClientState state; u32 uptime; u16 prot_vers; u8 ser_vers,major,minor,patch; std::string vers_string; #define ERET(code) \ if (!(code)) { \ dstream << FUNCTION_NAME << ": peer was not found" << std::endl; \ lua_pushnil(L); /* error */ \ return 1; \ } ERET(getServer(L)->getClientConInfo(player->peer_id,con::MIN_RTT,&min_rtt)) ERET(getServer(L)->getClientConInfo(player->peer_id,con::MAX_RTT,&max_rtt)) ERET(getServer(L)->getClientConInfo(player->peer_id,con::AVG_RTT,&avg_rtt)) ERET(getServer(L)->getClientConInfo(player->peer_id,con::MIN_JITTER,&min_jitter)) ERET(getServer(L)->getClientConInfo(player->peer_id,con::MAX_JITTER,&max_jitter)) ERET(getServer(L)->getClientConInfo(player->peer_id,con::AVG_JITTER,&avg_jitter)) ERET(getServer(L)->getClientInfo(player->peer_id, &state, &uptime, &ser_vers, &prot_vers, &major, &minor, &patch, &vers_string)) lua_newtable(L); int table = lua_gettop(L); lua_pushstring(L,"address"); lua_pushstring(L, addr.serializeString().c_str()); lua_settable(L, table); lua_pushstring(L,"ip_version"); if (addr.getFamily() == AF_INET) { lua_pushnumber(L, 4); } else if (addr.getFamily() == AF_INET6) { lua_pushnumber(L, 6); } else { lua_pushnumber(L, 0); } lua_settable(L, table); lua_pushstring(L,"min_rtt"); lua_pushnumber(L, min_rtt); lua_settable(L, table); lua_pushstring(L,"max_rtt"); lua_pushnumber(L, max_rtt); lua_settable(L, table); lua_pushstring(L,"avg_rtt"); lua_pushnumber(L, avg_rtt); lua_settable(L, table); lua_pushstring(L,"min_jitter"); lua_pushnumber(L, min_jitter); lua_settable(L, table); lua_pushstring(L,"max_jitter"); lua_pushnumber(L, max_jitter); lua_settable(L, table); lua_pushstring(L,"avg_jitter"); lua_pushnumber(L, avg_jitter); lua_settable(L, table); lua_pushstring(L,"connection_uptime"); lua_pushnumber(L, uptime); lua_settable(L, table); #ifndef NDEBUG lua_pushstring(L,"serialization_version"); lua_pushnumber(L, ser_vers); lua_settable(L, table); lua_pushstring(L,"protocol_version"); lua_pushnumber(L, prot_vers); lua_settable(L, table); lua_pushstring(L,"major"); lua_pushnumber(L, major); lua_settable(L, table); lua_pushstring(L,"minor"); lua_pushnumber(L, minor); lua_settable(L, table); lua_pushstring(L,"patch"); lua_pushnumber(L, patch); lua_settable(L, table); lua_pushstring(L,"version_string"); lua_pushstring(L, vers_string.c_str()); lua_settable(L, table); lua_pushstring(L,"state"); lua_pushstring(L,ClientInterface::state2Name(state).c_str()); lua_settable(L, table); #endif #undef ERET return 1; }
_er90b_open(char *fname, int oflag, int mode, struct fdinfo *fio, union spec_u *spec, struct ffsw *retstat, int cbits, int cblks, struct gl_o_inf *oinf) { int fd; /* file descriptor */ ER90BYT *er90b_info; struct tpdctl ctl; struct stat x; int save_err; /* * allocate *ER90BYT */ if((er90b_info = (ER90BYT *)calloc(sizeof(*er90b_info),1))==NULL){ ERETURN(retstat, FENOMEMY, 0); } if ((_numargs() > 8 ) && oinf->alreadyopen) { fd = oinf->fd; } else { /* * Open the file. */ oflag = (oflag | O_RAW) & (~O_CREAT); fd = open(fname, oflag, 0666); if (fd < 0){ free(er90b_info); ERETURN(retstat, errno, 0); } } #ifndef _CRAYMPP /* This ioctl does not work on the MPP */ if ( ioctl( fd, TPC_GETFL, &ctl) < 0 ){ /* If ioctl fails with ENOTTY, then this */ /* isn't a tape file. Make the errno more meaningful */ if (errno == ENOTTY) errno = FECONNTP; ERET(); } /* * If this is not a byte-stream ER90, error */ if ((ctl.tpc_type != DT_ER90) || (ctl.tpc_dbsize != 1)) { errno = FDC_ERR_NOER90; ERET(); } #endif er90b_info->tpos = TPOS_DONE; er90b_info->fd = fd; /* * Save device number and inode for tapeinfo requests */ if (fstat(fd, &x) < 0){ ERET(); } #ifdef _CRAYMPP if (_gsys_qtape(&x) == 0) { errno = FECONNTP; ERET(); } if (getenv("NOER90WARN")== NULL) { write(2,"Reads and writes to tape devices using the er90 layer\n",54); write(2,"may function differently than reads and writes using\n",53); write(2,"the tape layer.\n",16); write(2,"The use of the er90 layer with tape devices may not be\n",55); write(2,"supported in future releases.\n",30); write(2,"To disable this message, set the environment variable\n",54); write(2,"NOER90WARN to a non-zero value\n",31); } #endif er90b_info->tsireq.st_dev = x.st_dev; er90b_info->tsireq.st_ino = x.st_ino; er90b_info->tsireq.fd = fd; #ifndef _CRAYMPP /* Can't use an ioctl on MPP yet. */ if (sysconf(_SC_CRAY_RELEASE) >= 8300) { /* With operating system versions >= 8300, we can */ /* use an ioctl to get tape info. Er90s only run on Model E IOS, */ /* so this is safe. */ er90b_info->tsireq.ioctlreq = 1; } #endif fio->lyr_info = (char *)er90b_info; fio->realfd = fd; fio->rwflag = POSITIN; SETSTAT(retstat, 0, 0); return(0); badret: save_err = errno; free(er90b_info); (void) close(fd); errno = save_err; ERETURN(retstat, errno, 0); }
static int kvs_cursor_search_near(WT_CURSOR *wtcursor, int *exact) { CURSOR_SOURCE *cursor; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; WT_SESSION *session; size_t len; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; dbc = cursor->dbc; key = &cursor->key; value = &cursor->value; if ((ret = copyin_key(wtcursor)) != 0) return (ret); retry: if ((ret = dbc->get(dbc, key, value, DB_SET_RANGE)) == 0) { /* * WiredTiger returns the logically adjacent key (which might * be less than, equal to, or greater than the specified key), * Berkeley DB returns a key equal to or greater than the * specified key. Check for an exact match, otherwise Berkeley * DB must have returned a larger key than the one specified. */ if (key->size == wtcursor->key.size && memcmp(key->data, wtcursor->key.data, key->size) == 0) *exact = 0; else *exact = 1; copyout_key(wtcursor); copyout_value(wtcursor); return (0); } /* * Berkeley DB only returns keys equal to or greater than the specified * key, while WiredTiger returns adjacent keys, that is, if there's a * key smaller than the specified key, it's supposed to be returned. In * other words, WiredTiger only fails if the store is empty. Read the * last key in the store, and see if it's less than the specified key, * in which case we have the right key to return. If it's not less than * the specified key, we're racing with some other thread, throw up our * hands and try again. */ if ((ret = dbc->get(dbc, key, value, DB_LAST)) == 0) { len = key->size < wtcursor->key.size ? key->size : wtcursor->key.size; if (memcmp(key->data, wtcursor->key.data, len) < 0) { *exact = -1; copyout_key(wtcursor); copyout_value(wtcursor); return (0); } goto retry; } if (ret == DB_NOTFOUND || ret == DB_KEYEMPTY) return (WT_NOTFOUND); ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); }
static int kvs_cursor_insert(WT_CURSOR *wtcursor) { CURSOR_SOURCE *cursor; DB *db; DBC *dbc; DBT *key, *value; WT_EXTENSION_API *wt_api; WT_SESSION *session; int ret = 0; session = wtcursor->session; cursor = (CURSOR_SOURCE *)wtcursor; wt_api = cursor->wt_api; dbc = cursor->dbc; db = cursor->db; key = &cursor->key; value = &cursor->value; if ((ret = copyin_key(wtcursor)) != 0) return (ret); copyin_value(wtcursor); if (cursor->config_append) { /* * Berkeley DB cursors have no operation to append/create a * new record and set the cursor; use the DB handle instead * then set the cursor explicitly. * * When appending, we're allocating and returning a new record * number. */ if ((ret = db->put(db, NULL, key, value, DB_APPEND)) != 0) ERET(wt_api, session, WT_ERROR, "Db.put: %s", db_strerror(ret)); wtcursor->recno = *(db_recno_t *)key->data; if ((ret = dbc->get(dbc, key, value, DB_SET)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); } else if (cursor->config_overwrite) { if ((ret = dbc->put(dbc, key, value, DB_KEYFIRST)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.put: %s", db_strerror(ret)); } else { /* * Berkeley DB cursors don't have a no-overwrite flag; use * the DB handle instead then set the cursor explicitly. */ if ((ret = db->put(db, NULL, key, value, DB_NOOVERWRITE)) != 0) { if (ret == DB_KEYEXIST) return (WT_DUPLICATE_KEY); ERET(wt_api, session, WT_ERROR, "Db.put: %s", db_strerror(ret)); } if ((ret = dbc->get(dbc, key, value, DB_SET)) != 0) ERET(wt_api, session, WT_ERROR, "DbCursor.get: %s", db_strerror(ret)); } return (0); }