Author: cem
Date: Wed Oct  7 20:31:13 2020
New Revision: 366521
URL: https://svnweb.freebsd.org/changeset/base/366521

Log:
  bhyveload(8): Implement loader_callbacks::diskwrite
  
  The method was optional prior to r365938, which made it mandatory but did add
  any test that an implementation provides the method nor implement it for
  bhyveload.  The code path might not be hit unless the user's loader was
  configured to write to a file on disk, such as with nextboot(8).
  
  Reviewed by:  grehan, tsoome
  Approved by:  bhyve
  X-MFC-With:   r365938
  Differential Revision:        https://reviews.freebsd.org/D26710

Modified:
  head/usr.sbin/bhyveload/bhyveload.c

Modified: head/usr.sbin/bhyveload/bhyveload.c
==============================================================================
--- head/usr.sbin/bhyveload/bhyveload.c Wed Oct  7 20:09:26 2020        
(r366520)
+++ head/usr.sbin/bhyveload/bhyveload.c Wed Oct  7 20:31:13 2020        
(r366521)
@@ -300,11 +300,11 @@ cb_stat(void *arg, void *h, struct stat *sbp)
 
 static int
 cb_diskread(void *arg, int unit, uint64_t from, void *to, size_t size,
-           size_t *resid)
+    size_t *resid)
 {
        ssize_t n;
 
-       if (unit < 0 || unit >= ndisks )
+       if (unit < 0 || unit >= ndisks)
                return (EIO);
        n = pread(disk_fd[unit], to, size, from);
        if (n < 0)
@@ -314,6 +314,21 @@ cb_diskread(void *arg, int unit, uint64_t from, void *
 }
 
 static int
+cb_diskwrite(void *arg, int unit, uint64_t offset, void *src, size_t size,
+    size_t *resid)
+{
+       ssize_t n;
+
+       if (unit < 0 || unit >= ndisks)
+               return (EIO);
+       n = pwrite(disk_fd[unit], src, size, offset);
+       if (n < 0)
+               return (errno);
+       *resid = size - n;
+       return (0);
+}
+
+static int
 cb_diskioctl(void *arg, int unit, u_long cmd, void *data)
 {
        struct stat sb;
@@ -611,6 +626,7 @@ static struct loader_callbacks cb = {
        .stat = cb_stat,
 
        .diskread = cb_diskread,
+       .diskwrite = cb_diskwrite,
        .diskioctl = cb_diskioctl,
 
        .copyin = cb_copyin,
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to