Whamcloud - gitweb
LU-15496 tests: fix sanity/398c to use proper OSC name
[fs/lustre-release.git] / lustre / obdclass / upcall_cache.c
index 05be32d..f71901b 100644 (file)
@@ -151,6 +151,47 @@ static int check_unlink_entry(struct upcall_cache *cache,
        return 1;
 }
 
+int upcall_cache_set_upcall(struct upcall_cache *cache, const char *buffer,
+                           size_t count, bool path_only)
+{
+       char *upcall;
+
+       if (count >= UC_CACHE_UPCALL_MAXPATH)
+               return -E2BIG;
+
+       OBD_ALLOC(upcall, count + 1);
+       if (upcall == NULL)
+               return -ENOMEM;
+
+       /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
+       if (sscanf(buffer, "%s", upcall) != 1)
+               goto invalid;
+
+       if (upcall[0] == '/')
+               goto valid;
+
+       if (path_only)
+               goto invalid;
+
+       if (strcasecmp(upcall, "NONE") == 0) {
+               snprintf(upcall, count + 1, "NONE");
+               goto valid;
+       }
+
+invalid:
+       OBD_FREE(upcall, count + 1);
+       return -EINVAL;
+
+valid:
+       down_write(&cache->uc_upcall_rwsem);
+       strcpy(cache->uc_upcall, upcall);
+       up_write(&cache->uc_upcall_rwsem);
+
+       OBD_FREE(upcall, count + 1);
+       return 0;
+}
+EXPORT_SYMBOL(upcall_cache_set_upcall);
+
 static inline int refresh_entry(struct upcall_cache *cache,
                         struct upcall_cache_entry *entry)
 {
@@ -521,9 +562,9 @@ struct upcall_cache *upcall_cache_init(const char *name, const char *upcall,
                RETURN(ERR_PTR(-ENOMEM));
        for (i = 0; i < cache->uc_hashsize; i++)
                INIT_LIST_HEAD(&cache->uc_hashtable[i]);
-       strlcpy(cache->uc_name, name, sizeof(cache->uc_name));
+       strscpy(cache->uc_name, name, sizeof(cache->uc_name));
        /* upcall pathname proc tunable */
-       strlcpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall));
+       strscpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall));
        cache->uc_entry_expire = entry_expire;
        cache->uc_acquire_expire = acquire_expire;
        cache->uc_acquire_replay = replayable;