577 size_t ocount = 0, count;
578 loff_t pos;
579 int need_i_mutex;
580
581 XFS_STATS_INC(xs_write_calls);
582
583 error = generic_segment_checks(iovp, &segs, &ocount, VERIFY_READ);
584 if (error)
585 return error;
586
587 count = ocount;
588 pos = *offset;
589
590 if (count == 0)
591 return 0;
592
593 mp = xip->i_mount;
594
595 xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
596
597 if (XFS_FORCED_SHUTDOWN(mp))
598 return -EIO;
599
600relock:
601 if (ioflags & IO_ISDIRECT) {
602 iolock = XFS_IOLOCK_SHARED;
603 need_i_mutex = 0;
604 } else {
605 iolock = XFS_IOLOCK_EXCL;
606 need_i_mutex = 1;
607 mutex_lock(&inode->i_mutex);
608 }
609
610 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
611
612start:
613 error = -generic_write_checks(file, &pos, &count,
614 S_ISBLK(inode->i_mode));
615 if (error) {
616 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
617 goto out_unlock_mutex;