Author: pjd
Date: Tue Sep 15 11:23:59 2009
New Revision: 197217
URL: http://svn.freebsd.org/changeset/base/197217

Log:
  MFC r196822, r196823, r196824:
  
  Remove 'ad:' prefix from disk serial number. We don't want serial number
  to change when we reconnect the disk in a way that it is accessible through
  CAM for example.
  
  Discussed with:       trasz
  
  Simplify g_disk_ident_adjust() function and allow any printable character
  in serial number.
  
  Discussed with:       trasz
  Obtained from:        Wheel Sp. z o.o. (http://www.wheel.pl)
  
  Make serial numbers of daX disks visible by GEOM.
  
  No objections from:   scottl
  Obtained from:        Wheel Sp. z o.o. (http://www.wheel.pl)
  
  Approved by:  re (kib)

Modified:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cam/scsi/scsi_da.c
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/ata/ata-disk.c
  stable/8/sys/dev/xen/xenpci/   (props changed)
  stable/8/sys/geom/geom_disk.c

Modified: stable/8/sys/cam/scsi/scsi_da.c
==============================================================================
--- stable/8/sys/cam/scsi/scsi_da.c     Tue Sep 15 11:20:23 2009        
(r197216)
+++ stable/8/sys/cam/scsi/scsi_da.c     Tue Sep 15 11:23:59 2009        
(r197217)
@@ -1266,6 +1266,8 @@ daregister(struct cam_periph *periph, vo
        softc->disk->d_flags = 0;
        if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
                softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
+       strlcpy(softc->disk->d_ident, cgd->serial_num,
+           MIN(sizeof(softc->disk->d_ident), cgd->serial_num_len + 1));
        disk_create(softc->disk, DISK_VERSION);
        mtx_lock(periph->sim->mtx);
 

Modified: stable/8/sys/dev/ata/ata-disk.c
==============================================================================
--- stable/8/sys/dev/ata/ata-disk.c     Tue Sep 15 11:20:23 2009        
(r197216)
+++ stable/8/sys/dev/ata/ata-disk.c     Tue Sep 15 11:23:59 2009        
(r197217)
@@ -136,8 +136,8 @@ ad_attach(device_t dev)
     if ((atadev->param.support.command2 & ATA_SUPPORT_CFA) ||
        atadev->param.config == ATA_PROTO_CFA)
        adp->disk->d_flags = DISKFLAG_CANDELETE;
-    snprintf(adp->disk->d_ident, sizeof(adp->disk->d_ident), "ad:%s",
-       atadev->param.serial);
+    strlcpy(adp->disk->d_ident, atadev->param.serial,
+       sizeof(adp->disk->d_ident));
     disk_create(adp->disk, DISK_VERSION);
     device_add_child(dev, "subdisk", device_get_unit(dev));
     ad_firmware_geom_adjust(dev, adp->disk);

Modified: stable/8/sys/geom/geom_disk.c
==============================================================================
--- stable/8/sys/geom/geom_disk.c       Tue Sep 15 11:20:23 2009        
(r197216)
+++ stable/8/sys/geom/geom_disk.c       Tue Sep 15 11:23:59 2009        
(r197217)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>
 #include <sys/bio.h>
 #include <sys/conf.h>
+#include <sys/ctype.h>
 #include <sys/fcntl.h>
 #include <sys/malloc.h>
 #include <sys/sysctl.h>
@@ -400,39 +401,25 @@ g_disk_destroy(void *ptr, int flag)
 }
 
 /*
- * We only allow [a-za-z0-...@#%.:] characters, the rest is converted to 
'x<HH>'.
+ * We only allow printable characters in disk ident,
+ * the rest is converted to 'x<HH>'.
  */
 static void
 g_disk_ident_adjust(char *ident, size_t size)
 {
-       char newid[DISK_IDENT_SIZE], tmp[4];
-       size_t len;
-       char *p;
-
-       bzero(newid, sizeof(newid));
-       len = 0;
-       for (p = ident; *p != '\0' && len < sizeof(newid) - 1; p++) {
-               switch (*p) {
-               default:
-                       if ((*p < 'a' || *p > 'z') &&
-                           (*p < 'A' || *p > 'Z') &&
-                           (*p < '0' || *p > '9')) {
-                               snprintf(tmp, sizeof(tmp), "x%02hhx", *p);
-                               strlcat(newid, tmp, sizeof(newid));
-                               len += 3;
-                               break;
-                       }
-                       /* FALLTHROUGH */
-               case '-':
-               case '_':
-               case '@':
-               case '#':
-               case '%':
-               case '.':
-               case ':':
-                       newid[len++] = *p;
-                       break;
+       char *p, tmp[4], newid[DISK_IDENT_SIZE];
+
+       newid[0] = '\0';
+       for (p = ident; *p != '\0'; p++) {
+               if (isprint(*p)) {
+                       tmp[0] = *p;
+                       tmp[1] = '\0';
+               } else {
+                       snprintf(tmp, sizeof(tmp), "x%02hhx",
+                           *(unsigned char *)p);
                }
+               if (strlcat(newid, tmp, sizeof(newid)) >= sizeof(newid))
+                       break;
        }
        bzero(ident, size);
        strlcpy(ident, newid, size);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to