Print this page
6494 ASSERT supported zio_types for file and disk vdevs
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Approved by: Albert Lee <trisk@omniti.com>
NEX-4229 Panic destroying the pool using file backing store on FS with nbmand=on
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-3958 CLONE - Port NEX-3957 TRIM on file-backed vdevs is broken
Reviewed by: Alek Pinchuk <alek@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-3508 CLONE - Port NEX-2946 Add UNMAP/TRIM functionality to ZFS and illumos
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Conflicts:
    usr/src/uts/common/io/scsi/targets/sd.c
    usr/src/uts/common/sys/scsi/targets/sddef.h

@@ -19,10 +19,11 @@
  * CDDL HEADER END
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  */
 
 #include <sys/zfs_context.h>
 #include <sys/spa.h>
 #include <sys/spa_impl.h>

@@ -29,10 +30,13 @@
 #include <sys/vdev_file.h>
 #include <sys/vdev_impl.h>
 #include <sys/zio.h>
 #include <sys/fs/zfs.h>
 #include <sys/fm/fs/zfs.h>
+#include <sys/fcntl.h>
+#include <sys/vnode.h>
+#include <sys/dkioc_free_util.h>
 #include <sys/abd.h>
 
 /*
  * Virtual device vector for files.
  */

@@ -124,18 +128,26 @@
 
 static void
 vdev_file_close(vdev_t *vd)
 {
         vdev_file_t *vf = vd->vdev_tsd;
+        caller_context_t ct = {0};
 
         if (vd->vdev_reopening || vf == NULL)
                 return;
 
         if (vf->vf_vnode != NULL) {
                 (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
+                /*
+                 * We need to supply caller context with PID zero to fop_close
+                 * in order to clean properly a share reservation which might
+                 * have been created by vdev_file_open if nbmand was "on" for
+                 * underlaying filesystem. Mismatched PIDs in create and delete
+                 * reservation calls would lead to orphaned reservation.
+                 */
                 (void) VOP_CLOSE(vf->vf_vnode, spa_mode(vd->vdev_spa), 1, 0,
-                    kcred, NULL);
+                    kcred, &ct);
                 VN_RELE(vf->vf_vnode);
         }
 
         vd->vdev_delayed_close = B_FALSE;
         kmem_free(vf, sizeof (vdev_file_t));

@@ -208,10 +220,37 @@
                 switch (zio->io_cmd) {
                 case DKIOCFLUSHWRITECACHE:
                         zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
                             kcred, NULL);
                         break;
+                case DKIOCFREE:
+                {
+                        dkioc_free_list_t *dfl = zio->io_private;
+
+                        ASSERT(dfl != NULL);
+                        for (int i = 0; i < dfl->dfl_num_exts; i++) {
+                                struct flock64 flck;
+                                int error;
+
+                                if (dfl->dfl_exts[i].dfle_length == 0)
+                                        continue;
+
+                                bzero(&flck, sizeof (flck));
+                                flck.l_type = F_FREESP;
+                                flck.l_start = dfl->dfl_exts[i].dfle_start +
+                                    dfl->dfl_offset;
+                                flck.l_len = dfl->dfl_exts[i].dfle_length;
+
+                                error = VOP_SPACE(vf->vf_vnode,
+                                    F_FREESP, &flck, 0, 0, kcred, NULL);
+                                if (error != 0) {
+                                        zio->io_error = SET_ERROR(error);
+                                        break;
+                                }
+                        }
+                        break;
+                }
                 default:
                         zio->io_error = SET_ERROR(ENOTSUP);
                 }
 
                 zio_execute(zio);