1*9ab15106SMatthew Dillon /*
2*9ab15106SMatthew Dillon * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
3*9ab15106SMatthew Dillon *
4*9ab15106SMatthew Dillon * This code is derived from software contributed to The DragonFly Project
5*9ab15106SMatthew Dillon * by Matthew Dillon <dillon@dragonflybsd.org>
6*9ab15106SMatthew Dillon * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
7*9ab15106SMatthew Dillon *
8*9ab15106SMatthew Dillon * Redistribution and use in source and binary forms, with or without
9*9ab15106SMatthew Dillon * modification, are permitted provided that the following conditions
10*9ab15106SMatthew Dillon * are met:
11*9ab15106SMatthew Dillon *
12*9ab15106SMatthew Dillon * 1. Redistributions of source code must retain the above copyright
13*9ab15106SMatthew Dillon * notice, this list of conditions and the following disclaimer.
14*9ab15106SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
15*9ab15106SMatthew Dillon * notice, this list of conditions and the following disclaimer in
16*9ab15106SMatthew Dillon * the documentation and/or other materials provided with the
17*9ab15106SMatthew Dillon * distribution.
18*9ab15106SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
19*9ab15106SMatthew Dillon * contributors may be used to endorse or promote products derived
20*9ab15106SMatthew Dillon * from this software without specific, prior written permission.
21*9ab15106SMatthew Dillon *
22*9ab15106SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23*9ab15106SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24*9ab15106SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25*9ab15106SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26*9ab15106SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27*9ab15106SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28*9ab15106SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29*9ab15106SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30*9ab15106SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31*9ab15106SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32*9ab15106SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*9ab15106SMatthew Dillon * SUCH DAMAGE.
34*9ab15106SMatthew Dillon */
35*9ab15106SMatthew Dillon
36*9ab15106SMatthew Dillon #include "hammer2.h"
37*9ab15106SMatthew Dillon
38*9ab15106SMatthew Dillon /*
39*9ab15106SMatthew Dillon * Start-up the leaf daemon for a PFS on this machine.
40*9ab15106SMatthew Dillon *
41*9ab15106SMatthew Dillon * One leaf daemon is run for each mounted PFS. The daemon may multi-thread
42*9ab15106SMatthew Dillon * to improve performance if desired. The daemon performs the following
43*9ab15106SMatthew Dillon * functions:
44*9ab15106SMatthew Dillon *
45*9ab15106SMatthew Dillon * (1) Makes and maintains connections to all cluster nodes found for
46*9ab15106SMatthew Dillon * the PFS, retrieved from the REMOTE configuration stored in
47*9ab15106SMatthew Dillon * the HAMMER2 mount. A localhost connection is always implied
48*9ab15106SMatthew Dillon * (using the backbone), but also having more direct connections
49*9ab15106SMatthew Dillon * can result in higher performance.
50*9ab15106SMatthew Dillon *
51*9ab15106SMatthew Dillon * This also includes any required encryption or authentication.
52*9ab15106SMatthew Dillon *
53*9ab15106SMatthew Dillon * (2) Runs the spanning tree protocol as a leaf, meaning that
54*9ab15106SMatthew Dillon * the leaf daemon does not serve as a relay and the individual
55*9ab15106SMatthew Dillon * connections made in (1) do not cross-connect.
56*9ab15106SMatthew Dillon *
57*9ab15106SMatthew Dillon * (3) Obtains the PFS's registration and makes it available to the
58*9ab15106SMatthew Dillon * cluster via the spanning tree protocol.
59*9ab15106SMatthew Dillon *
60*9ab15106SMatthew Dillon * (4) Creates a communications pipe to the HAMMER2 VFS in the kernel
61*9ab15106SMatthew Dillon * (installed via ioctl()) which the HAMMER2 VFS uses to accept and
62*9ab15106SMatthew Dillon * communicate high-level requests.
63*9ab15106SMatthew Dillon *
64*9ab15106SMatthew Dillon * (5) Performs all complex high-level messaging protocol operations,
65*9ab15106SMatthew Dillon * such as quorum operations, maintains persistent cache state,
66*9ab15106SMatthew Dillon * and so on and so forth.
67*9ab15106SMatthew Dillon *
68*9ab15106SMatthew Dillon * As you may have noted, the leaf daemon serves as an intermediary between
69*9ab15106SMatthew Dillon * the kernel and the rest of the cluster. The kernel will issue high level
70*9ab15106SMatthew Dillon * protocol commands to the leaf which performs the protocol and sends a
71*9ab15106SMatthew Dillon * response. The kernel does NOT have to deal with the quorum or other
72*9ab15106SMatthew Dillon * complex maintainance.
73*9ab15106SMatthew Dillon *
74*9ab15106SMatthew Dillon * Basically the kernel is simply another client from the point of view
75*9ab15106SMatthew Dillon * of the high-level protocols, requesting cache state locks and such from
76*9ab15106SMatthew Dillon * the leaf (in a degenerate situation one master lock is all that is needed).
77*9ab15106SMatthew Dillon * If the kernel PFS has local media storage that storage can be used for
78*9ab15106SMatthew Dillon * numerous purposes, such as caching, and in the degenerate non-clustered
79*9ab15106SMatthew Dillon * case simply represents the one-and-only master copy of the filesystem.
80*9ab15106SMatthew Dillon */
81*9ab15106SMatthew Dillon int
cmd_leaf(const char * sel_info)82*9ab15106SMatthew Dillon cmd_leaf(const char *sel_info)
83*9ab15106SMatthew Dillon {
84*9ab15106SMatthew Dillon int ecode = 0;
85*9ab15106SMatthew Dillon int fd;
86*9ab15106SMatthew Dillon
87*9ab15106SMatthew Dillon /*
88*9ab15106SMatthew Dillon * Obtain an ioctl descriptor and retrieve the registration info
89*9ab15106SMatthew Dillon * for the PFS.
90*9ab15106SMatthew Dillon */
91*9ab15106SMatthew Dillon if ((fd = hammer2_ioctl_handle(sel_info)) < 0)
92*9ab15106SMatthew Dillon return(1);
93*9ab15106SMatthew Dillon
94*9ab15106SMatthew Dillon /*
95*9ab15106SMatthew Dillon * Start a daemon to interconnect the HAMMER2 PFS in-kernel to the
96*9ab15106SMatthew Dillon * master-node daemon. This daemon's thread will spend most of its
97*9ab15106SMatthew Dillon * time in the kernel.
98*9ab15106SMatthew Dillon */
99*9ab15106SMatthew Dillon /* hammer2_demon(helper_pfs_interlink, (void *)(intptr_t)fd);*/
100*9ab15106SMatthew Dillon if (NormalExit)
101*9ab15106SMatthew Dillon close(fd);
102*9ab15106SMatthew Dillon
103*9ab15106SMatthew Dillon return ecode;
104*9ab15106SMatthew Dillon }
105*9ab15106SMatthew Dillon
106*9ab15106SMatthew Dillon #if 0
107*9ab15106SMatthew Dillon /*
108*9ab15106SMatthew Dillon * LEAF interconnect between PFS and the messaging core. We create a
109*9ab15106SMatthew Dillon * socket connection to the messaging core, register the PFS with the
110*9ab15106SMatthew Dillon * core, and then pass the messaging descriptor to the kernel.
111*9ab15106SMatthew Dillon *
112*9ab15106SMatthew Dillon * The kernel takes over operation of the interconnect until the filesystem
113*9ab15106SMatthew Dillon * is unmounted or the descriptor is lost or explicitly terminated via
114*9ab15106SMatthew Dillon * a hammer2 command.
115*9ab15106SMatthew Dillon *
116*9ab15106SMatthew Dillon * This is essentially a localhost connection, so we don't have to worry
117*9ab15106SMatthew Dillon * about encryption. Any encryption will be handled by the messaging
118*9ab15106SMatthew Dillon * core.
119*9ab15106SMatthew Dillon */
120*9ab15106SMatthew Dillon static
121*9ab15106SMatthew Dillon void *
122*9ab15106SMatthew Dillon leaf_connect(void *data)
123*9ab15106SMatthew Dillon {
124*9ab15106SMatthew Dillon int fd;
125*9ab15106SMatthew Dillon
126*9ab15106SMatthew Dillon fd = (int)(intptr_t)data;
127*9ab15106SMatthew Dillon
128*9ab15106SMatthew Dillon return (NULL);
129*9ab15106SMatthew Dillon }
130*9ab15106SMatthew Dillon #endif
131