aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/rpc_pipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sunrpc/rpc_pipe.c')
-rw-r--r--net/sunrpc/rpc_pipe.c134
1 files changed, 132 insertions, 2 deletions
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index b36bfb93924c..cfeba77de567 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -884,6 +884,124 @@ rpc_unlink(struct dentry *dentry)
884} 884}
885EXPORT_SYMBOL_GPL(rpc_unlink); 885EXPORT_SYMBOL_GPL(rpc_unlink);
886 886
887/**
888 * rpc_init_pipe_dir_head - initialise a struct rpc_pipe_dir_head
889 * @pdh: pointer to struct rpc_pipe_dir_head
890 */
891void rpc_init_pipe_dir_head(struct rpc_pipe_dir_head *pdh)
892{
893 INIT_LIST_HEAD(&pdh->pdh_entries);
894 pdh->pdh_dentry = NULL;
895}
896EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_head);
897
898/**
899 * rpc_init_pipe_dir_object - initialise a struct rpc_pipe_dir_object
900 * @pdo: pointer to struct rpc_pipe_dir_object
901 * @pdo_ops: pointer to const struct rpc_pipe_dir_object_ops
902 * @pdo_data: pointer to caller-defined data
903 */
904void rpc_init_pipe_dir_object(struct rpc_pipe_dir_object *pdo,
905 const struct rpc_pipe_dir_object_ops *pdo_ops,
906 void *pdo_data)
907{
908 INIT_LIST_HEAD(&pdo->pdo_head);
909 pdo->pdo_ops = pdo_ops;
910 pdo->pdo_data = pdo_data;
911}
912EXPORT_SYMBOL_GPL(rpc_init_pipe_dir_object);
913
914static int
915rpc_add_pipe_dir_object_locked(struct net *net,
916 struct rpc_pipe_dir_head *pdh,
917 struct rpc_pipe_dir_object *pdo)
918{
919 int ret = 0;
920
921 if (pdh->pdh_dentry)
922 ret = pdo->pdo_ops->create(pdh->pdh_dentry, pdo);
923 if (ret == 0)
924 list_add_tail(&pdo->pdo_head, &pdh->pdh_entries);
925 return ret;
926}
927
928static void
929rpc_remove_pipe_dir_object_locked(struct net *net,
930 struct rpc_pipe_dir_head *pdh,
931 struct rpc_pipe_dir_object *pdo)
932{
933 if (pdh->pdh_dentry)
934 pdo->pdo_ops->destroy(pdh->pdh_dentry, pdo);
935 list_del_init(&pdo->pdo_head);
936}
937
938/**
939 * rpc_add_pipe_dir_object - associate a rpc_pipe_dir_object to a directory
940 * @net: pointer to struct net
941 * @pdh: pointer to struct rpc_pipe_dir_head
942 * @pdo: pointer to struct rpc_pipe_dir_object
943 *
944 */
945int
946rpc_add_pipe_dir_object(struct net *net,
947 struct rpc_pipe_dir_head *pdh,
948 struct rpc_pipe_dir_object *pdo)
949{
950 int ret = 0;
951
952 if (list_empty(&pdo->pdo_head)) {
953 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
954
955 mutex_lock(&sn->pipefs_sb_lock);
956 ret = rpc_add_pipe_dir_object_locked(net, pdh, pdo);
957 mutex_unlock(&sn->pipefs_sb_lock);
958 }
959 return ret;
960}
961EXPORT_SYMBOL_GPL(rpc_add_pipe_dir_object);
962
963/**
964 * rpc_remove_pipe_dir_object - remove a rpc_pipe_dir_object from a directory
965 * @net: pointer to struct net
966 * @pdh: pointer to struct rpc_pipe_dir_head
967 * @pdo: pointer to struct rpc_pipe_dir_object
968 *
969 */
970void
971rpc_remove_pipe_dir_object(struct net *net,
972 struct rpc_pipe_dir_head *pdh,
973 struct rpc_pipe_dir_object *pdo)
974{
975 if (!list_empty(&pdo->pdo_head)) {
976 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
977
978 mutex_lock(&sn->pipefs_sb_lock);
979 rpc_remove_pipe_dir_object_locked(net, pdh, pdo);
980 mutex_unlock(&sn->pipefs_sb_lock);
981 }
982}
983EXPORT_SYMBOL_GPL(rpc_remove_pipe_dir_object);
984
985static void
986rpc_create_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
987{
988 struct rpc_pipe_dir_object *pdo;
989 struct dentry *dir = pdh->pdh_dentry;
990
991 list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
992 pdo->pdo_ops->create(dir, pdo);
993}
994
995static void
996rpc_destroy_pipe_dir_objects(struct rpc_pipe_dir_head *pdh)
997{
998 struct rpc_pipe_dir_object *pdo;
999 struct dentry *dir = pdh->pdh_dentry;
1000
1001 list_for_each_entry(pdo, &pdh->pdh_entries, pdo_head)
1002 pdo->pdo_ops->destroy(dir, pdo);
1003}
1004
887enum { 1005enum {
888 RPCAUTH_info, 1006 RPCAUTH_info,
889 RPCAUTH_EOF 1007 RPCAUTH_EOF
@@ -924,16 +1042,28 @@ struct dentry *rpc_create_client_dir(struct dentry *dentry,
924 const char *name, 1042 const char *name,
925 struct rpc_clnt *rpc_client) 1043 struct rpc_clnt *rpc_client)
926{ 1044{
927 return rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL, 1045 struct dentry *ret;
1046
1047 ret = rpc_mkdir_populate(dentry, name, S_IRUGO | S_IXUGO, NULL,
928 rpc_clntdir_populate, rpc_client); 1048 rpc_clntdir_populate, rpc_client);
1049 if (!IS_ERR(ret)) {
1050 rpc_client->cl_pipedir_objects.pdh_dentry = ret;
1051 rpc_create_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
1052 }
1053 return ret;
929} 1054}
930 1055
931/** 1056/**
932 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir() 1057 * rpc_remove_client_dir - Remove a directory created with rpc_create_client_dir()
933 * @dentry: dentry for the pipe 1058 * @dentry: dentry for the pipe
1059 * @rpc_client: rpc_client for the pipe
934 */ 1060 */
935int rpc_remove_client_dir(struct dentry *dentry) 1061int rpc_remove_client_dir(struct dentry *dentry, struct rpc_clnt *rpc_client)
936{ 1062{
1063 if (rpc_client->cl_pipedir_objects.pdh_dentry) {
1064 rpc_destroy_pipe_dir_objects(&rpc_client->cl_pipedir_objects);
1065 rpc_client->cl_pipedir_objects.pdh_dentry = NULL;
1066 }
937 return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate); 1067 return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate);
938} 1068}
939 1069