File: dmfs-error.c

package info (click to toggle)
devmapper 2%3A1.01.00-4sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,044 kB
  • ctags: 2,336
  • sloc: ansic: 11,777; sh: 2,695; makefile: 291; perl: 16
file content (136 lines) | stat: -rw-r--r-- 3,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * dmfs-error.c
 *
 * Copyright (C) 2001 Sistina Software
 *
 * This software 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, or (at
 * your option) any later version.
 *
 * This software 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 GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "dm.h"
#include "dmfs.h"

#include <linux/list.h>
#include <linux/seq_file.h>

struct dmfs_error {
	struct list_head list;
	unsigned len;
	char *msg;
};

static struct dmfs_error oom_error;

static struct list_head oom_list = {
	next:	&oom_error.list,
	prev:	&oom_error.list,
};

static struct dmfs_error oom_error = {
	list:	{next: &oom_list, prev:&oom_list},
	len:	39,
	msg:	"Out of memory during creation of table\n",
};

int dmfs_error_revalidate(struct dentry *dentry)
{
	struct inode *inode = dentry->d_inode;
	struct inode *parent = dentry->d_parent->d_inode;

	if (!list_empty(&DMFS_I(parent)->errors))
		inode->i_size = 1;
	else
		inode->i_size = 0;

	return 0;
}

void dmfs_add_error(struct inode *inode, unsigned num, char *str)
{
	struct dmfs_i *dmi = DMFS_I(inode);
	int len = strlen(str) + sizeof(struct dmfs_error) + 12;
	struct dmfs_error *e = kmalloc(len, GFP_KERNEL);

	if (e) {
		e->msg = (char *)(e + 1);
		e->len = sprintf(e->msg, "%8u: %s\n", num, str);
		list_add(&e->list, &dmi->errors);
	}
}

void dmfs_zap_errors(struct inode *inode)
{
	struct dmfs_i *dmi = DMFS_I(inode);
	struct dmfs_error *e;

	while (!list_empty(&dmi->errors)) {
		e = list_entry(dmi->errors.next, struct dmfs_error, list);
		list_del(&e->list);
		kfree(e);
	}
}

static void *e_start(struct seq_file *e, loff_t *pos)
{
	struct list_head *p;
	loff_t n = *pos;
	struct dmfs_i *dmi = e->context;

	down(&dmi->sem);

	if (dmi->status) {
		list_for_each(p, &oom_list)
			if (n-- == 0)
				return list_entry(p, struct dmfs_error, list);
	} else {
		list_for_each(p, &dmi->errors)
			if (n-- == 0)
				return list_entry(p, struct dmfs_error, list);
	}

	return NULL;
}

static void *e_next(struct seq_file *e, void *v, loff_t *pos)
{
	struct dmfs_i *dmi = e->context;
	struct list_head *p = ((struct dmfs_error *)v)->list.next;

	(*pos)++;

	return (p == &dmi->errors) || 
	       (p == &oom_list) ? NULL : list_entry(p, struct dmfs_error, list);
}

static void e_stop(struct seq_file *e, void *v)
{
	struct dmfs_i *dmi = e->context;
	up(&dmi->sem);
}

static int show_error(struct seq_file *e, void *v)
{
	struct dmfs_error *d = v;
	seq_puts(e, d->msg);

	return 0;
}

struct seq_operations dmfs_error_seq_ops = {
	start:	e_start,
	next:	e_next,
	stop:	e_stop,
	show:	show_error,
};