Author: sephe
Date: Mon Mar 21 06:54:21 2016
New Revision: 297142
URL: https://svnweb.freebsd.org/changeset/base/297142

Log:
  hyperv: Factor out snprinf_hv_guid()
  
  Submitted by: Ju Sun <junsu microsoft com>
  Reviewed by:  Dexuan Cui <decui microsoft com>, sephe
  MFC after:    1 week
  Sponsored by: Microsoft OSTC
  Differential Revision:        https://reviews.freebsd.org/D5651

Modified:
  head/sys/dev/hyperv/include/hyperv.h
  head/sys/dev/hyperv/utilities/hv_kvp.c
  head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c

Modified: head/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- head/sys/dev/hyperv/include/hyperv.h        Mon Mar 21 06:52:35 2016        
(r297141)
+++ head/sys/dev/hyperv/include/hyperv.h        Mon Mar 21 06:54:21 2016        
(r297142)
@@ -124,6 +124,8 @@ typedef struct hv_guid {
         unsigned char data[16];
 } __packed hv_guid;
 
+int snprintf_hv_guid(char *, size_t, const hv_guid *);
+
 #define HV_NIC_GUID                                                    \
        .data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,        \
                0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}

Modified: head/sys/dev/hyperv/utilities/hv_kvp.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_kvp.c      Mon Mar 21 06:52:35 2016        
(r297141)
+++ head/sys/dev/hyperv/utilities/hv_kvp.c      Mon Mar 21 06:54:21 2016        
(r297142)
@@ -304,28 +304,11 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru
 {
        int err_ip, err_subnet, err_gway, err_dns, err_adap;
        int UNUSED_FLAG = 1;
-       int guid_index;
        struct hv_device *hv_dev;       /* GUID Data Structure */
        hn_softc_t *sc;                 /* hn softc structure  */
        char if_name[4];
-       unsigned char guid_instance[40];
-       char *guid_data = NULL;
        char buf[39];
 
-       struct guid_extract {
-               char    a1[2];
-               char    a2[2];
-               char    a3[2];
-               char    a4[2];
-               char    b1[2];
-               char    b2[2];
-               char    c1[2];
-               char    c2[2];
-               char    d[4];
-               char    e[12];
-       };
-
-       struct guid_extract *id;
        device_t *devs;
        int devcnt;
 
@@ -352,17 +335,7 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(stru
                        /* Trying to find GUID of Network Device */
                        hv_dev = sc->hn_dev_obj;
 
-                       for (guid_index = 0; guid_index < 16; guid_index++) {
-                               sprintf(&guid_instance[guid_index * 2], "%02x",
-                                   hv_dev->device_id.data[guid_index]);
-                       }
-
-                       guid_data = (char *)guid_instance;
-                       id = (struct guid_extract *)guid_data;
-                       snprintf(buf, sizeof(buf), 
"{%.2s%.2s%.2s%.2s-%.2s%.2s-%.2s%.2s-%.4s-%s}",
-                           id->a4, id->a3, id->a2, id->a1,
-                           id->b2, id->b1, id->c2, id->c1, id->d, id->e);
-                       guid_data = NULL;
+                       snprintf_hv_guid(buf, sizeof(buf), &hv_dev->device_id);
                        sprintf(if_name, "%s%d", "hn", 
device_get_unit(devs[devcnt]));
 
                        if (strncmp(buf, (char 
*)umsg->body.kvp_ip_val.adapter_id, 39) == 0) {

Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c    Mon Mar 21 06:52:35 
2016        (r297141)
+++ head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c    Mon Mar 21 06:54:21 
2016        (r297142)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/pcpu.h>
 #include <x86/apicvar.h>
 
+#include <dev/hyperv/include/hyperv.h>
 #include "hv_vmbus_priv.h"
 
 #include <contrib/dev/acpica/include/acpi.h>
@@ -300,15 +301,17 @@ hv_vmbus_child_device_create(
        return (child_dev);
 }
 
-static void
-print_dev_guid(struct hv_device *dev)
+int
+snprintf_hv_guid(char *buf, size_t sz, const hv_guid *guid)
 {
-       int i;
-       unsigned char guid_name[100];
-       for (i = 0; i < 32; i += 2)
-               sprintf(&guid_name[i], "%02x", dev->class_id.data[i / 2]);
-       if(bootverbose)
-               printf("VMBUS: Class ID: %s\n", guid_name);
+       int cnt;
+       const unsigned char *d = guid->data;
+
+       cnt = snprintf(buf, sz,
+               
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+               d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6],
+               d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
+       return (cnt);
 }
 
 int
@@ -317,8 +320,11 @@ hv_vmbus_child_device_register(struct hv
        device_t child;
        int ret = 0;
 
-       print_dev_guid(child_dev);
-
+       if (bootverbose) {
+               char name[40];
+               snprintf_hv_guid(name, sizeof(name), &child_dev->class_id);
+               printf("VMBUS: Class ID: %s\n", name);
+       }
 
        child = device_add_child(vmbus_devp, NULL, -1);
        child_dev->device = child;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to