Lines Matching defs:db
234 static int init_tsock(CNID_private *db)
241 db->db_dir, db->cnidserver, db->cnidport);
243 if ((fd = tsock_getfd(db->cnidserver, db->cnidport)) < 0)
246 len = strlen(db->db_dir);
251 iov[1].iov_base = db->db_dir;
266 static int send_packet(CNID_private *db, struct cnid_dbd_rqst *rqst)
284 if (write_vec(db->fd, iov, towrite, vecs) != towrite) {
286 db->db_dir, strerror(errno));
322 static int dbd_rpc(CNID_private *db, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
328 if (send_packet(db, rqst) < 0) {
334 ret = readt(db->fd, rply, sizeof(struct cnid_dbd_rply), 0, ONE_DELAY);
338 db->db_dir, ret == -1 ? strerror(errno) : "closed");
346 db->db_dir, rply->name, rply->namelen, len);
349 if (rply->namelen && (ret = readt(db->fd, rply->name, rply->namelen, 0, ONE_DELAY)) != (ssize_t)rply->namelen) {
351 db->db_dir, ret == -1?strerror(errno):"closed");
361 static int transmit(CNID_private *db, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
366 if (db->changed) {
367 /* volume and db don't have the same timestamp
372 if (db->fd == -1) {
378 if ((db->fd = init_tsock(db)) < 0) {
386 if (dbd_rpc(db, &rqst_stamp, &rply_stamp) < 0)
391 if (db->notfirst) {
393 if (memcmp(stamp, db->stamp, ADEDLEN_PRIVSYN)) {
394 LOG(log_error, logtype_cnid, "transmit: ... not the same db!");
395 db->changed = 1;
399 } else { /* db->notfirst == 0 */
400 db->notfirst = 1;
401 if (db->client_stamp)
402 memcpy(db->client_stamp, stamp, ADEDLEN_PRIVSYN);
403 memcpy(db->stamp, stamp, ADEDLEN_PRIVSYN);
406 db->db_dir, *(uint64_t *)stamp);
408 if (!dbd_rpc(db, rqst, rply)) {
413 if (db->fd != -1) {
414 close(db->fd);
415 db->fd = -1; /* FD not valid... will need to reconnect */
420 LOG(log_error, logtype_cnid, "transmit: connection refused (db_dir %s)", db->db_dir);
427 LOG(log_error, logtype_cnid, "transmit: Request to dbd daemon (db_dir %s) timed out.", db->db_dir);
473 CNID_private *db = NULL;
485 if ((db = (CNID_private *)calloc(1, sizeof(CNID_private))) == NULL) {
490 cdb->_private = db;
492 /* We keep a copy of the directory in the db structure so that we can
494 strcpy(db->db_dir, args->dir);
495 db->magic = CNID_DB_MAGIC;
496 db->fd = -1;
497 db->cnidserver = strdup(args->cnidserver);
498 db->cnidport = strdup(args->cnidport);
500 LOG(log_debug, logtype_cnid, "cnid_dbd_open: Finished initializing cnid dbd module for volume '%s'", db->db_dir);
511 if (db != NULL)
512 free(db);
520 CNID_private *db;
527 if ((db = cdb->_private) != NULL) {
528 LOG(log_debug, logtype_cnid, "closing database connection for volume '%s'", db->db_dir);
530 if (db->fd >= 0)
531 close(db->fd);
532 free(db);
546 CNID_private *db;
551 if (!cdb || !(db = cdb->_private) || !st || !name) {
581 if (transmit(db, &rqst, &rply) < 0) {
610 CNID_private *db;
615 if (!cdb || !(db = cdb->_private) || !name) {
636 if (transmit(db, &rqst, &rply) < 0) {
663 CNID_private *db;
668 if (!cdb || !(db = cdb->_private) || !id || !(*id)) {
689 if (transmit(db, &rqst, &rply) < 0) {
720 CNID_private *db;
722 if (!cdb || !(db = cdb->_private) || len != ADEDLEN_PRIVSYN) {
727 db->client_stamp = buffer;
728 db->stamp_size = len;
737 CNID_private *db;
742 if (!cdb || !(db = cdb->_private) || !st || !name) {
771 if (transmit(db, &rqst, &rply) < 0) {
798 CNID_private *db;
803 if (!cdb || !(db = cdb->_private) || !name) {
826 if (transmit(db, &rqst, &rply) < 0) {
854 CNID_private *db;
858 if (!cdb || !(db = cdb->_private) || !id || !st || !name) {
886 if (transmit(db, &rqst, &rply) < 0) {
909 CNID_private *db;
914 if (!cdb || !(db = cdb->_private) || !st || !name || hint == CNID_INVALID) {
943 if (transmit(db, &rqst, &rply) < 0) {
971 CNID_private *db;
975 if (!cdb || !(db = cdb->_private) || !id) {
988 if (transmit(db, &rqst, &rply) < 0) {