From patchwork Fri Dec 3 11:09:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ronnie sahlberg X-Patchwork-Id: 74109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B97FAB70A9 for ; Fri, 3 Dec 2010 22:17:03 +1100 (EST) Received: from localhost ([127.0.0.1]:41751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POTdK-00033H-Ps for incoming@patchwork.ozlabs.org; Fri, 03 Dec 2010 06:16:58 -0500 Received: from [140.186.70.92] (port=58877 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POTXp-0001Vo-SV for qemu-devel@nongnu.org; Fri, 03 Dec 2010 06:11:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POTXo-0002fB-Ik for qemu-devel@nongnu.org; Fri, 03 Dec 2010 06:11:17 -0500 Received: from mail-gy0-f173.google.com ([209.85.160.173]:62863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POTXo-0002f4-EK for qemu-devel@nongnu.org; Fri, 03 Dec 2010 06:11:16 -0500 Received: by gye5 with SMTP id 5so5066682gye.4 for ; Fri, 03 Dec 2010 03:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=J4XV4Rnp+xFR1KMCs+NHaHL4a9FZ7c1KDDwvvPRVExc=; b=NiiQdj9IGdxZT7CHqH59fQKBh81zjTSxSk1uSLRyHVyT4pTFj3Kgv5UkYt9yUfkU6N Six11TGD7tt6G0r6t6ZJ6L5RHVIW7zn/CNPwoIIykQcjTPmbJR8aOZsjvzA1IRovTnFY w8CuOiGaCYBdRRshoETDmFk4ziIX8/aD5Kkl0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=rzgKIcAlbvPzYn9ad+gCbmNzK9YjAf3P6KZcNfGJl0g2XWIMpbOvEYpOlACPlsl6zI P3szDFIcGeFNp/kLPxlc1zq2oU3qRA13rFfRUPvv6FT/oCWx0v4KLTZXCYOW7ZXQpFmr 5GooWSh8ZLnjPi8VUtpFPJfuk+wOxGy+xUfrQ= Received: by 10.151.153.10 with SMTP id f10mr3605177ybo.21.1291374674690; Fri, 03 Dec 2010 03:11:14 -0800 (PST) Received: from ronniesahlberg@gmail.com (CPE-121-216-183-74.lnse2.ken.bigpond.net.au [121.216.183.74]) by mx.google.com with ESMTPS id v12sm1190375ybk.11.2010.12.03.03.11.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 03 Dec 2010 03:11:14 -0800 (PST) Received: by ronniesahlberg@gmail.com (sSMTP sendmail emulation); Fri, 03 Dec 2010 22:10:46 +1100 From: ronniesahlberg@gmail.com To: qemu-devel@nongnu.org Date: Fri, 3 Dec 2010 22:09:45 +1100 Message-Id: <1291374593-17448-7-git-send-email-ronniesahlberg@gmail.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1291374593-17448-1-git-send-email-ronniesahlberg@gmail.com> References: <1291374593-17448-1-git-send-email-ronniesahlberg@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Ronnie Sahlberg Subject: [Qemu-devel] [PATCH 06/14] ./block/iscsi/nop.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ronnie Sahlberg 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 --- 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 + + 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 . +*/ + +#include +#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; +}