kernel -- vn: Implement BUF_CMD_FLUSH for vn(ode) devices.
authorVenkatesh Srinivas <me@endeavour.zapto.org>
Tue, 8 May 2012 12:33:56 +0000 (05:33 -0700)
committerVenkatesh Srinivas <me@endeavour.zapto.org>
Tue, 8 May 2012 12:33:56 +0000 (05:33 -0700)
File-backed vnode devices implement BUF_CMD_FLUSH by VOP_FSYNC-ing
the backing vnode.

sys/dev/disk/vn/vn.c

index c0fa2a3..18e4053 100644 (file)
@@ -341,14 +341,28 @@ vnstrategy(struct dev_strategy_args *ap)
                 * fs backing the VN device and whatever is running on
                 * the VN device.
                 */
-               if (bp->b_cmd == BUF_CMD_READ) {
+               switch (bp->b_cmd) {
+               case (BUF_CMD_READ):
                        vn_lock(vn->sc_vp, LK_SHARED | LK_RETRY);
                        error = VOP_READ(vn->sc_vp, &auio, IO_RECURSE,
                                         vn->sc_cred);
-               } else {
+                       break;
+
+               case (BUF_CMD_WRITE):
                        vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY);
                        error = VOP_WRITE(vn->sc_vp, &auio, IO_RECURSE,
                                          vn->sc_cred);
+                       break;
+
+               case (BUF_CMD_FLUSH):
+                       auio.uio_resid = 0;
+                       vn_lock(vn->sc_vp, LK_EXCLUSIVE | LK_RETRY);
+                       error = VOP_FSYNC(vn->sc_vp, MNT_WAIT, 0);
+                       break;
+               default:
+                       auio.uio_resid = 0;
+                       error = 0;
+                       break;
                }
                vn_unlock(vn->sc_vp);
                bp->b_resid = auio.uio_resid;