File: test_writeatomic16_vpd.c

package info (click to toggle)
libiscsi 1.20.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,080 kB
  • sloc: ansic: 40,928; xml: 749; sh: 689; makefile: 352
file content (135 lines) | stat: -rw-r--r-- 6,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
   Copyright (C) 2015 by Ronnie Sahlberg <sahlberg@gmail.com>

   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 <stdlib.h>
#include <string.h>

#include <CUnit/CUnit.h>

#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"

void
test_writeatomic16_vpd(void)
{
        int ret;
        struct scsi_inquiry_block_limits *bl;
        struct scsi_task *bl_task = NULL;
        int gran;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test WRITEATOMIC16 VPD data");

        CHECK_FOR_SBC;
        CHECK_FOR_DATALOSS;


        logging(LOG_VERBOSE, "Block device. Verify that we can read Block "
                "Limits VPD");
        ret = inquiry(sd, &bl_task,
                      1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 255,
                      EXPECT_STATUS_GOOD);
        CU_ASSERT_EQUAL(ret, 0);
        if (ret != 0) {
                logging(LOG_NORMAL, "[FAILURE] failed to read Block Limits VDP");
                CU_FAIL("[FAILURE] failed to read Block Limits VDP");
                goto finished;
        }
        bl = scsi_datain_unmarshall(bl_task);
        if (bl == NULL) {
                logging(LOG_NORMAL, "[FAILURE] failed to unmarshall Block Limits VDP");
                CU_FAIL("[FAILURE] failed to unmarshall Block Limits VDP");
                goto finished;
        }


        logging(LOG_VERBOSE, "Check if WRITEATOMIC16 is supported");
        gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
        memset(scratch   , 0x00, block_size * gran);
        ret = writeatomic16(sd, 0, block_size * gran,
                            block_size, 0, 0, 0, 0, scratch,
                            EXPECT_STATUS_GOOD);
        if (ret == -2) {
                logging(LOG_VERBOSE, "WRITEATOMIC16 is NOT supported by the target.");

                logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero");
                if (bl->max_atomic_xfer_len) {
                        logging(LOG_VERBOSE, "MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16");
                        CU_FAIL("MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16");
                }

                logging(LOG_VERBOSE, "Verify that ATOMIC_ALIGNMENT is zero");
                if (bl->atomic_align) {
                        logging(LOG_VERBOSE, "ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16");
                        CU_FAIL("ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16");
                }

                logging(LOG_VERBOSE, "Verify that ATOMIC_GRANULARITY is zero");
                if (bl->atomic_gran) {
                        logging(LOG_VERBOSE, "ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16");
                        CU_FAIL("ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16");
                }
                goto finished;
        }

        logging(LOG_VERBOSE, "WRITEATOMIC16 IS supported by the target.");
        logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero");
        if (!bl->max_atomic_xfer_len) {
                logging(LOG_VERBOSE, "[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16");
                CU_FAIL("[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16");
        }

        logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is less than or equal to MAXIMUM_TRANSFER_LENGTH");
        if (bl->max_atomic_xfer_len > bl->max_xfer_len) {
                logging(LOG_VERBOSE, "[FAILED] MAXIMUM_ATOMIC_TRANSFER_LENGTH is greater than MAXIMUM_TRANSFER_LENGTH");
                CU_FAIL("[FAILED] MAXIMUM_ATOMIC_TRANSFER_LENGTH is greater than MAXIMUM_TRANSFER_LENGTH");
        }

        logging(LOG_VERBOSE, "Check handling on misaligned writes");
        if (bl->atomic_align < 2) {
                logging(LOG_VERBOSE, "[SKIPPED] No alignment restrictions on this LUN");
        } else {
                logging(LOG_VERBOSE, "Atomic Write at LBA 1 should fail due to misalignment");
                ret = writeatomic16(sd, 1, block_size * gran,
                                    block_size, 0, 0, 0, 0, scratch,
                                    EXPECT_INVALID_FIELD_IN_CDB);
                if (ret) {
                        logging(LOG_VERBOSE, "[FAILED] Misaligned write did NOT fail with INVALID_FIELD_IN_CDB");
                CU_FAIL("[FAILED] Misaligned write did NOT fail with INVALID_FIELD_IN_CDB");
                }
        }

        logging(LOG_VERBOSE, "Check handling on invalid granularity");
        if (bl->atomic_gran < 2) {
                logging(LOG_VERBOSE, "[SKIPPED] No granularity restrictions on this LUN");
        } else {
                logging(LOG_VERBOSE, "Atomic Write of 1 block should fail due to invalid granularity");
                ret = writeatomic16(sd, 0, block_size,
                                    block_size, 0, 0, 0, 0, scratch,
                                    EXPECT_INVALID_FIELD_IN_CDB);
                if (ret) {
                        logging(LOG_VERBOSE, "[FAILED] Misgranularity write did NOT fail with INVALID_FIELD_IN_CDB");
                CU_FAIL("[FAILED] Misgranularity write did NOT fail with INVALID_FIELD_IN_CDB");
                }
        }


finished:
        scsi_free_scsi_task(bl_task);
}