infa: introduce wrapper layer for compatibiliy with multiple kernels

This is needed for adaptation of the out-of-tree MARS version to multiple
kernel versions.

It will be much simplified after upstream merging, and/or
removed/replaced by something better.
This commit is contained in:
Thomas Schoebel-Theuer 2015-08-26 09:29:55 +02:00
parent 79c7ffe9d4
commit eaa6fc0efc
2 changed files with 106 additions and 1 deletions

46
kernel/compat.h Normal file
View File

@ -0,0 +1,46 @@
/*
* MARS Long Distance Replication Software
*
* This file is part of MARS project: http://schoebel.github.io/mars/
*
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
* Copyright (C) 2011-2014 1&1 Internet AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _MARS_COMPAT
#define _MARS_COMPAT
#include <linux/major.h>
/* TRANSITIONAL compatibility to BOTH the old prepatch
* and the new wrappers around vfs_*().
*/
#ifdef MARS_MAJOR
#define HAS_MARS_PREPATCH
#else
#define MARS_MAJOR (DRBD_MAJOR + 1)
#endif
#ifdef HAS_MARS_PREPATCH
#include <linux/syscalls.h>
#else /* HAS_MARS_PREPATCH */
#endif /* HAS_MARS_PREPATCH */
#endif /* _MARS_COMPAT */

View File

@ -34,6 +34,8 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/namei.h>
#include <linux/mount.h>
#include <linux/utsname.h> #include <linux/utsname.h>
#include "strategy.h" #include "strategy.h"
@ -41,7 +43,7 @@
#include "../lib_mapfree.h" #include "../lib_mapfree.h"
#include "../mars_client.h" #include "../mars_client.h"
#include <linux/syscalls.h> #include "../compat.h"
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/statfs.h> #include <linux/statfs.h>
@ -51,6 +53,12 @@
// remove_this // remove_this
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/version.h> #include <linux/version.h>
#ifndef DCACHE_MISS_TYPE /* define accessors compatible to b18825a7c8e37a7cf6abb97a12a6ad71af160de7 */
#define d_is_negative(dentry) ((dentry)->d_inode == NULL)
#define d_backing_inode(dentry) ((dentry)->d_inode)
#endif
/* FIXME: some Redhat/openvz kernels seem to have both (backporting etc). /* FIXME: some Redhat/openvz kernels seem to have both (backporting etc).
* The folling is an incomplete quickfix / workaround. TBD. * The folling is an incomplete quickfix / workaround. TBD.
*/ */
@ -99,6 +107,57 @@ const struct meta mars_dent_meta[] = {
}; };
EXPORT_SYMBOL_GPL(mars_dent_meta); EXPORT_SYMBOL_GPL(mars_dent_meta);
// remove_this
#ifndef HAS_MARS_PREPATCH
/////////////////////////////////////////////////////////////////////
/* The _compat_*() functions are needed for the out-of-tree version
* of MARS for adapdation to different kernel version.
*/
#ifdef SB_FREEZE_LEVELS
/* since kernel 3.6 */
/* see a8104a9fcdeb82e22d7acd55fca20746581067d3 */
/* locking order changes in c30dabfe5d10c5fd70d882e5afb8f59f2942b194, we need to adapt */
#define __NEW_PATH_CREATE
#endif
#ifndef FSCACHE_OP_DEAD
/* since kernel 3.8 */
/* see b9d6ba94b875192ef5e2dab92d72beea33b83c3d */
#define __HAS_RETRY_ESTALE
#endif
/* Hack because of 8bcb77fabd7cbabcad49f58750be8683febee92b
*/
static int __path_parent(const char *name, struct path *path, unsigned flags)
{
#ifdef user_path
return kern_path(name, flags | LOOKUP_PARENT | LOOKUP_DIRECTORY | LOOKUP_FOLLOW, path);
#else
char *tmp;
int len;
int error;
len = strlen(name);
while (len > 0 && name[len] != '/')
len--;
if (unlikely(!len))
return -EINVAL;
tmp = brick_string_alloc(len + 1);
strncpy(tmp, name, len);
tmp[len] = '\0';
error = kern_path(tmp, flags | LOOKUP_DIRECTORY | LOOKUP_FOLLOW, path);
brick_string_free(tmp);
return error;
#endif
}
#endif
// end_remove_this
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// some helpers // some helpers