X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fext2fs%2Fmmp.c;h=eb9417020e6d3fa8627433106f6919f5bc41671f;hb=dcdf3ac77a13a131dcbf54bdb61fa75eb9eee9a8;hp=c21ae272f0e3b8ed2dde78ad426b3647e7e75d06;hpb=b741827a4f766d7503c334994f6c7fa29b3a0018;p=platform%2Fupstream%2Fe2fsprogs.git diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c index c21ae27..eb94170 100644 --- a/lib/ext2fs/mmp.c +++ b/lib/ext2fs/mmp.c @@ -57,21 +57,21 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf) * regardless of how the io_manager is doing reads, to avoid caching of * the MMP block by the io_manager or the VM. It needs to be fresh. */ if (fs->mmp_fd <= 0) { - int flags = O_RDWR | O_DIRECT; + struct stat st; + int flags = O_RDONLY | O_DIRECT; + + /* + * There is no reason for using O_DIRECT if we're working with + * regular file. Disabling it also avoids problems with + * alignment when the device of the host file system has sector + * size larger than blocksize of the fs we're working with. + */ + if (stat(fs->device_name, &st) == 0 && + S_ISREG(st.st_mode)) + flags &= ~O_DIRECT; -retry: fs->mmp_fd = open(fs->device_name, flags); if (fs->mmp_fd < 0) { - struct stat st; - - /* Avoid O_DIRECT for filesystem image files if open - * fails, since it breaks when running on tmpfs. */ - if (errno == EINVAL && (flags & O_DIRECT) && - stat(fs->device_name, &st) == 0 && - S_ISREG(st.st_mode)) { - flags &= ~O_DIRECT; - goto retry; - } retval = EXT2_ET_MMP_OPEN_DIRECT; goto out; } @@ -356,7 +356,7 @@ clean_seq: #ifdef HAVE_GETHOSTNAME gethostname((char *) mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename)); #else - strcpy(mmp_s->mmp_nodename, "unknown host"); + strcpy((char *) mmp_s->mmp_nodename, "unknown host"); #endif strncpy((char *) mmp_s->mmp_bdevname, fs->device_name, sizeof(mmp_s->mmp_bdevname)); @@ -403,10 +403,11 @@ errcode_t ext2fs_mmp_stop(ext2_filsys fs) errcode_t retval = 0; if (!ext2fs_has_feature_mmp(fs->super) || - !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) + !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP) || + (fs->mmp_buf == NULL) || (fs->mmp_cmp == NULL)) goto mmp_error; - retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL); if (retval) goto mmp_error;