[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need notification to my application when a SCSI disk gets connected to the system

Posted on 2013-01-23
7
Medium Priority
?
491 Views
Last Modified: 2013-01-28
Hi,
I am using an application written in C++ on Windows 7, that is used to detect  SAS disks connected to the LSI HBA on my system and to send various SCSI commands to the disk.

Presently to the detect the disks connected to the system, user has to scan the device tree of windows, get the details of the new disks that are added to the system and update my application with those details.
my application uses SetupDiGetClassDevs API with the flag GUID_DEVINTERFACE_DISK for this purpose.

I have a requirement of enabling the application to receive a notification from windows when the disk is connected/removed  to/from  the system. In other words, i need to make my application PNP enabled.  

Is it possible to get a notification when a new disk gets connected to the SAS HBA or removed from the HBA? Does windows 7 provide any  APIS for this purpose?

Can i find some sample code which does this?
0
Comment
Question by:raj_ksrt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 47

Expert Comment

by:David
ID: 38809747
Exactly what controller do you have?  This is critical, because certain LSI controllers do not tell the O/S anything when HDDs are added/removed.  So with some controllers, the only way to do the job is to use the LSI API.  As such even if I were to write it for you, I wouldn't be able to release anything but an executable.
0
 

Author Comment

by:raj_ksrt
ID: 38813155
Hi,

I am using LSI-9200 16e controllers and i am able see some notifications from LSI controller to my mini port driver. Also i had done some search around and found an example application in MFC that receives WM_DEVICECHANGE message when a hard disk is connected or removed from the LSI controller.

My question is whether i can get some call back from OS without using MFC in my app.

Also i think device manager is just an applet. If some controllers don't inform OS about the changes in the connected disk configuration then  how device manager would update its device list accordingly when a disk is added or removed from the system?
0
 
LVL 47

Assisted Solution

by:David
David earned 2000 total points
ID: 38813184
Those controllers will not always notify the OS of a change.  In fact, the card doesn't even do the WM_DEVICECHANGE reliably.  You've been lucky (well, perhaps unlucky) that you haven't run into a test scenario when the WM_DEVICECHANGE didn't sense a change.

If your goal is to have an automated trigger under windows that tells you when a device is added/removed in all cases, then forget it.  You have to probe.  I've got the developer's library and there is a low-level controller ioctl that you have to send to it in order to force a rescan.

I don't know how high you scale, but I've seen all sorts of discovery issues when you start having multiple initiator situations and/or expanders, and just even reconnect targets.  The windows device name (\\.\PHYSICALDRIVEn  can change for any arbitrary disk if you disconnect and reconnect also, or the \\.\PHYSICALDRIVEn can even get mapped to a different device on a reboot or even rescan after a disconnect-reconnect).

Bottom line, the answer is not only no, there is no way to do this (accurately), but I expect your existing code is broken unless you don't have to worry about expanders, SATA/SATL encapsulation, multipathing, or SAS targets getting disconnected/reconnected or even moved to a different bay in an expander.

Hint - if you want this to work, no matter what, you need to enable persistent mapping.  I learned that the hard way a few years ago.  Based on my assumption of what you are trying to do, if you don't enable it, you risk talking to the wrong device after a topology change.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:raj_ksrt
ID: 38813544
Hi,

Thanks for the reply.  From the above I understand that it is not very viable solution to rely upon WM_DEVICECHANGE message from windows. (although i have seen windows throwing this message fairly consistently in case of disk topology changes on the controller)

Can i know what is persistent mapping , it's purpose and how to enable the same?  Just for information sake.
0
 
LVL 47

Assisted Solution

by:David
David earned 2000 total points
ID: 38814017
Persistent mapping is a firmware feature that nails the WWN to a specific device name .  So each target will always have the same \\.\PHYSICALDRIVEx, even through reboots and hardware changes.

I am a LSI developer and so have the API under non-disclosure, and just control it that way through my C code, so am not sure how you can manipulate it without the API, but chances are good such a setting is available through the BIOS.
0
 

Author Comment

by:raj_ksrt
ID: 38817616
I am running some sudden power off test cases on my disk for multiple iterations and with each iteration after the disk is powered on, i am observing that the is getting a new target ID assigned by the the HBA.

so here is my understanding.

1. A device usually has a WWN that is unique to that ID and that doesn't change.

2. The Persistent mapping feature binds the WWN to a specific device name such as \\.\PHYSICALDRIVE0 or  \\.\PHYSICALDRIVE1 hence even when the disk is removed and reconnected or when the system is rebooted the device name will not change. Also the target ID assigned to the drive by the HBA will not change across power cycles of the disk.

Could you please confirm if the understanding is correct? i think that will conclude this topic.
0
 
LVL 47

Accepted Solution

by:
David earned 2000 total points
ID: 38818241
1) True, but a device can have more than one WWN, depending on what is on EVPD pages 80-83h.  Also SATA disks may or may not have a WWN, depending on the version of ATA spec they are compliant with. But if you put a SATA device on an expander and/or attach to a SAS/SATA controller, then it will be given a WWN one way or another.   One must be wary of SATA devices and the WWN may be auto-assigned so that the WWN is a function of nothing more than a bay# in an expander.  

So there is going to be a unique WWN per EXPANDER.  And the  individual device itself will have a unique WWN if SAS.  If SATA,it may or may not have a unique WWN.   (There are also more than one kind of WWN)

WWNs can be overwritten by SAS switches, and through the LSI API.  These don't change the device itself, they just change what is presented to the host OS and/or expanders.

Also since SAS devices are dual ported, you are going to always have 2 WWNs, one per port, SATA are single ported.  Cross referencing can be done by doing EVPD page SCSI inquiries.

2) Persistence mapping actually insures the WWN gets mapped to same bus/target ids, which is subtle difference.  The O/S still has the option to change the mapping, but that typically requires you to add/remove HBAs, or use different HBA ports, or make some sort of hardware change.   Persistence is more appropriately used to make sure that if you are doing multipathing or have to swap out a LSI controller that the mapping will be exactly the same between them. I have seen windows change a device name when persistent mapping is turned on, but I have never seen this happen if the HDD has a drive letter assigned to it.  Sorry I can't be more specific on persistent mapping rules, I never had to really care about them enough in any of my code so never needed to research all the rules of what can and can't happen.  Probably a whitepaper on it somewhere on the internet.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question