3939#include <linux/list.h>
4040#include <linux/delay.h>
4141#include <linux/freezer.h>
42- #include <linux/loop.h>
43- #include <linux/falloc.h>
44- #include <linux/fs.h>
4542
4643#include <xen/events.h>
4744#include <xen/page.h>
@@ -362,7 +359,7 @@ static int xen_blkbk_map(struct blkif_request *req,
362359{
363360 struct gnttab_map_grant_ref map [BLKIF_MAX_SEGMENTS_PER_REQUEST ];
364361 int i ;
365- int nseg = req -> nr_segments ;
362+ int nseg = req -> u . rw . nr_segments ;
366363 int ret = 0 ;
367364
368365 /*
@@ -416,30 +413,25 @@ static int xen_blkbk_map(struct blkif_request *req,
416413 return ret ;
417414}
418415
419- static void xen_blk_discard (struct xen_blkif * blkif , struct blkif_request * req )
416+ static int dispatch_discard_io (struct xen_blkif * blkif ,
417+ struct blkif_request * req )
420418{
421419 int err = 0 ;
422420 int status = BLKIF_RSP_OKAY ;
423421 struct block_device * bdev = blkif -> vbd .bdev ;
424422
425- if (blkif -> blk_backend_type == BLKIF_BACKEND_PHY )
426- /* just forward the discard request */
423+ blkif -> st_ds_req ++ ;
424+
425+ xen_blkif_get (blkif );
426+ if (blkif -> blk_backend_type == BLKIF_BACKEND_PHY ||
427+ blkif -> blk_backend_type == BLKIF_BACKEND_FILE ) {
428+ unsigned long secure = (blkif -> vbd .discard_secure &&
429+ (req -> u .discard .flag & BLKIF_DISCARD_SECURE )) ?
430+ BLKDEV_DISCARD_SECURE : 0 ;
427431 err = blkdev_issue_discard (bdev ,
428432 req -> u .discard .sector_number ,
429433 req -> u .discard .nr_sectors ,
430- GFP_KERNEL , 0 );
431- else if (blkif -> blk_backend_type == BLKIF_BACKEND_FILE ) {
432- /* punch a hole in the backing file */
433- struct loop_device * lo = bdev -> bd_disk -> private_data ;
434- struct file * file = lo -> lo_backing_file ;
435-
436- if (file -> f_op -> fallocate )
437- err = file -> f_op -> fallocate (file ,
438- FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE ,
439- req -> u .discard .sector_number << 9 ,
440- req -> u .discard .nr_sectors << 9 );
441- else
442- err = - EOPNOTSUPP ;
434+ GFP_KERNEL , secure );
443435 } else
444436 err = - EOPNOTSUPP ;
445437
@@ -449,7 +441,9 @@ static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req)
449441 } else if (err )
450442 status = BLKIF_RSP_ERROR ;
451443
452- make_response (blkif , req -> id , req -> operation , status );
444+ make_response (blkif , req -> u .discard .id , req -> operation , status );
445+ xen_blkif_put (blkif );
446+ return err ;
453447}
454448
455449static void xen_blk_drain_io (struct xen_blkif * blkif )
@@ -573,8 +567,11 @@ __do_block_io_op(struct xen_blkif *blkif)
573567
574568 /* Apply all sanity checks to /private copy/ of request. */
575569 barrier ();
576-
577- if (dispatch_rw_block_io (blkif , & req , pending_req ))
570+ if (unlikely (req .operation == BLKIF_OP_DISCARD )) {
571+ free_req (pending_req );
572+ if (dispatch_discard_io (blkif , & req ))
573+ break ;
574+ } else if (dispatch_rw_block_io (blkif , & req , pending_req ))
578575 break ;
579576
580577 /* Yield point for this unbounded loop. */
@@ -633,33 +630,29 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
633630 blkif -> st_f_req ++ ;
634631 operation = WRITE_FLUSH ;
635632 break ;
636- case BLKIF_OP_DISCARD :
637- blkif -> st_ds_req ++ ;
638- operation = REQ_DISCARD ;
639- break ;
640633 default :
641634 operation = 0 ; /* make gcc happy */
642635 goto fail_response ;
643636 break ;
644637 }
645638
646639 /* Check that the number of segments is sane. */
647- nseg = req -> nr_segments ;
648- if ( unlikely ( nseg == 0 && operation != WRITE_FLUSH &&
649- operation != REQ_DISCARD ) ||
640+ nseg = req -> u . rw . nr_segments ;
641+
642+ if ( unlikely ( nseg == 0 && operation != WRITE_FLUSH ) ||
650643 unlikely (nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST )) {
651644 pr_debug (DRV_PFX "Bad number of segments in request (%d)\n" ,
652645 nseg );
653646 /* Haven't submitted any bio's yet. */
654647 goto fail_response ;
655648 }
656649
657- preq .dev = req -> handle ;
650+ preq .dev = req -> u . rw . handle ;
658651 preq .sector_number = req -> u .rw .sector_number ;
659652 preq .nr_sects = 0 ;
660653
661654 pending_req -> blkif = blkif ;
662- pending_req -> id = req -> id ;
655+ pending_req -> id = req -> u . rw . id ;
663656 pending_req -> operation = req -> operation ;
664657 pending_req -> status = BLKIF_RSP_OKAY ;
665658 pending_req -> nr_pages = nseg ;
@@ -707,7 +700,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
707700 * the hypercall to unmap the grants - that is all done in
708701 * xen_blkbk_unmap.
709702 */
710- if (operation != REQ_DISCARD && xen_blkbk_map (req , pending_req , seg ))
703+ if (xen_blkbk_map (req , pending_req , seg ))
711704 goto fail_flush ;
712705
713706 /*
@@ -739,23 +732,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
739732
740733 /* This will be hit if the operation was a flush or discard. */
741734 if (!bio ) {
742- BUG_ON (operation != WRITE_FLUSH && operation != REQ_DISCARD );
735+ BUG_ON (operation != WRITE_FLUSH );
743736
744- if (operation == WRITE_FLUSH ) {
745- bio = bio_alloc (GFP_KERNEL , 0 );
746- if (unlikely (bio == NULL ))
747- goto fail_put_bio ;
737+ bio = bio_alloc (GFP_KERNEL , 0 );
738+ if (unlikely (bio == NULL ))
739+ goto fail_put_bio ;
748740
749- biolist [nbio ++ ] = bio ;
750- bio -> bi_bdev = preq .bdev ;
751- bio -> bi_private = pending_req ;
752- bio -> bi_end_io = end_block_io_op ;
753- } else if (operation == REQ_DISCARD ) {
754- xen_blk_discard (blkif , req );
755- xen_blkif_put (blkif );
756- free_req (pending_req );
757- return 0 ;
758- }
741+ biolist [nbio ++ ] = bio ;
742+ bio -> bi_bdev = preq .bdev ;
743+ bio -> bi_private = pending_req ;
744+ bio -> bi_end_io = end_block_io_op ;
759745 }
760746
761747 /*
@@ -784,7 +770,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
784770 xen_blkbk_unmap (pending_req );
785771 fail_response :
786772 /* Haven't submitted any bio's yet. */
787- make_response (blkif , req -> id , req -> operation , BLKIF_RSP_ERROR );
773+ make_response (blkif , req -> u . rw . id , req -> operation , BLKIF_RSP_ERROR );
788774 free_req (pending_req );
789775 msleep (1 ); /* back off a bit */
790776 return - EIO ;
0 commit comments