1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 Inktank, Inc
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "XfsFileStoreBackend.h"
19 #include <sys/ioctl.h>
22 #include <sys/utsname.h>
26 #include "common/errno.h"
27 #include "common/linux_version.h"
28 #include "include/assert.h"
29 #include "include/compat.h"
31 #define dout_context cct()
32 #define dout_subsys ceph_subsys_filestore
34 #define dout_prefix *_dout << "xfsfilestorebackend(" << get_basedir_path() << ") "
36 XfsFileStoreBackend::XfsFileStoreBackend(FileStore *fs):
37 GenericFileStoreBackend(fs), m_has_extsize(false) { }
40 * Set extsize attr on a file to val. Should be a free-standing
41 * function, but dout_prefix expanding to a call to get_basedir_path()
42 * protected member function won't let it.
44 int XfsFileStoreBackend::set_extsize(int fd, unsigned int val)
50 if (fstat(fd, &sb) < 0) {
52 dout(0) << "set_extsize: fstat: " << cpp_strerror(ret) << dendl;
55 if (!S_ISREG(sb.st_mode)) {
56 dout(0) << "set_extsize: invalid target file type" << dendl;
60 if (ioctl(fd, XFS_IOC_FSGETXATTR, &fsx) < 0) {
62 dout(0) << "set_extsize: FSGETXATTR: " << cpp_strerror(ret) << dendl;
67 if ((fsx.fsx_xflags & XFS_XFLAG_EXTSIZE) && fsx.fsx_extsize == val)
70 // xfs won't change extent size if any extents are allocated
71 if (fsx.fsx_nextents != 0)
74 fsx.fsx_xflags |= XFS_XFLAG_EXTSIZE;
75 fsx.fsx_extsize = val;
77 if (ioctl(fd, XFS_IOC_FSSETXATTR, &fsx) < 0) {
79 dout(0) << "set_extsize: FSSETXATTR: " << cpp_strerror(ret) << dendl;
86 int XfsFileStoreBackend::detect_features()
90 ret = GenericFileStoreBackend::detect_features();
95 int fd = ::openat(get_basedir_fd(), "extsize_test", O_CREAT|O_WRONLY, 0600);
98 dout(0) << "detect_feature: failed to create test file for extsize attr: "
99 << cpp_strerror(ret) << dendl;
102 if (::unlinkat(get_basedir_fd(), "extsize_test", 0) < 0) {
104 dout(0) << "detect_feature: failed to unlink test file for extsize attr: "
105 << cpp_strerror(ret) << dendl;
109 if (cct()->_conf->filestore_xfs_extsize) {
110 ret = set_extsize(fd, 1U << 15); // a few pages
113 dout(0) << "detect_feature: failed to set test file extsize, assuming extsize is NOT supported" << dendl;
117 // make sure we have 3.5 or newer, which includes this fix
118 // aff3a9edb7080f69f07fe76a8bd089b3dfa4cb5d
119 // for this set_extsize bug
120 // http://oss.sgi.com/bugzilla/show_bug.cgi?id=874
121 int ver = get_linux_version();
123 dout(0) << __func__ << ": couldn't verify extsize not buggy, disabling extsize" << dendl;
124 m_has_extsize = false;
125 } else if (ver < KERNEL_VERSION(3, 5, 0)) {
126 dout(0) << __func__ << ": disabling extsize, your kernel < 3.5 and has buggy extsize ioctl" << dendl;
127 m_has_extsize = false;
129 dout(0) << __func__ << ": extsize is supported and your kernel >= 3.5" << dendl;
130 m_has_extsize = true;
133 dout(0) << "detect_feature: extsize is disabled by conf" << dendl;
137 TEMP_FAILURE_RETRY(::close(fd));
142 int XfsFileStoreBackend::set_alloc_hint(int fd, uint64_t hint)
147 assert(hint < UINT_MAX);
148 return set_extsize(fd, hint);