2014-11-21 10:51:34 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-01-23 11:21:22 +00:00
|
|
|
#ifndef MARS_LIB_MAPFREE_H
|
|
|
|
#define MARS_LIB_MAPFREE_H
|
|
|
|
|
|
|
|
/* Mapfree infrastructure.
|
|
|
|
*
|
|
|
|
* Purposes:
|
|
|
|
*
|
|
|
|
* 1) Open files only once when possible, do ref-counting on struct mapfree_info
|
|
|
|
*
|
|
|
|
* 2) Automatically call invalidate_mapping_pages() in the background on
|
|
|
|
* "unused" areas to free resources.
|
|
|
|
* Used areas can be indicated by calling mapfree_set() frequently.
|
|
|
|
* Usage model: tailored to sequential logfiles.
|
|
|
|
*
|
|
|
|
* 3) Do it all in a completely decoupled manner, in order to prevent resource deadlocks.
|
|
|
|
*
|
|
|
|
* 4) Also to prevent deadlocks: always set mapping_set_gfp_mask() accordingly.
|
|
|
|
*/
|
|
|
|
|
2017-12-09 10:16:50 +00:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
|
2013-01-23 11:21:22 +00:00
|
|
|
#include "mars.h"
|
|
|
|
|
|
|
|
extern int mapfree_period_sec;
|
2013-09-16 09:51:03 +00:00
|
|
|
extern int mapfree_grace_keep_mb;
|
2013-01-23 11:21:22 +00:00
|
|
|
|
2017-12-10 09:57:53 +00:00
|
|
|
enum dirty_stage {
|
|
|
|
DIRTY_SUBMITTED,
|
2022-06-05 08:04:49 +00:00
|
|
|
DIRTY_COMPLETING,
|
2017-12-10 09:57:53 +00:00
|
|
|
DIRTY_FINISHED,
|
|
|
|
/* Keep this the last element */
|
|
|
|
DIRTY_MAX
|
2022-03-28 14:18:41 +00:00
|
|
|
} __packed;
|
2017-12-10 09:57:53 +00:00
|
|
|
|
|
|
|
struct dirty_length {
|
|
|
|
rwlock_t dl_lock;
|
2020-11-05 07:30:05 +00:00
|
|
|
u64 dl_appends;
|
2017-12-10 09:57:53 +00:00
|
|
|
loff_t dl_length;
|
|
|
|
};
|
|
|
|
|
2013-01-23 11:21:22 +00:00
|
|
|
struct mapfree_info {
|
|
|
|
struct list_head mf_head;
|
2014-03-30 06:18:47 +00:00
|
|
|
struct list_head mf_dirty_anchor;
|
2013-01-23 11:21:22 +00:00
|
|
|
char *mf_name;
|
|
|
|
struct file *mf_filp;
|
|
|
|
int mf_flags;
|
2015-02-10 09:45:40 +00:00
|
|
|
int mf_mode;
|
2013-01-23 11:21:22 +00:00
|
|
|
atomic_t mf_count;
|
2020-09-08 08:13:17 +00:00
|
|
|
/* private */
|
2017-12-09 10:16:50 +00:00
|
|
|
struct rw_semaphore mf_mutex;
|
2013-01-23 11:21:22 +00:00
|
|
|
loff_t mf_min[2];
|
|
|
|
loff_t mf_last;
|
2013-04-16 07:37:54 +00:00
|
|
|
loff_t mf_max;
|
2013-01-23 11:21:22 +00:00
|
|
|
long long mf_jiffies;
|
2020-09-08 08:13:17 +00:00
|
|
|
unsigned int mf_hash;
|
2021-11-02 09:42:47 +00:00
|
|
|
bool mf_finished;
|
2017-12-10 09:57:53 +00:00
|
|
|
struct dirty_length mf_length[DIRTY_MAX];
|
2013-01-23 11:21:22 +00:00
|
|
|
};
|
|
|
|
|
2020-09-30 08:34:14 +00:00
|
|
|
struct mapfree_info *mapfree_get(const char *filename, int flags, int *error);
|
2013-01-23 11:21:22 +00:00
|
|
|
|
|
|
|
void mapfree_put(struct mapfree_info *mf);
|
|
|
|
|
2013-04-16 07:37:54 +00:00
|
|
|
void mapfree_set(struct mapfree_info *mf, loff_t min, loff_t max);
|
2013-01-23 11:21:22 +00:00
|
|
|
|
2015-06-08 12:32:29 +00:00
|
|
|
void mapfree_pages(struct mapfree_info *mf, int grace_keep);
|
|
|
|
|
2020-11-05 06:43:22 +00:00
|
|
|
loff_t mapfree_real_size(struct mapfree_info *mf);
|
|
|
|
|
2017-12-10 09:57:53 +00:00
|
|
|
////////////////// dirty IOs in append mode //////////////////
|
|
|
|
|
|
|
|
void mf_dirty_append(struct mapfree_info *mf, enum dirty_stage stage, loff_t newlen);
|
2020-04-04 08:42:01 +00:00
|
|
|
void mf_dirty_reduce(struct mapfree_info *mf, enum dirty_stage stage, loff_t newlen);
|
2017-12-10 09:57:53 +00:00
|
|
|
loff_t mf_dirty_length(struct mapfree_info *mf, enum dirty_stage stage);
|
|
|
|
|
2014-03-30 06:18:47 +00:00
|
|
|
////////////////// dirty IOs on the fly //////////////////
|
|
|
|
|
2017-12-10 10:30:21 +00:00
|
|
|
loff_t mf_get_any_dirty(const char *filename, int stage);
|
2014-03-30 06:18:47 +00:00
|
|
|
|
2013-01-23 11:21:22 +00:00
|
|
|
////////////////// module init stuff /////////////////////////
|
|
|
|
|
|
|
|
int __init init_mars_mapfree(void);
|
|
|
|
|
2014-04-23 11:16:26 +00:00
|
|
|
void exit_mars_mapfree(void);
|
2013-01-23 11:21:22 +00:00
|
|
|
|
|
|
|
#endif
|