diff options
author | Max Kellermann <max@duempel.org> | 2014-10-05 07:41:50 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-10-05 07:41:50 +0200 |
commit | b1a252a64d39d17618d2d00ac341684b6f290ef6 (patch) | |
tree | 10eff9b871e5bf9a6a7b8934ada5cf8a23920218 /src/lib/nfs/Base.cxx | |
parent | fb90b64bac49d6efadc2db021cf0fbf65c9d66a6 (diff) | |
download | mpd-b1a252a64d39d17618d2d00ac341684b6f290ef6.tar.gz mpd-b1a252a64d39d17618d2d00ac341684b6f290ef6.tar.xz mpd-b1a252a64d39d17618d2d00ac341684b6f290ef6.zip |
lib/nfs/Base: kludge to reduce number of NFS mounts
Creating a NfsStorage sets its own export_name as the "base". Now
NfsFileReader can use this information to derive the export_name to be
mounted, instead of guessing. This solves the "too many connection"
problem on the NFS server while updating the database.
Diffstat (limited to 'src/lib/nfs/Base.cxx')
-rw-r--r-- | src/lib/nfs/Base.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lib/nfs/Base.cxx b/src/lib/nfs/Base.cxx new file mode 100644 index 000000000..3004cd11b --- /dev/null +++ b/src/lib/nfs/Base.cxx @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "Base.hxx" + +#include <assert.h> +#include <string.h> + +static char nfs_base_server[64]; +static char nfs_base_export_name[256]; +static size_t nfs_base_export_name_length; + +void +nfs_set_base(const char *server, const char *export_name) +{ + assert(server != nullptr); + assert(export_name != nullptr); + + const size_t server_length = strlen(server); + const size_t export_name_length = strlen(export_name); + + if (server_length >= sizeof(nfs_base_server) || + export_name_length > sizeof(nfs_base_export_name)) + return; + + memcpy(nfs_base_server, server, server_length + 1); + memcpy(nfs_base_export_name, export_name, export_name_length); + nfs_base_export_name_length = export_name_length; +} + +const char * +nfs_check_base(const char *server, const char *path) +{ + assert(server != nullptr); + assert(path != nullptr); + + return strcmp(nfs_base_server, server) == 0 && + memcmp(nfs_base_export_name, path, + nfs_base_export_name_length) == 0 && + (path[nfs_base_export_name_length] == 0 || + path[nfs_base_export_name_length] == '/') + ? path + nfs_base_export_name_length + : nullptr; +} |