Author: asomers
Date: Mon Aug 12 20:21:36 2019
New Revision: 350956
URL: https://svnweb.freebsd.org/changeset/base/350956

Log:
  MFC r349231, r349233, r349280, r349478
  
  r349231:
  Add FIOBMAP2 ioctl
  
  This ioctl exposes VOP_BMAP information to userland. It can be used by
  programs like fragmentation analyzers and optimized cp implementations. But
  I'm using it to test fusefs's VOP_BMAP implementation. The "2" in the name
  distinguishes it from the similar but incompatible FIBMAP ioctls in NetBSD
  and Linux.  FIOBMAP2 differs from FIBMAP in that it uses a 64-bit block
  number instead of 32-bit, and it also returns runp and runb.
  
  Reviewed by:  mckusick
  Sponsored by: The FreeBSD Foundation
  Differential Revision:        https://reviews.freebsd.org/D20705
  
  r349233:
  #include <sys/types.h> from sys/filio.h
  
  This fixes world build after r349231
  
  Reported by:  Jenkins
  MFC-With:     349231
  Sponsored by: The FreeBSD Foundation
  
  r349280:
  Reduce namespace pollution from r349233
  
  Define __daddr_t in _types.h and use it in filio.h
  
  Reported by:  ian, bde
  Reviewed by:  ian, imp, cem
  MFC-With:     349233
  Sponsored by: The FreeBSD Foundation
  Differential Revision:        https://reviews.freebsd.org/D20715
  
  r349478:
  FIOBMAP2: inline vn_ioc_bmap2
  
  Reported by:  kib
  Reviewed by:  kib
  MFC-With:     349238
  Sponsored by: The FreeBSD Foundation
  Differential Revision:        https://reviews.freebsd.org/D20783

Modified:
  stable/12/sys/kern/vfs_vnops.c
  stable/12/sys/sys/_types.h
  stable/12/sys/sys/filio.h
  stable/12/sys/sys/types.h
  stable/12/sys/ufs/ufs/ufs_bmap.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/vfs_vnops.c
==============================================================================
--- stable/12/sys/kern/vfs_vnops.c      Mon Aug 12 20:00:21 2019        
(r350955)
+++ stable/12/sys/kern/vfs_vnops.c      Mon Aug 12 20:21:36 2019        
(r350956)
@@ -1462,6 +1462,7 @@ vn_ioctl(struct file *fp, u_long com, void *data, stru
 {
        struct vattr vattr;
        struct vnode *vp;
+       struct fiobmap2_arg *bmarg;
        int error;
 
        vp = fp->f_vnode;
@@ -1475,6 +1476,18 @@ vn_ioctl(struct file *fp, u_long com, void *data, stru
                        VOP_UNLOCK(vp, 0);
                        if (error == 0)
                                *(int *)data = vattr.va_size - fp->f_offset;
+                       return (error);
+               case FIOBMAP2:
+                       bmarg = (struct fiobmap2_arg *)data;
+                       vn_lock(vp, LK_SHARED | LK_RETRY);
+#ifdef MAC
+                       error = mac_vnode_check_read(active_cred, fp->f_cred,
+                           vp);
+                       if (error == 0)
+#endif
+                               error = VOP_BMAP(vp, bmarg->bn, NULL,
+                                   &bmarg->bn, &bmarg->runp, &bmarg->runb);
+                       VOP_UNLOCK(vp, 0);
                        return (error);
                case FIONBIO:
                case FIOASYNC:

Modified: stable/12/sys/sys/_types.h
==============================================================================
--- stable/12/sys/sys/_types.h  Mon Aug 12 20:00:21 2019        (r350955)
+++ stable/12/sys/sys/_types.h  Mon Aug 12 20:21:36 2019        (r350956)
@@ -68,6 +68,7 @@ typedef       unsigned int    __useconds_t;   /* microseconds 
(un
 typedef        int             __cpuwhich_t;   /* which parameter for cpuset. 
*/
 typedef        int             __cpulevel_t;   /* level parameter for cpuset. 
*/
 typedef int            __cpusetid_t;   /* cpuset identifier. */
+typedef __int64_t      __daddr_t;      /* bwrite(3), FIOBMAP2, etc */
 
 /*
  * Unusual type definitions.

Modified: stable/12/sys/sys/filio.h
==============================================================================
--- stable/12/sys/sys/filio.h   Mon Aug 12 20:00:21 2019        (r350955)
+++ stable/12/sys/sys/filio.h   Mon Aug 12 20:21:36 2019        (r350956)
@@ -40,6 +40,7 @@
 #ifndef        _SYS_FILIO_H_
 #define        _SYS_FILIO_H_
 
+#include <sys/_types.h>
 #include <sys/ioccom.h>
 
 /* Generic file-descriptor ioctl's. */
@@ -62,5 +63,12 @@ struct fiodgname_arg {
 /* Handle lseek SEEK_DATA and SEEK_HOLE for holey file knowledge. */
 #define        FIOSEEKDATA     _IOWR('f', 97, off_t)   /* SEEK_DATA */
 #define        FIOSEEKHOLE     _IOWR('f', 98, off_t)   /* SEEK_HOLE */
+struct fiobmap2_arg {
+       __daddr_t       bn;
+       int             runp;
+       int             runb;
+};
+/* Get the file's bmap info for the logical block bn. */
+#define        FIOBMAP2        _IOWR('f', 99, struct fiobmap2_arg)
 
 #endif /* !_SYS_FILIO_H_ */

Modified: stable/12/sys/sys/types.h
==============================================================================
--- stable/12/sys/sys/types.h   Mon Aug 12 20:00:21 2019        (r350955)
+++ stable/12/sys/sys/types.h   Mon Aug 12 20:21:36 2019        (r350956)
@@ -101,7 +101,7 @@ typedef     __clockid_t     clockid_t;
 #endif
 
 typedef        __critical_t    critical_t;     /* Critical section value */
-typedef        __int64_t       daddr_t;        /* disk address */
+typedef        __daddr_t       daddr_t;        /* disk address */
 
 #ifndef _DEV_T_DECLARED
 typedef        __dev_t         dev_t;          /* device number or struct cdev 
*/

Modified: stable/12/sys/ufs/ufs/ufs_bmap.c
==============================================================================
--- stable/12/sys/ufs/ufs/ufs_bmap.c    Mon Aug 12 20:00:21 2019        
(r350955)
+++ stable/12/sys/ufs/ufs/ufs_bmap.c    Mon Aug 12 20:21:36 2019        
(r350956)
@@ -200,12 +200,15 @@ ufs_bmaparray(vp, bn, bnp, nbp, runp, runb)
                        *bnp = blkptrtodb(ump, ip->i_din2->di_extb[-1 - bn]);
                        if (*bnp == 0)
                                *bnp = -1;
-                       if (nbp == NULL)
-                               panic("ufs_bmaparray: mapping ext data");
+                       if (nbp == NULL) {
+                               /* indirect block not found */
+                               return (EINVAL);
+                       }
                        nbp->b_xflags |= BX_ALTDATA;
                        return (0);
                } else {
-                       panic("ufs_bmaparray: blkno out of range");
+                       /* blkno out of range */
+                       return (EINVAL);
                }
                /*
                 * Since this is FFS independent code, we are out of
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to