autoconf: detect existence of linux/fiemap.h

This commit is contained in:
Yehuda Sadeh 2010-08-05 17:19:16 -07:00
parent afb8cdf02e
commit 823c36c290
3 changed files with 63 additions and 8 deletions

View File

@ -141,6 +141,10 @@ AC_CHECK_HEADER([openssl/md5.h],
[],
[AC_MSG_ERROR([Sorry you need openssl dev files (libssl-dev on debian)])])
AC_CHECK_HEADER([linux/fiemap.h],
[AC_DEFINE([HAVE_FIEMAP_H], [], [linux/fiemap.h was found, fiemap ioctl will be used])],
[AC_MSG_NOTICE([linux/fiemap.h was not found, fiemap ioctl will not be used])])
AC_CHECK_HEADERS([sys/xattr.h arpa/inet.h netdb.h netinet/in.h sys/file.h sys/ioctl.h sys/mount.h sys/param.h sys/socket.h sys/statvfs.h sys/time.h sys/vfs.h syslog.h utime.h])
# sync_file_range

View File

@ -35,10 +35,11 @@
#include <errno.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#warning fix fiemap include and define
#include "include/fiemap.h"
#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap)
#ifdef HAVE_FIEMAP_H
#include <linux/fiemap.h>
#endif
#ifndef __CYGWIN__
# include <sys/xattr.h>
@ -130,6 +131,7 @@ bool parse_attrname(char **name)
return false;
}
#ifdef HAVE_FIEMAP_H
static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap)
{
struct fiemap *fiemap = NULL;
@ -175,6 +177,12 @@ done_err:
free(fiemap);
return ret;
}
#else
static int do_fiemap(int fd, off_t start, size_t len, struct fiemap **pfiemap)
{
return -ENOTSUP;
}
#endif
int FileStore::statfs(struct statfs *buf)
{
@ -1395,6 +1403,7 @@ int FileStore::read(coll_t cid, const sobject_t& oid,
return r;
}
#ifdef HAVE_FIEMAP_H
int FileStore::fiemap(coll_t cid, const sobject_t& oid,
uint64_t offset, size_t len,
bufferlist& bl)
@ -1405,7 +1414,7 @@ int FileStore::fiemap(coll_t cid, const sobject_t& oid,
get_coname(cid, oid, fn, sizeof(fn));
dout(15) << "read " << fn << " " << offset << "~" << len << dendl;
dout(15) << "fiemap " << fn << " " << offset << "~" << len << dendl;
int r;
int fd = ::open(fn, O_RDONLY);
@ -1461,7 +1470,17 @@ done:
free(fiemap);
return r;
}
#else
int FileStore::fiemap(coll_t cid, const sobject_t& oid,
uint64_t offset, size_t len,
bufferlist& bl)
{
map<off_t, size_t> m;
m[offset] = len;
::encode(m, bl);
return 0;
}
#endif
int FileStore::_remove(coll_t cid, const sobject_t& oid)

View File

@ -38,9 +38,34 @@ using namespace librados;
#include "include/rbd_types.h"
#warning fix fiemap include and define
#include "include/fiemap.h"
#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap)
#include <linux/fs.h>
#ifdef HAVE_FIEMAP_H
#include <linux/fiemap.h>
#else
/*
the following structures differ from the original structures
and should only be used in the following code. Using it for
the fiemap ioctl will not work.
*/
struct fiemap_extent {
__u64 fe_logical;
__u64 fe_physical;
__u64 fe_length;
__u32 fe_flags;
};
struct fiemap {
__u64 fm_start;
__u64 fm_length;
__u32 fm_flags;
__u32 fm_mapped_extents;
__u32 fm_extent_count;
struct fiemap_extent fm_extents[0];
};
#endif
struct pools {
pool_t md;
@ -759,6 +784,7 @@ done_img:
update_snap_name(*new_img, snap);
}
#ifdef HAVE_FIEMAP_H
/*
* the following function was taken from fiemap.c by Colin Ian King, colin.king@canonical.com
*/
@ -809,6 +835,12 @@ done_err:
free(fiemap);
return NULL;
}
#else
static struct fiemap *read_fiemap(int fd)
{
return NULL;
}
#endif
static int do_import(pool_t pool, const char *imgname, int order, const char *path)
{