Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst disks: Get disk identify data from drvctl



details:   https://anonhg.NetBSD.org/src/rev/734c8162737e
branches:  trunk
changeset: 366128:734c8162737e
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 15 14:48:37 2022 +0000

description:
disks: Get disk identify data from drvctl

When /dev/drvctl exists, attempt to use the disk-info/type property as
a disk's description string. Fallback to ATA / SCSI probing when the
identify data is not available through this interface.

This has the side-effect of adding descriptions for things like NVMe and
SD/eMMC devices.

diffstat:

 usr.sbin/sysinst/disks.c |  74 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 3 deletions(-)

diffs (108 lines):

diff -r 5ea6c3a78efc -r 734c8162737e usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c  Sun May 15 12:48:25 2022 +0000
+++ b/usr.sbin/sysinst/disks.c  Sun May 15 14:48:37 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.77 2022/05/15 12:48:25 jmcneill Exp $ */
+/*     $NetBSD: disks.c,v 1.78 2022/05/15 14:48:37 jmcneill Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -61,6 +61,8 @@
 #include <dev/ata/atareg.h>
 #include <sys/ataio.h>
 
+#include <sys/drvctlio.h>
+
 #include "defs.h"
 #include "md.h"
 #include "msg_defs.h"
@@ -321,12 +323,80 @@
        return 1;
 }
 
+static int
+get_descr_drvctl(struct disk_desc *dd)
+{
+       prop_dictionary_t command_dict;
+       prop_dictionary_t args_dict;
+       prop_dictionary_t results_dict;
+       prop_dictionary_t props;
+       int8_t perr;
+       int error, fd;
+       bool rv;
+       char size[5];
+       const char *model;
+
+       fd = open("/dev/drvctl", O_RDONLY);
+       if (fd == -1)
+               return 0;
+
+       command_dict = prop_dictionary_create();
+       args_dict = prop_dictionary_create();
+
+       prop_dictionary_set_cstring_nocopy(command_dict, "drvctl-command",
+           "get-properties");
+       prop_dictionary_set_cstring_nocopy(args_dict, "device-name",
+           dd->dd_name);
+       prop_dictionary_set(command_dict, "drvctl-arguments", args_dict);
+       prop_object_release(args_dict);
+
+       error = prop_dictionary_sendrecv_ioctl(command_dict, fd,
+           DRVCTLCOMMAND, &results_dict);
+       prop_object_release(command_dict);
+       close(fd);
+       if (error)
+               return 0;
+
+       rv = prop_dictionary_get_int8(results_dict, "drvctl-error", &perr);
+       if (rv == false || perr != 0) {
+               prop_object_release(results_dict);
+               return 0;
+       }
+
+       props = prop_dictionary_get(results_dict,
+           "drvctl-result-data");
+       if (props == NULL) {
+               prop_object_release(results_dict);
+               return 0;
+       }
+       props = prop_dictionary_get(props, "disk-info");
+       if (props == NULL ||
+           !prop_dictionary_get_string(props, "type", &model)) {
+               prop_object_release(results_dict);
+               return 0;
+       }
+
+       humanize_number(size, sizeof(size),
+           (uint64_t)dd->dd_secsize * (uint64_t)dd->dd_totsec,
+           "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
+
+       snprintf(dd->dd_descr, sizeof(dd->dd_descr), "%s (%s, %s)",
+           dd->dd_name, size, model);
+
+       prop_object_release(results_dict);
+
+       return 1;
+}
+
 static void
 get_descr(struct disk_desc *dd)
 {
        char size[5];
        dd->dd_descr[0] = '\0';
 
+       /* try drvctl first, fallback to direct probing */
+       if (get_descr_drvctl(dd))
+               return;
        /* try ATA */
        if (get_descr_ata(dd))
                return;
@@ -334,8 +404,6 @@
        if (get_descr_scsi(dd))
                return;
 
-       /* XXX: identify for ld @ NVME or microSD */
-
        /* XXX: get description from raid, cgd, vnd... */
 
        /* punt, just give some generic info */



Home | Main Index | Thread Index | Old Index