Example #1
0
int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
		const struct CACHED_GENERIC *item, cache_compare compare,
		int flags)
{
	struct CACHED_GENERIC *current;
	struct CACHED_GENERIC *previous;
	struct CACHED_GENERIC *next;
	struct HASH_ENTRY *link;
	int count;
	int h;

	current = (struct CACHED_GENERIC*)NULL;
	count = 0;
	if (cache) {
		if (!(flags & CACHE_NOHASH) && cache->dohash) {
			/*
			 * When possible, use the hash table to
			 * find out whether the entry if present
			 */
			h = cache->dohash(item);
		        link = cache->first_hash[h];
			while (link) {
				if (compare(link->entry, item))
					link = link->next;
				else {
					current = link->entry;
					link = link->next;
					if (current) {
						drophashindex(cache,current,h);
						do_invalidate(cache,
							current,flags);
						count++;
					}
				}
			}
		}
		if ((flags & CACHE_NOHASH) || !cache->dohash) {
				/*
				 * Search sequentially in LRU list
				 */
			current = cache->most_recent_entry;
			previous = (struct CACHED_GENERIC*)NULL;
			while (current) {
				if (!compare(current, item)) {
					next = current->next;
					if (cache->dohash)
						drophashindex(cache,current,
						    cache->dohash(current));
					do_invalidate(cache,current,flags);
					current = next;
					count++;
				} else {
					previous = current;
					current = current->next;
				}
			}
		}
	}
	return (count);
}
Example #2
0
int ntfs_remove_cache(struct CACHE_HEADER *cache,
		struct CACHED_GENERIC *item, int flags)
{
	int count;

	count = 0;
	if (cache) {
		if (cache->dohash)
			drophashindex(cache,item,cache->dohash(item));
		do_invalidate(cache,item,flags);
		count++;
	}
	return (count);
}
Example #3
0
int main(int argc, char *argv[])
{
  SetDefaultLogging("TEST");
  SetNamePgm("test_configurable_lru");

  char buf[LENBUF];
  int ok = 1;
  int hrc = 0;
  int rc = 0;
  int expected_rc;
  char c;
  char *p;
  int key;

  LRU_status_t status = 0;
  LRU_list_t *plru;
  LRU_parameter_t param;

  param.nb_entry_prealloc = PREALLOC;
  param.entry_to_str = print_entry;
  param.clean_entry = clean_entry;
  param.name = "Test";

  BuddyInit(NULL);

  if((plru = LRU_Init(param, &status)) == NULL)
    {
      LogTest("Test ECHOUE : Mauvaise init");
      exit(1);
    }

  /*
   *
   * La syntaxe d'un test est 
   * 'i key rc' : invalide l'entree avec la clef key
   * 'n key rc' : cree une nouvelle entree avec la clef key
   * 'g key rc' : passage du garbage collector (key ne sert a rien)
   * 'p key rc' : imprime le LRU (key et rc ne servent a rien).
   * 
   * Une ligne qui debute par '#' est un commentaire
   * Une ligne qui debute par un espace ou un tab est une ligne vide [meme si il y a des trucs derriere.. :-( ]
   * Une ligne vide (juste un CR) est une ligne vide (cette citation a recu le Premier Prix lors du Festival International 
   * de la Tautologie de Langue Francaise (FITLF), a Poully le Marais, en Aout 2004)
   *
   */

  LogTest("============ Debut de l'interactif =================");

  while(ok)
    {
      /* Code interactif, pompe sur le test rbt de Jacques */
      fputs("> ", stdout);
      if((p = fgets(buf, LENBUF, stdin)) == NULL)
        {
          LogTest("fin des commandes");
          ok = 0;
          continue;
        }
      if((p = strchr(buf, '\n')) != NULL)
        *p = '\0';

      rc = sscanf(buf, "%c %d %d", &c, &key, &expected_rc);
      if(c == '#')
        {
          /* # indique un commentaire */
          continue;
        }
      else if(c == ' ' || c == '\t' || rc == -1)
        {
          /* Cas d'une ligne vide */
          if(rc > 1)
            LogTest("Erreur de syntaxe : mettre un diese au debut d'un commentaire");

          continue;
        }
      else
        {
          if(rc != 3)
            {
              LogTest("Erreur de syntaxe : sscanf retourne %d au lieu de 3", rc);
              continue;
            }
          LogTest("---> %c %d %d", c, key, expected_rc);
        }

      switch (c)
        {
        case 'i':
          /* set overwrite */
          LogTest("invalidate  %d  --> %d ?", key, expected_rc);

          hrc = do_invalidate(plru, key);

          if(hrc != expected_rc)
            LogTest(">>>> ERREUR: invalidate  %d : %d != %d (expected)",
                    key, hrc, expected_rc);
          else
            LogTest(">>>> OK invalidate %d", key);
          break;

        case 'n':
          /* test */
          LogTest("new %d --> %d ?", key, expected_rc);

          hrc = do_new(plru, key);

          if(hrc != expected_rc)
            LogTest(">>>> ERREUR: new %d : %d != %d (expected)", key, hrc, expected_rc);
          else
            LogTest(">>>> OK new %d", key);
          break;

        case 'g':
          /* set no overwrite */
          LogTest("gc  %d --> %d ?", key, expected_rc);

          hrc = do_gc(plru);

          if(hrc != expected_rc)
            LogTest(">>>> ERREUR: gc %d: %d != %d (expected)", key, hrc, expected_rc);
          else
            LogTest(">>>> OK new  %d", key);
          break;

        case 'p':
          /* Print */
          LRU_Print(plru);
          break;

        default:
          /* syntaxe error */
          LogTest("ordre '%c' non-reconnu", c);
          break;
        }
    }

  LogTest("====================================================");
  LogTest("Test reussi : tous les tests sont passes avec succes");
  exit(0);
  return;
}                               /* main */