qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 06/14] ./block/iscsi/nop.c


From: ronniesahlberg
Subject: [Qemu-devel] [PATCH 06/14] ./block/iscsi/nop.c
Date: Fri, 3 Dec 2010 22:09:45 +1100

From: Ronnie Sahlberg <address@hidden>

iscsi  client library  : nop.c
This file contains functions for processing of initiator initiated
NOP exchanges.
While target initiated exchanged look virtually identical, these
are not implemented.

TGTD iscsin target does not use target initiated nop exchanges
but other targets may.

...

./block/iscsi/ contains a copy of a general purpose iscsi client
library which is aimed at providing a clientside api for iscsi
for both qemu/kvm as well as otther scsi related utilities.

As such, there is need to make merging across various consumers,
qemu/kvm being one of many here, as easy as possible when features
are added to the library.
As such, no consumer/qemu specific code is used in this library as well
as coding guidelined might not be adhered to 100%

It is the intention that this library will be useful for many
and that iscsi use spawned from this will flourish.

Signed-off-by: Ronnie Sahlberg <address@hidden>
---
 block/iscsi/nop.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 block/iscsi/nop.c

diff --git a/block/iscsi/nop.c b/block/iscsi/nop.c
new file mode 100644
index 0000000..8cbbc2a
--- /dev/null
+++ b/block/iscsi/nop.c
@@ -0,0 +1,91 @@
+/*
+   Copyright (C) 2010 by Ronnie Sahlberg <address@hidden>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include "iscsi.h"
+#include "iscsi-private.h"
+
+int
+iscsi_nop_out_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
+                   unsigned char *data, int len, void *private_data)
+{
+       struct iscsi_pdu *pdu;
+
+       if (iscsi->is_loggedin == 0) {
+               iscsi_set_error(iscsi, "trying send nop-out while not logged "
+                               "in");
+               return -2;
+       }
+
+       pdu = iscsi_allocate_pdu(iscsi, ISCSI_PDU_NOP_OUT, ISCSI_PDU_NOP_IN);
+       if (pdu == NULL) {
+               iscsi_set_error(iscsi, "Failed to allocate nop-out pdu");
+               return -3;
+       }
+
+       /* immediate flag */
+       iscsi_pdu_set_immediate(pdu);
+
+       /* flags */
+       iscsi_pdu_set_pduflags(pdu, 0x80);
+
+       /* ttt */
+       iscsi_pdu_set_ttt(pdu, 0xffffffff);
+
+       /* lun */
+       iscsi_pdu_set_lun(pdu, 2);
+
+       /* cmdsn is not increased if Immediate delivery*/
+       iscsi_pdu_set_cmdsn(pdu, iscsi->cmdsn);
+       pdu->cmdsn = iscsi->cmdsn;
+
+       pdu->callback     = cb;
+       pdu->private_data = private_data;
+
+       if (iscsi_pdu_add_data(iscsi, pdu, data, len) != 0) {
+               iscsi_set_error(iscsi, "Failed to add outdata to nop-out");
+               iscsi_free_pdu(iscsi, pdu);
+               return -4;
+       }
+
+
+       if (iscsi_queue_pdu(iscsi, pdu) != 0) {
+               iscsi_set_error(iscsi, "failed to queue iscsi nop-out pdu");
+               iscsi_free_pdu(iscsi, pdu);
+               return -5;
+       }
+
+       return 0;
+}
+
+int
+iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
+                           const unsigned char *hdr, int size)
+{
+       struct iscsi_data data;
+
+       data.data = NULL;
+       data.size = 0;
+
+       if (size > ISCSI_HEADER_SIZE) {
+               data.data = discard_const(&hdr[ISCSI_HEADER_SIZE]);
+               data.size = size - ISCSI_HEADER_SIZE;
+       }
+       pdu->callback(iscsi, SCSI_STATUS_GOOD, &data, pdu->private_data);
+
+       return 0;
+}
-- 
1.7.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]