public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: brace@beardog.cca.cpqcorp.net
To: linux-scsi@vger.kernel.org
Cc: James.Bottomley@HansenPartnership.com, fujita.tomonori@lab.ntt.co.jp
Subject: Problems adding/removing scsi devices.
Date: Thu, 28 Aug 2008 12:46:23 -0500	[thread overview]
Message-ID: <20080828174623.GA3611@beardog.cca.cpqcorp.net> (raw)

I am having problems with my scsi driver. There is an application that issues
configuration changes to my driver to add/remove scsi devices. 

I am having a problem with the following sequence:
	1) Add a drive. 
	2) Remove the drive.
	3) Add the drive back.

The first two work correctly, the third works, but the drive's sdev_state is 
set to SDEV_DEL and can no longer be managed.

To delete the scsi_device, The driver does the following:

struct scsi_device *sdev = scsi_device_lookup(sh, removed[i].bus, 
					removed[i].target,removed[i].lun);
if (sdev != NULL) {
	scsi_remove_device(sdev);
	scsi_device_put(sdev);
}

Later on that application adds a scsi_device. (Using the same bus, target, 
and lun as before).

rc = scsi_add_device(sh, added[i].bus, added[i].target, added[i].lun);
if (rc == 0) {
	printk(DRIVERNAME "%d: shost[%p] added b%dt%dl%d\n", h->ctlr_num, sh,
				added[i].bus, added[i].target, added[i].lun);
	struct scsi_device *sdev = scsi_device_lookup(sh, added[i].bus, 
						added[i].target, added[i].lun);
	printk(DRIVERNAME "%d: shost[%p] looked up sdev[%p]\n", h->ctlr_num,sh,sdev);
	continue;
}

The scsi_device_lookup() call after the scsi_device_add() fails because the 
scsi_device.sdev_state is set to SDEV_DEL. 

I added code to scsi_add_device() and printed out the state just before the 
return statement, it is SDEV_RUNNING. After returning back to my driver, the 
scsi_device.sdev_state is set to SDEV_DEL. 

int scsi_add_device(struct Scsi_Host *host,                     rc = scsi_add_device(sh, added[i].bus,
                    uint channel, uint target, uint lun)                           added[i].target, added[i].lun);
{                                                               ==>// Here the state is SDEV_DEL.

	struct scsi_device *sdev = __scsi_add_device(host, 
                                                     channel, 
                                                     target, 
                                                     lun, NULL); 
	if (IS_ERR(sdev)) 
		return PTR_ERR(sdev); 
		scsi_device_put(sdev); 
		printk("sdev[%p] state = %04x\n", sdev.sdev_state); <===== Here is is running.
	return 0;
}

Can you not add, remove, and add the same bus, target, lun?

             reply	other threads:[~2008-08-28 17:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-28 17:46 brace [this message]
2008-08-28 18:11 ` Problems adding/removing scsi devices James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080828174623.GA3611@beardog.cca.cpqcorp.net \
    --to=brace@beardog.cca.cpqcorp.net \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox