Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 246961 Details for
Bug 364421
Kernel panic when using sg driver to write
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
source file that exhibits failure
sglib.c (text/plain), 13.95 KB, created by
Sean Bruno
on 2007-11-02 18:55:59 UTC
(
hide
)
Description:
source file that exhibits failure
Filename:
MIME Type:
Creator:
Sean Bruno
Created:
2007-11-02 18:55:59 UTC
Size:
13.95 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <scsi/sg.h> >#include <sys/ioctl.h> >#include "sg_err.c" >#include <errno.h> > >#define INQ_REPLY_LEN 96 >#define INQ_CMD_CODE 0x12 >#define INQ_CMD_LEN 6 >#define SENSE_BUFF_LEN 32 /* Arbitrary, could be larger */ >#define DEF_TIMEOUT 40000 /* 40,000 millisecs == 40 seconds */ >#ifndef SG_FLAG_MMAP_IO >#define SG_FLAG_MMAP_IO 4 >#endif > >static int pack_id_count = 0; >static int sum_of_resids = 0; > >int isSgDev (int fd) > { > int k; > if ((ioctl (fd, SG_GET_VERSION_NUM, & k) < 0) || (k < 30000)) > return -1; > return 0; > } > >int reportScsiId (int fd) > { > int rc; > struct sg_scsi_id sgScsiId; > rc = ioctl (fd, SG_GET_SCSI_ID, & sgScsiId); > if (rc == -1) > { > perror ("Trying to SG_GET_SCSI_ID"); > return -1; > } > printf ("host_no %d, channel %d, scsi_id %d, lun %d, scsi_type %d, h_cmd_per_lun %d, d_queue_depth %d\n", > sgScsiId . host_no, sgScsiId . channel, sgScsiId . scsi_id, sgScsiId . lun, sgScsiId . scsi_type, sgScsiId . h_cmd_per_lun, sgScsiId . d_queue_depth); > return 0; > } > >int sgInquiry (int sg_fd) > { > int k; > unsigned char inqCmdBlk [INQ_CMD_LEN] = {INQ_CMD_CODE, 0, 0, 0, INQ_REPLY_LEN, 0}; > /* This is a "standard" SCSI INQUIRY command. It is standard because the > * CMDDT and EVPD bits (in the second byte) are zero. All SCSI targets > * should respond promptly to a standard INQUIRY */ > unsigned char inqBuff [INQ_REPLY_LEN]; > unsigned char sense_buffer [32]; > sg_io_hdr_t io_hdr; > > /* Prepare INQUIRY command */ > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (inqCmdBlk); > /* io_hdr.iovec_count = 0; */ /* memset takes care of this */ > io_hdr . mx_sb_len = sizeof (sense_buffer); > io_hdr . dxfer_direction = SG_DXFER_FROM_DEV; > io_hdr . dxfer_len = INQ_REPLY_LEN; > io_hdr . dxferp = inqBuff; > io_hdr . cmdp = inqCmdBlk; > io_hdr . sbp = sense_buffer; > io_hdr . timeout = 20000; /* 20000 millisecs == 20 seconds */ > /* io_hdr . flags = 0; */ /* take defaults: indirect IO, etc */ > /* io_hdr . pack_id = 0; */ > /* io_hdr . usr_ptr = NULL; */ > > if (ioctl (sg_fd, SG_IO, & io_hdr) < 0) > { > perror ("sg_simple0: Inquiry SG_IO ioctl error"); > return 1; > } > > /* now for the error processing */ > if ((io_hdr . info & SG_INFO_OK_MASK) != SG_INFO_OK) > { > if (io_hdr . sb_len_wr > 0) > { > printf ("INQUIRY sense data: "); > for (k = 0; k < io_hdr . sb_len_wr; ++ k) > { > if ((k > 0) && (0 == (k % 10))) > printf ("\n "); > printf ("0x%02x ", sense_buffer [k]); > } > printf ("\n"); > } > if (io_hdr . masked_status) > printf ("INQUIRY SCSI status=0x%x\n", io_hdr . status); > if (io_hdr . host_status) > printf("INQUIRY host_status=0x%x\n", io_hdr . host_status); > if (io_hdr . driver_status) > printf ("INQUIRY driver_status=0x%x\n", io_hdr . driver_status); > } > else > { /* assume INQUIRY response is present */ > char * p = (char *) inqBuff; > printf ("Some of the INQUIRY command's response:\n"); > printf (" %.8s %.16s %.4s\n", p + 8, p + 16, p + 32); > printf ("INQUIRY duration=%u millisecs, resid=%d\n", io_hdr . duration, io_hdr . resid); > } > return 0; > } > >#define TUR_CMD_LEN 6 > >// return -1 err; 0: ready; 1: not ready >int sgTestUnitReady (int sg_fd) > { > sg_io_hdr_t io_hdr; > unsigned char turCmdBlk [TUR_CMD_LEN] = {0x00, 0, 0, 0, 0, 0}; > unsigned char sense_buffer [32]; > int ok; > > /* Prepare TEST UNIT READY command */ > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (turCmdBlk); > io_hdr . mx_sb_len = sizeof (sense_buffer); > io_hdr . dxfer_direction = SG_DXFER_NONE; > io_hdr . cmdp = turCmdBlk; > io_hdr . sbp = sense_buffer; > io_hdr . timeout = 20000; /* 20000 millisecs == 20 seconds */ > > if (ioctl (sg_fd, SG_IO, &io_hdr) < 0) > { > perror ("Test Unit Ready SG_IO ioctl error"); > return -1; > } > > ok = 0; > switch (sg_err_category3 (& io_hdr)) > { > case SG_ERR_CAT_CLEAN: > ok = 1; > break; > case SG_ERR_CAT_RECOVERED: > printf ("Recovered error on Test Unit Ready, continuing\n"); > ok = 1; > break; > default: /* won't bother decoding other categories */ > sg_chk_n_print3 ("Test Unit Ready command error", & io_hdr); > break; > } > > if (ok) > printf("Test Unit Ready successful so unit is ready!\n"); > else > printf("Test Unit Ready failed so unit may _not_ be ready!\n"); > return ok; > } > >/* -1 -> unrecoverable error, 0 -> successful, 1 -> recoverable (ENOMEM), > 2 -> try again */ >int sgWrite (int sg_fd, unsigned char * buff, int blocks, int to_block, int bs, int * diop) > { > unsigned char wrCmd [10] = {0x2a, 0, 0, 0, 0, 0, 0, 0, 0, 0}; > unsigned char senseBuff [SENSE_BUFF_LEN]; > sg_io_hdr_t io_hdr; > int res; > wrCmd [2] = (unsigned char) ((to_block >> 24) & 0xFF); > wrCmd [3] = (unsigned char) ((to_block >> 16) & 0xFF); > wrCmd [4] = (unsigned char) ((to_block >> 8) & 0xFF); > wrCmd [5] = (unsigned char) (to_block & 0xFF); > wrCmd [7] = (unsigned char) ((blocks >> 8) & 0xff); > wrCmd [8] = (unsigned char) (blocks & 0xff); > > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (wrCmd); > io_hdr . cmdp = wrCmd; > io_hdr . dxfer_direction = SG_DXFER_TO_DEV; > io_hdr . dxfer_len = bs * blocks; > io_hdr . dxferp = buff; > io_hdr . mx_sb_len = SENSE_BUFF_LEN; > io_hdr . sbp = senseBuff; > io_hdr . timeout = DEF_TIMEOUT; > io_hdr . pack_id = to_block; > if (diop && * diop) > io_hdr.flags |= SG_FLAG_DIRECT_IO; > while (((res = write (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > if (ENOMEM == errno) > return 1; > perror ("writing (wr) on sg device, error"); > return -1; > } > > while (((res = read (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > perror ("writing (rd) on sg device, error"); > return -1; > } > switch (sg_err_category3 (& io_hdr)) > { > case SG_ERR_CAT_CLEAN: > break; > case SG_ERR_CAT_RECOVERED: > fprintf (stderr, "Recovered error while writing block=%d, num=%d\n", to_block, blocks); > break; > case SG_ERR_CAT_MEDIA_CHANGED: > return 2; > default: > sg_chk_n_print3( "writing", & io_hdr); > return -1; > } > if (diop && * diop && > ((io_hdr . info & SG_INFO_DIRECT_IO_MASK) != SG_INFO_DIRECT_IO)) > * diop = 0; /* flag that dio not done (completely) */ > return 0; > } > >/* -1 -> unrecoverable error, 0 -> successful, 1 -> recoverable (ENOMEM), > 2 -> try again */ >int sgWriteAsync (int sg_fd, unsigned char * buff, int blocks, int to_block, int bs, int * diop) > { > unsigned char wrCmd [10] = {0x2a, 0, 0, 0, 0, 0, 0, 0, 0, 0}; > unsigned char senseBuff [SENSE_BUFF_LEN]; > sg_io_hdr_t io_hdr; > int res; > wrCmd [2] = (unsigned char) ((to_block >> 24) & 0xFF); > wrCmd [3] = (unsigned char) ((to_block >> 16) & 0xFF); > wrCmd [4] = (unsigned char) ((to_block >> 8) & 0xFF); > wrCmd [5] = (unsigned char) (to_block & 0xFF); > wrCmd [7] = (unsigned char) ((blocks >> 8) & 0xff); > wrCmd [8] = (unsigned char) (blocks & 0xff); > > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (wrCmd); > io_hdr . cmdp = wrCmd; > io_hdr . dxfer_direction = SG_DXFER_TO_DEV; > io_hdr . dxfer_len = bs * blocks; > io_hdr . dxferp = buff; > io_hdr . mx_sb_len = SENSE_BUFF_LEN; > io_hdr . sbp = senseBuff; > io_hdr . timeout = DEF_TIMEOUT; > io_hdr . pack_id = to_block; > if (diop && * diop) > io_hdr.flags |= SG_FLAG_DIRECT_IO; > while (((res = write (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > if (ENOMEM == errno) > return 1; > perror ("writing (wr) on sg device, error"); > return -1; > } > return 0; > } > >/* -1 -> unrecoverable error, 0 -> successful, 1 -> recoverable (ENOMEM), > 2 -> try again */ >int sgWriteAsyncSync (int sg_fd, unsigned char * buff, int blocks, int to_block, int bs, int * diop) > { > sg_io_hdr_t io_hdr; > int res; > > while (((res = read (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > ((errno == EINTR) || (errno == EAGAIN))) > ; > if (res < 0) > { > perror ("writing (rd) on sg device, error"); > return -1; > } > switch (sg_err_category3 (& io_hdr)) > { > case SG_ERR_CAT_CLEAN: > break; > case SG_ERR_CAT_RECOVERED: > fprintf (stderr, "Recovered error while writing block=%d, num=%d\n", to_block, blocks); > break; > case SG_ERR_CAT_MEDIA_CHANGED: > return 2; > default: > sg_chk_n_print3( "writing", & io_hdr); > return -1; > } > if (diop && * diop && > ((io_hdr . info & SG_INFO_DIRECT_IO_MASK) != SG_INFO_DIRECT_IO)) > * diop = 0; /* flag that dio not done (completely) */ > return 0; > } > >/* -1 -> unrecoverable error, 0 -> successful, 1 -> recoverable (ENOMEM), > 2 -> try again */ >int sgWrite6 (int sg_fd, unsigned char * buff, int blocks, int to_block, int bs, int * diop) > { > unsigned char wrCmd [6] = {0x0a, 0, 0, 0, 0, 0}; > unsigned char senseBuff [SENSE_BUFF_LEN]; > sg_io_hdr_t io_hdr; > int res; > > //fprintf (stderr, "In sgWrite6\n"); > if (blocks > 256) > return -1; > if (to_block > 0x1fffff) > return -1; > wrCmd [1] = (unsigned char) ((to_block >> 16) & 0x1F); > wrCmd [2] = (unsigned char) ((to_block >> 8) & 0xFF); > wrCmd [3] = (unsigned char) (to_block & 0xFF); > wrCmd [4] = (unsigned char) (blocks == 256 ? 0 : blocks); > > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (wrCmd); > io_hdr . cmdp = wrCmd; > io_hdr . dxfer_direction = SG_DXFER_TO_DEV; > io_hdr . dxfer_len = bs * blocks; > io_hdr . dxferp = buff; > io_hdr . mx_sb_len = SENSE_BUFF_LEN; > io_hdr . sbp = senseBuff; > io_hdr . timeout = DEF_TIMEOUT; > io_hdr . pack_id = to_block; > if (diop && * diop) > io_hdr.flags |= SG_FLAG_DIRECT_IO; > while (((res = write (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > if (ENOMEM == errno) > return 1; > perror ("writing (wr) on sg device, error"); > return -1; > } > > while (((res = read (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > perror ("writing (rd) on sg device, error"); > return -1; > } > switch (sg_err_category3 (& io_hdr)) > { > case SG_ERR_CAT_CLEAN: > break; > case SG_ERR_CAT_RECOVERED: > fprintf (stderr, "Recovered error while writing block=%d, num=%d\n", to_block, blocks); > break; > case SG_ERR_CAT_MEDIA_CHANGED: > return 2; > default: > sg_chk_n_print3( "writing", & io_hdr); > return -1; > } > if (diop && * diop && > ((io_hdr . info & SG_INFO_DIRECT_IO_MASK) != SG_INFO_DIRECT_IO)) > * diop = 0; /* flag that dio not done (completely) */ > return 0; > } > >/* -1 -> unrecoverable error, 0 -> successful, 1 -> recoverable (ENOMEM), > 2 -> try again */ >int sgRead (int sg_fd, unsigned char * buff, int blocks, int from_block, > int bs, int * diop, int do_mmap) > { > unsigned char rdCmd [10] = {0x28, 0, 0, 0, 0, 0, 0, 0, 0, 0}; > unsigned char senseBuff [SENSE_BUFF_LEN]; > sg_io_hdr_t io_hdr; > int res; > > rdCmd [2] = (unsigned char) ((from_block >> 24) & 0xFF); > rdCmd [3] = (unsigned char) ((from_block >> 16) & 0xFF); > rdCmd [4] = (unsigned char) ((from_block >> 8) & 0xFF); > rdCmd [5] = (unsigned char) (from_block & 0xFF); > rdCmd [7] = (unsigned char) ((blocks >> 8) & 0xff); > rdCmd [8] = (unsigned char) (blocks & 0xff); > > memset (& io_hdr, 0, sizeof (sg_io_hdr_t)); > io_hdr . interface_id = 'S'; > io_hdr . cmd_len = sizeof (rdCmd); > io_hdr . cmdp = rdCmd; > io_hdr . dxfer_direction = SG_DXFER_FROM_DEV; > io_hdr . dxfer_len = bs * blocks; > if (! do_mmap) /* not required: shows dxferp unused during mmap-ed IO */ > io_hdr . dxferp = buff; > io_hdr . mx_sb_len = SENSE_BUFF_LEN; > io_hdr . sbp = senseBuff; > io_hdr . timeout = DEF_TIMEOUT; > io_hdr . pack_id = pack_id_count ++; > if (diop && * diop) > io_hdr.flags |= SG_FLAG_DIRECT_IO; > else if (do_mmap) > io_hdr . flags |= SG_FLAG_MMAP_IO; > > while (((res = write (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > if (ENOMEM == errno) > return 1; > perror ("reading (wr) on sg device, error"); > return -1; > } > > while (((res = read (sg_fd, & io_hdr, sizeof (io_hdr))) < 0) && > (EINTR == errno)) > ; > if (res < 0) > { > perror ("reading (rd) on sg device, error"); > return -1; > } > switch (sg_err_category3 (& io_hdr)) > { > case SG_ERR_CAT_CLEAN: > break; > case SG_ERR_CAT_RECOVERED: > fprintf (stderr, "Recovered error while reading block=%d, num=%d\n", > from_block, blocks); > break; > case SG_ERR_CAT_MEDIA_CHANGED: > return 2; > default: > sg_chk_n_print3 ("reading", & io_hdr); > return -1; > } > if (diop && * diop && > ((io_hdr . info & SG_INFO_DIRECT_IO_MASK) != SG_INFO_DIRECT_IO)) > * diop = 0; /* flag that dio not done (completely) */ > sum_of_resids += io_hdr . resid; >#if SG_DEBUG > fprintf (stderr, "duration=%u ms\n", io_hdr . duration); >#endif > return 0; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 364421
: 246961 |
246971