xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: Olaf Hering <olaf@aepfle.de>
Cc: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH 3 of 3] xend/pvscsi: update sysfs parser for Linux 3.0
Date: Fri, 24 Aug 2012 10:24:05 +0100	[thread overview]
Message-ID: <1345800245.12501.178.camel@zakaz.uk.xensource.com> (raw)
In-Reply-To: <482b9db173f2ceefed06.1345746249@probook.site>

On Thu, 2012-08-23 at 19:24 +0100, Olaf Hering wrote:
> # HG changeset patch
> # User Olaf Hering <olaf@aepfle.de>
> # Date 1345743331 -7200
> # Node ID 482b9db173f2ceefed06346bec9e6d8cef9704fe
> # Parent  2b9992aea26cfebc2dda56d1a97a35dc3a5c8ce8
> xend/pvscsi: update sysfs parser for Linux 3.0
> 
> The sysfs parser for /sys/bus/scsi/devices understands only the layout
> of kernel version 2.6.16. This looks as follows:
> 
> /sys/bus/scsi/devices/1:0:0:0/block:sda is a symlink to /sys/block/sda/
> /sys/bus/scsi/devices/1:0:0:0/scsi_generic:sg1 is a symlink to /sys/class/scsi_generic/sg1
> 
> Both directories contain a 'dev' file with the major:minor information.
> This patch updates the used regex strings to match also the colon to
> make it more robust against possible future changes.
> 
> 
> In kernel version 3.0 the layout changed:
> /sys/bus/scsi/devices/ contains now additional symlinks to directories
> such as host1 and target1:0:0. This patch ignores these as they do not
> point to the desired scsi devices. They just clutter the devices array.
> 
> The directory layout in '1:0:0:0' changed as well, the 'type:name'
> notation was replaced with 'type/name' directories:
> 
> /sys/bus/scsi/devices/1:0:0:0/block/sda/
> /sys/bus/scsi/devices/1:0:0:0/scsi_generic/sg1/
> 
> Both directories contain a 'dev' file with the major:minor information.
> This patch adds additional code to walk the subdir to find the 'dev'
> file to make sure the given subdirectory is really the kernel name.
> 
> 
> In addition this patch makes sure devname is not None.

Did you test this with both pre- and post-3.0 kernels?

> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
> 
> diff -r 2b9992aea26c -r 482b9db173f2 tools/python/xen/util/vscsi_util.py
> --- a/tools/python/xen/util/vscsi_util.py
> +++ b/tools/python/xen/util/vscsi_util.py
> @@ -130,20 +130,36 @@ def _vscsi_get_scsidevices_by_sysfs():
>  
>      for dirpath, dirnames, files in os.walk(sysfs_mnt + SYSFS_SCSI_PATH):
>          for hctl in dirnames:
> +            if len(hctl.split(':')) != 4:
> +                continue
>              paths = os.path.join(dirpath, hctl)
>              devname = None
>              sg = None
>              scsi_id = None
>              for f in os.listdir(paths):
>                  realpath = os.path.realpath(os.path.join(paths, f))
> -                if  re.match('^block', f) or \
> -                    re.match('^tape', f) or \
> -                    re.match('^scsi_changer', f) or \
> -                    re.match('^onstream_tape', f):
> +                if  re.match('^block:', f) or \
> +                    re.match('^tape:', f) or \
> +                    re.match('^scsi_changer:', f) or \
> +                    re.match('^onstream_tape:', f):
>                      devname = os.path.basename(realpath)
> +                elif f == "block" or \
> +                     f == "tape" or \
> +                     f == "scsi_changer" or \
> +                     f == "onstream_tape":
> +                    for dir in os.listdir(os.path.join(paths, f)):
> +                        if os.path.exists(os.path.join(paths, f, dir, "dev")):
> +                            devname = os.path.basename(dir)
>  
> -                if re.match('^scsi_generic', f):
> +                if re.match('^scsi_generic:', f):
>                      sg = os.path.basename(realpath)
> +                elif f == "scsi_generic":
> +                    for dir in os.listdir(os.path.join(paths, f)):
> +                        if os.path.exists(os.path.join(paths, f, dir, "dev")):
> +                            sg = os.path.basename(dir)
> +                if sg:
> +                    if devname is None:
> +                        devname = sg
>                      scsi_id = _vscsi_get_scsiid(sg)
>              devices.append([hctl, devname, sg, scsi_id])
>  
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  reply	other threads:[~2012-08-24  9:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-23 18:24 [PATCH 0 of 3] xend pvscsi fixes Olaf Hering
2012-08-23 18:24 ` [PATCH 1 of 3] xend/pvscsi: fix passing of SCSI control LUNs Olaf Hering
2012-08-24  9:15   ` Ian Campbell
2012-08-24 11:17     ` Olaf Hering
2012-08-23 18:24 ` [PATCH 2 of 3] xend/pvscsi: fix usage of persistant device names for SCSI devices Olaf Hering
2012-08-24  9:20   ` Ian Campbell
2012-08-23 18:24 ` [PATCH 3 of 3] xend/pvscsi: update sysfs parser for Linux 3.0 Olaf Hering
2012-08-24  9:24   ` Ian Campbell [this message]
2012-08-24 11:20     ` Olaf Hering

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=1345800245.12501.178.camel@zakaz.uk.xensource.com \
    --to=ian.campbell@citrix.com \
    --cc=olaf@aepfle.de \
    --cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).