Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Mar 2020 18:26:23 +0900
From:      =?UTF-8?B?6Yqt5LiH5qOa?= <wanpengqian@gmail.com>
To:        virtualization@freebsd.org
Subject:   Patch for Nominal Media Rotation Rate field of AHCI disk.
Message-ID:  <CANBJ%2BxQv2%2Bpe=jnL6zO=X3MtU=oW%2B1hyEfOmCz205ozGX5U2Mg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi all
I have a patch for Nominal Media Rotation Rate field.
currently bhyve will not report this field.

setting nmrr=1 will let ahci controller report disk as Solid State Disk.
other valid value will report as RPM of disk.

ref document:
http://www.t13.org/documents/UploadedDocuments/docs2016/di529r14-ATAATAPI_Command_Set_-_4.pdf

9.11.5.4 NOMINAL MEDIA ROTATION RATE field

Best Regards
Qian

[-- Attachment #2 --]
diff -u -r -N usr.sbin/bhyve/block_if.c usr.sbin/bhyvenmrr/block_if.c
--- usr.sbin/bhyve/block_if.c	2020-03-11 18:09:31.556080000 +0900
+++ usr.sbin/bhyvenmrr/block_if.c	2020-03-11 18:06:18.641165000 +0900
@@ -102,6 +102,7 @@
 	int			bc_sectsz;
 	int			bc_psectsz;
 	int			bc_psectoff;
+	int			bc_nmrr;  // Nominal Media Rotation Rate
 	int			bc_closing;
 	pthread_t		bc_btid[BLOCKIF_NUMTHR];
 	pthread_mutex_t		bc_mtx;
@@ -407,7 +408,7 @@
 	struct stat sbuf;
 	struct diocgattr_arg arg;
 	off_t size, psectsz, psectoff;
-	int extra, fd, i, sectsz;
+	int extra, fd, i, sectsz, nmrr;
 	int nocache, sync, ro, candelete, geom, ssopt, pssopt;
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_t rights;
@@ -421,6 +422,7 @@
 	nocache = 0;
 	sync = 0;
 	ro = 0;
+        nmrr = 0;
 
 	/*
 	 * The first element in the optstring is always a pathname.
@@ -441,6 +443,12 @@
 			;
 		else if (sscanf(cp, "sectorsize=%d", &ssopt) == 1)
 			pssopt = ssopt;
+		else if (sscanf(cp, "nmrr=%d", &nmrr) == 1) {
+			if(nmrr < 0x0
+			  || (nmrr >= 0x2 && nmrr <= 0x400)
+			  || nmrr >= 0xFFFF)
+				nmrr = 0;
+		}
 		else {
 			fprintf(stderr, "Invalid device option \"%s\"\n", cp);
 			goto err;
@@ -556,6 +564,7 @@
 	bc->bc_sectsz = sectsz;
 	bc->bc_psectsz = psectsz;
 	bc->bc_psectoff = psectoff;
+	bc->bc_nmrr = nmrr;
 	pthread_mutex_init(&bc->bc_mtx, NULL);
 	pthread_cond_init(&bc->bc_cond, NULL);
 	TAILQ_INIT(&bc->bc_freeq);
@@ -846,4 +855,10 @@
 
 	assert(bc->bc_magic == BLOCKIF_SIG);
 	return (bc->bc_candelete);
+}
+
+int
+blockif_nmrr(struct blockif_ctxt *bc)
+{
+	return (bc->bc_nmrr);
 }
diff -u -r -N usr.sbin/bhyve/block_if.h usr.sbin/bhyvenmrr/block_if.h
--- usr.sbin/bhyve/block_if.h	2020-03-11 18:09:31.559563000 +0900
+++ usr.sbin/bhyvenmrr/block_if.h	2020-03-11 17:44:40.843631000 +0900
@@ -68,6 +68,7 @@
 int	blockif_queuesz(struct blockif_ctxt *bc);
 int	blockif_is_ro(struct blockif_ctxt *bc);
 int	blockif_candelete(struct blockif_ctxt *bc);
+int	blockif_nmrr(struct blockif_ctxt *bc);
 int	blockif_read(struct blockif_ctxt *bc, struct blockif_req *breq);
 int	blockif_write(struct blockif_ctxt *bc, struct blockif_req *breq);
 int	blockif_flush(struct blockif_ctxt *bc, struct blockif_req *breq);
diff -u -r -N usr.sbin/bhyve/pci_ahci.c usr.sbin/bhyvenmrr/pci_ahci.c
--- usr.sbin/bhyve/pci_ahci.c	2020-03-11 18:09:31.559350000 +0900
+++ usr.sbin/bhyvenmrr/pci_ahci.c	2020-03-11 18:16:55.952888000 +0900
@@ -1069,6 +1069,7 @@
 		}
 		buf[119] = (ATA_SUPPORT_RWLOGDMAEXT | 1 << 14);
 		buf[120] = (ATA_SUPPORT_RWLOGDMAEXT | 1 << 14);
+		buf[217] = blockif_nmrr(p->bctx);
 		buf[222] = 0x1020;
 		buf[255] = 0x00a5;
 		ahci_checksum((uint8_t *)buf, sizeof(buf));
diff -u -r -N usr.sbin/bhyve/pci_nvme.c usr.sbin/bhyvenmrr/pci_nvme.c
--- usr.sbin/bhyve/pci_nvme.c	2020-03-11 18:09:31.559032000 +0900
+++ usr.sbin/bhyvenmrr/pci_nvme.c	2020-03-09 15:42:39.491514000 +0900
@@ -451,6 +451,9 @@
 
 	memset(&sc->err_log, 0, sizeof(sc->err_log));
 	memset(&sc->health_log, 0, sizeof(sc->health_log));
+sc->health_log.temperature=311;
+sc->health_log.available_spare=100;
+sc->health_log.available_spare_threshold=10;
 	memset(&sc->fw_log, 0, sizeof(sc->fw_log));
 }
 

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANBJ%2BxQv2%2Bpe=jnL6zO=X3MtU=oW%2B1hyEfOmCz205ozGX5U2Mg>