Files
xen/tools/memshr/bidir-daemon.c
T
Ian Campbell 443701ef0c Replace FSF street address with canonical URL
As recommended in http://www.gnu.org/licenses/gpl-howto.en.html.

This is the result of:
$ git grep -El Mass\|Temple\|Franklin | xargs ./fsf.pl

Where fsf.pl is:
    #!/usr/bin/perl -w -pi.bak -0777
    my $repl = 'If not, see <http://www.gnu.org/licenses/>.';
    my $br = qr/(?:\s*\n\s*(?:[\*\#]|\/\/|\.\\" )?\s*|\s+)/;

    my $inwt = qr/[Ii]f${br}not,${br}write${br}(?:to${br})?the${br}Free${br}Software${br}Foundation,(?:${br}Inc\.,)?/;

    my $mass = qr/675${br}Mass${br}Ave,?${br}Cambridge,?${br}MA${br}02139,?${br}USA,?\.?/;
    my $franklin = qr/51${br}Franklin${br}St(?:reet)?(?:,${br}| - )Fifth${br}Floor,?${br}Boston,?${br}MA,?${br}02110-1301,?${br}USA,?\.?/;
    my $temple = qr/59${br}Temple${br}Place(?:,${br}| - )Suite${br}330,?${br}Boston,?${br}MA,?${br}021110?-1307,?${br}USA,?\.?/;

    s|$inwt$br$mass|$repl|m;
    s|$inwt$br$franklin|$repl|m;
    s|$inwt$br$temple|$repl|m;

The only remaining mentions of these addresses are in COPYING files which I
haven't touched.

Some of the changed files are imports from elsewhere, however
filtering them out is tricky, I think it is tolerable to have these
files be modified here and then perhaps reverted on the next sync,
since it's only 1-2 lines and obvious what is going on.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2015-07-29 11:14:07 +01:00

104 lines
3.1 KiB
C

/******************************************************************************
*
* Copyright (c) 2009 Citrix Systems, Inc. (Grzegorz Milos)
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <pthread.h>
#include <inttypes.h>
#include <unistd.h>
#include <errno.h>
#include "bidir-hash.h"
#include "memshr-priv.h"
static struct blockshr_hash *blks_hash;
/* Callback in the iterator, remember this value, and leave */
int find_one(vbdblk_t k, share_tuple_t v, void *priv)
{
share_tuple_t *rv = (share_tuple_t *) priv;
*rv = v;
/* Break out of iterator loop */
return 1;
}
void* bidir_daemon(void *unused)
{
uint32_t nr_ent, max_nr_ent, tab_size, max_load, min_load;
while(1)
{
blockshr_hash_sizes( blks_hash,
&nr_ent,
&max_nr_ent,
&tab_size,
&max_load,
&min_load);
/* Remove some hints as soon as we get to 90% capacity */
if(10 * nr_ent > 9 * max_nr_ent)
{
share_tuple_t next_remove;
int to_remove;
int ret;
to_remove = 0.1 * max_nr_ent;
while(to_remove > 0)
{
/* We use the iterator to get one entry */
next_remove.handle = 0;
ret = blockshr_hash_iterator(blks_hash, find_one, &next_remove);
if ( !ret )
if ( next_remove.handle == 0 )
ret = -ESRCH;
if ( !ret )
ret = blockshr_shrhnd_remove(blks_hash, next_remove, NULL);
if(ret <= 0)
{
/* We failed to remove an entry, because of a serious hash
* table error */
DPRINTF("Could not remove handle %"PRId64", error: %d\n",
next_remove.handle, ret);
/* Force to exit the loop early */
to_remove = 0;
} else
if(ret > 0)
{
/* Managed to remove the entry. Note next_remove not
* incremented, in case there are duplicates */
to_remove--;
}
}
}
sleep(1);
}
}
void bidir_daemon_launch(void)
{
pthread_t thread;
pthread_create(&thread, NULL, bidir_daemon, NULL);
}
void bidir_daemon_initialize(struct blockshr_hash *blks)
{
blks_hash = blks;
bidir_daemon_launch();
}