-static int
-vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd,
- struct iovec *iov,
- int niov,
- bool write)
-{
- struct scatterlist *sg = cmd->tvc_sgl;
- unsigned int sgl_count = 0;
- int ret, i;
-
- for (i = 0; i < niov; i++)
- sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len);
-
- if (sgl_count > TCM_VHOST_PREALLOC_SGLS) {
- pr_err("vhost_scsi_map_iov_to_sgl() sgl_count: %u greater than"
- " preallocated TCM_VHOST_PREALLOC_SGLS: %u\n",
- sgl_count, TCM_VHOST_PREALLOC_SGLS);
- return -ENOBUFS;
- }
-
- pr_debug("%s sg %p sgl_count %u\n", __func__, sg, sgl_count);
- sg_init_table(sg, sgl_count);
- cmd->tvc_sgl_count = sgl_count;
-
- pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count);
-
- for (i = 0; i < niov; i++) {
- ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len,
- sg, write);
- if (ret < 0) {
- for (i = 0; i < cmd->tvc_sgl_count; i++) {
- struct page *page = sg_page(&cmd->tvc_sgl[i]);
- if (page)
- put_page(page);
- }
- cmd->tvc_sgl_count = 0;
- return ret;
- }
- sg += ret;
- sgl_count -= ret;
- }
- return 0;
-}
-
-static int
-vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd,
- struct iovec *iov,
- int niov,
- bool write)
-{
- struct scatterlist *prot_sg = cmd->tvc_prot_sgl;
- unsigned int prot_sgl_count = 0;
- int ret, i;
-
- for (i = 0; i < niov; i++)
- prot_sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len);
-
- if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) {
- pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than"
- " preallocated TCM_VHOST_PREALLOC_PROT_SGLS: %u\n",
- prot_sgl_count, TCM_VHOST_PREALLOC_PROT_SGLS);
- return -ENOBUFS;
- }
-
- pr_debug("%s prot_sg %p prot_sgl_count %u\n", __func__,
- prot_sg, prot_sgl_count);
- sg_init_table(prot_sg, prot_sgl_count);
- cmd->tvc_prot_sgl_count = prot_sgl_count;
-
- for (i = 0; i < niov; i++) {
- ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len,
- prot_sg, write);
- if (ret < 0) {
- for (i = 0; i < cmd->tvc_prot_sgl_count; i++) {
- struct page *page = sg_page(&cmd->tvc_prot_sgl[i]);
- if (page)
- put_page(page);
- }
- cmd->tvc_prot_sgl_count = 0;
- return ret;
- }
- prot_sg += ret;
- prot_sgl_count -= ret;
- }
- return 0;
-}
-