summaryrefslogtreecommitdiff
path: root/ufs/pokeloc.c
blob: d09942e84431b0d090fbd1d2b18e137364304c76 (plain)
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
/* Remember where we've written the disk to speed up sync
   Copyright (C) 1994, 1996 Free Software Foundation, Inc.
   Written by Michael I. Bushnell.

   This file is part of the GNU Hurd.

   The GNU Hurd 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.

   The GNU Hurd 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., 675 Mass Ave, Cambridge, MA 02139, USA. */

#include "ufs.h"

struct pokeloc
{
  vm_offset_t offset;
  vm_size_t length;
  struct pokeloc *next;
};

struct pokeloc *pokelist;
spin_lock_t pokelistlock = SPIN_LOCK_INITIALIZER;

/* Remember that data here on the disk has been modified. */
void
record_poke (void *loc, vm_size_t length)
{
  struct pokeloc *pl = malloc (sizeof (struct pokeloc));
  vm_offset_t offset;

  offset = loc - disk_image;
  pl->offset = trunc_page (offset);
  pl->length = round_page (offset + length) - pl->offset;

  spin_lock (&pokelistlock);
  pl->next = pokelist;
  pokelist = pl;
  spin_unlock (&pokelistlock);
}

/* Get rid of any outstanding pokes.  */
void
flush_pokes ()
{
  struct pokeloc *pl;

  spin_lock (&pokelistlock);
  pl = pokelist;
  pokelist = 0;
  spin_unlock (&pokelistlock);

  while (pl)
    {
      struct pokeloc *next = pl->next;
      free (pl);
      pl = next;
    }
}

/* Sync all the modified pieces of disk */
void
sync_disk (int wait)
{
  struct pokeloc *pl, *tmp;

  spin_lock (&pokelistlock);
  for (pl = pokelist; pl; pl = tmp)
    {
      pager_sync_some (disk_pager, pl->offset, pl->length, wait);
      tmp = pl->next;
      free (pl);
    }
  pokelist = 0;
  spin_unlock (&pokelistlock);
}