plugins/nbd/nbd.c
/* Perform the request half of a transaction. On success, return the
   non-negative fd for reading the reply; on error return -1. */
Perform the request half of a transaction. On success, return the
non-negative fd for reading the reply; on error return -1.
Perform the request half of a transaction . On success return the non - negative fd for reading the reply ; on error return - 1 .
static int
nbd_request_full (struct handle *h, uint16_t flags, uint16_t type,
                  uint64_t offset, uint32_t count, const void *req_buf,
                  void *rep_buf)
{
  int err;
  struct transaction *trans;
  int fd;
  uint64_t cookie;
  trans = calloc (1, sizeof *trans);
  if (!trans) {
    nbdkit_error ("unable to track transaction: %m");
    return -1;
  }
  if (pipe (trans->u.fds)) {
    nbdkit_error ("unable to create pipe: %m");
    free (trans);
    return -1;
  }
  trans->buf = rep_buf;
  trans->count = rep_buf ? count : 0;
  nbd_lock (h);
  if (h->dead) {
    nbd_unlock (h);
    goto err;
  }
  trans->next = h->trans;
  h->trans = trans;
  fd = trans->u.fds[0];
  cookie = trans->u.cookie;
  nbd_unlock (h);
  if (nbd_request_raw (h, flags, type, offset, count, cookie, req_buf) == 0)
    return fd;
  trans = find_trans_by_cookie (h, cookie);
 err:
  err = errno;
  if (trans) {
    close (trans->u.fds[0]);
    close (trans->u.fds[1]);
    free (trans);
  }
  else
    close (fd);
  errno = err;
  return nbd_mark_dead (h);
}
static int nbd_request_full ( struct handle * h , uint16_t flags , uint16_t type , uint64_t offset , uint32_t count , const void * req_buf , void * rep_buf ) { int err ; struct transaction * trans ; int fd ; uint64_t cookie ; trans = calloc ( 1 , sizeof * trans ) ; if ( ! trans ) { nbdkit_error ( " " ) ; return -1 ; } if ( pipe ( trans -> u . fds ) ) { nbdkit_error ( " " ) ; free ( trans ) ; return -1 ; } trans -> buf = rep_buf ; trans -> count = rep_buf ? count : 0 ; nbd_lock ( h ) ; if ( h -> dead ) { nbd_unlock ( h ) ; goto err ; } trans -> next = h -> trans ; h -> trans = trans ; fd = trans -> u . fds [ 0 ] ; cookie = trans -> u . cookie ; nbd_unlock ( h ) ; if ( nbd_request_raw ( h , flags , type , offset , count , cookie , req_buf ) == 0 ) return fd ; trans = find_trans_by_cookie ( h , cookie ) ; err : err = errno ; if ( trans ) { close ( trans -> u . fds [ 0 ] ) ; close ( trans -> u . fds [ 1 ] ) ; free ( trans ) ; } else close ( fd ) ; errno = err ; return nbd_mark_dead ( h ) ; }
Perform the request half of a transaction.
Perform the request half of a transaction .
/* Still in sync with server, so don't mark connection dead */ /* Still in sync with server, so don't mark connection dead */