Home | History | Annotate | Download | only in mount
      1 //
      2 // CDDL HEADER START
      3 //
      4 // The contents of this file are subject to the terms of the
      5 // Common Development and Distribution License (the License).
      6 // You may not use this file except in compliance with the License.
      7 //
      8 // You can obtain a copy of the license at usr/src/CDDL.txt
      9 // or http://www.opensolaris.org/os/licensing.
     10 // See the License for the specific language governing permissions
     11 // and limitations under the License.
     12 //
     13 // When distributing Covered Code, include this CDDL HEADER in each
     14 // file and include the License file at usr/src/CDDL.txt.
     15 // If applicable, add the following below this CDDL HEADER, with the
     16 // fields enclosed by brackets [] replaced with your own identifying
     17 // information: Portions Copyright [yyyy] [name of copyright owner]
     18 //
     19 // CDDL HEADER END
     20 //
     21 
     22 //
     23 // Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     24 // Use is subject to license terms.
     25 //
     26 
     27 #ifndef _MOUNT_REPLICA_IMPL_H
     28 #define	_MOUNT_REPLICA_IMPL_H
     29 
     30 #pragma ident	"@(#)mount_replica_impl.h	1.25	08/05/20 SMI"
     31 
     32 #include <repl/service/replica_tmpl.h>
     33 #include <h/pxfs.h>
     34 #include <h/repl_pxfs.h>
     35 #include <sys/os.h>
     36 #include <pxfs/common/pxfslib.h>
     37 
     38 // Forward declarations.
     39 class mount_server_impl;
     40 
     41 //
     42 // This struct is used for building a table for supporting the mapping
     43 // from version protocol spec file version number to the various IDL
     44 // interface versions it represents.  The table will be a two dimensional
     45 // array indexed by major/minor vp version.
     46 //
     47 typedef struct {		// idl interfaces
     48 	int	ms;		// fs::mount_server
     49 	int	ms_ckpt;	// repl_pxfs::mount_replica
     50 } mount_ver_map_t;
     51 
     52 //
     53 // These are the current maximum indexes used for accessing the vp to idl
     54 // version table.
     55 //
     56 const int	MOUNT_VP_MAX_MAJOR = 2;
     57 const int	MOUNT_VP_MAX_MINOR = 2;
     58 
     59 //
     60 // HA service for recording mount commands.
     61 // There is one service for the whole cluster and is never shutdown.
     62 //
     63 class mount_replica_impl : public repl_server<repl_pxfs::mount_replica> {
     64 public:
     65 	mount_replica_impl(const char *id);
     66 	~mount_replica_impl();
     67 
     68 	// Required functions for replica framework.
     69 	// replica::repl_prov::=
     70 	void become_secondary(Environment &_environment);
     71 
     72 	void add_secondary(replica::checkpoint_ptr sec_chkpt,
     73 	    const char *secondary_name, Environment &_environment);
     74 
     75 	void remove_secondary(const char *secondary_name,
     76 	    Environment &_environment);
     77 
     78 	void freeze_primary_prepare(Environment &_environment);
     79 
     80 	void freeze_primary(Environment &_environment);
     81 
     82 	void unfreeze_primary(Environment &_environment);
     83 
     84 	void become_primary(const replica::repl_name_seq &secondary_names,
     85 	    Environment &_environment);
     86 
     87 	void become_spare(Environment &_environment);
     88 
     89 	void shutdown(Environment &_environment);
     90 
     91 	CORBA::Object_ptr get_root_obj(Environment &_environment);
     92 	//
     93 
     94 	// repl_pxfs::mount_replica::=
     95 	void ckpt_new_server(fs::mount_server_ptr server,
     96 	    Environment &_environment);
     97 
     98 	void ckpt_add_client(fs::mount_client_died_ptr clobj,
     99 	    fs::mount_client_ptr client, sol::nodeid_t nodeid,
    100 	    bool shutdown, Environment &_environment);
    101 
    102 	void ckpt_remove_client(fs::mount_client_ptr client,
    103 	    Environment &_environment);
    104 
    105 	void ckpt_mount_start(const sol::mounta &ma,
    106 	    fs::mount_client_ptr client, Environment &_environment);
    107 
    108 	void ckpt_mount_start_v1(const sol::mounta &ma,
    109 	    fs::mount_client_ptr client, Environment &_environment);
    110 
    111 	void ckpt_mount_err(sol::error_t error, Environment &_environment);
    112 
    113 	void	ckpt_mount(
    114 	    fs::filesystem_ptr		fs,
    115 	    const fs::fs_info		&fsinfo,
    116 	    const sol::mounta		&ma,
    117 	    const char			*mntoptions,
    118 	    bool			dev_is_ha,
    119 	    const char			*dev_name,
    120 	    const sol::nodeid_seq_t	&dev_nids,
    121 	    Environment			&_environment);
    122 
    123 	void	ckpt_mount_v1(
    124 	    pxfs_v1::filesystem_ptr	fs,
    125 	    const pxfs_v1::fs_info	&fsinfo,
    126 	    const sol::mounta		&ma,
    127 	    const char			*mntoptions,
    128 	    bool			dev_is_ha,
    129 	    const char			*dev_name,
    130 	    const sol::nodeid_seq_t	&dev_nids,
    131 	    Environment			&_environment);
    132 
    133 	void	ckpt_mount_middle(
    134 	    fs::filesystem_ptr		fs,
    135 	    const fs::fs_info		&fsinfo,
    136 	    const char			*mntoptions,
    137 	    bool			dev_is_ha,
    138 	    const char			*dev_name,
    139 	    const sol::nodeid_seq_t	&dev_nids,
    140 	    Environment			&_environment);
    141 
    142 	void	ckpt_mount_middle_v1(
    143 	    pxfs_v1::filesystem_ptr	fs,
    144 	    const pxfs_v1::fs_info	&fsinfo,
    145 	    const char			*mntoptions,
    146 	    bool			dev_is_ha,
    147 	    const char			*dev_name,
    148 	    const sol::nodeid_seq_t	&dev_nids,
    149 	    Environment			&_environment);
    150 
    151 	void	ckpt_remount_middle(
    152 	    fs::filesystem_ptr	fs,
    153 	    uint32_t		vfsflags,
    154 	    const char		*mntoptions,
    155 	    Environment		&_environment);
    156 
    157 	void	ckpt_remount_middle_v1(
    158 	    pxfs_v1::filesystem_ptr	fs,
    159 	    uint32_t			vfsflags,
    160 	    const char			*mntoptions,
    161 	    Environment			&_environment);
    162 
    163 	void	ckpt_unmount_start(
    164 	    fs::filesystem_ptr		fs,
    165 	    solobj::cred_ptr		credobj,
    166 	    fs::mount_client_ptr	client,
    167 	    bool			is_shutdown,
    168 	    Environment			&_environment);
    169 
    170 	void ckpt_unmount_start_1(
    171 	    fs::filesystem_ptr		fs,
    172 	    int32_t			flags,
    173 	    solobj::cred_ptr		credobj,
    174 	    fs::mount_client_ptr	client,
    175 	    bool			is_shutdown,
    176 	    Environment			&_environment);
    177 
    178 	void	ckpt_unmount_start_v1(
    179 	    pxfs_v1::filesystem_ptr	fs,
    180 	    int32_t			flags,
    181 	    solobj::cred_ptr		credobj,
    182 	    fs::mount_client_ptr	client,
    183 	    bool			is_shutdown,
    184 	    Environment			&_environment);
    185 
    186 	void ckpt_unmount_middle(sol::error_t error,
    187 	    Environment &_environment);
    188 
    189 	void ckpt_unmount_notified(Environment &_environment);
    190 
    191 	void ckpt_unmount_end(Environment &_environment);
    192 
    193 	void ckpt_unmount_shutdown(fs::mount_client_ptr client,
    194 	    Environment &_environment);
    195 
    196 	void ckpt_devlock(fs::mount_client_ptr client, sol::nodeid_t nodeid,
    197 	    const char *dev_name, Environment &_environment);
    198 
    199 	void ckpt_devunlock(const char *dev_name, Environment &_environment);
    200 
    201 	void ckpt_get_dc_callback(fs::dc_callback_ptr cb,
    202 	    Environment &_environment);
    203 
    204 	void ckpt_notify_change(sol::dev_t gdev,
    205 	    const sol::nodeid_seq_t &dev_nids, Environment &_environment);
    206 
    207 	void ckpt_service_version(unsigned short new_major,
    208 	    unsigned short new_minor, Environment &);
    209 
    210 	void ckpt_upgrade_client_list(fs::mount_client_ptr client,
    211 	    sol::nodeid_t nodeid, Environment &_environment);
    212 
    213 	void ckpt_upgrade_devlock_list(const char *dev_name,
    214 	    fs::mount_client_ptr client, Environment &_environment);
    215 	//
    216 
    217 	// These are called when the pxfs server module is loaded or unloaded.
    218 	static int startup();
    219 	static int shutdown();
    220 
    221 	// Checkpoint accessor function
    222 	repl_pxfs::mount_replica_ptr	get_checkpoint_mount_replica();
    223 
    224 	//
    225 	// mount_version_callback_impl::do_callback is called by the
    226 	// version manager.  That method calls here to pass on the version
    227 	// update.
    228 	//
    229 	void upgrade_callback(const version_manager::vp_version_t &,
    230 	    Environment &);
    231 
    232 	// Set the initial version number.
    233 	void set_version(const version_manager::vp_version_t &);
    234 
    235 	//
    236 	// These are both protected by version_lock.
    237 	// current_version is the versioned protocol number the version
    238 	// manager has told us we should be running as.
    239 	// pending_version is set when a secondary gets a callback before
    240 	// the primary sends a checkpoint so a failover during upgrade
    241 	// commit is processed correctly.
    242 	//
    243 	version_manager::vp_version_t current_version;
    244 	version_manager::vp_version_t pending_version;
    245 
    246 	//
    247 	// This lock protects 'current_version', _ckpt_proxy and
    248 	// provides locking between upgrade callbacks and become_primary().
    249 	// It needs to be a rwlock since we make checkpoint calls while
    250 	// holding the lock.
    251 	//
    252 	os::rwlock_t version_lock;
    253 
    254 private:
    255 	// Pointer to the root HA object for this service.
    256 	mount_server_impl		*mount_serverp;
    257 
    258 	//
    259 	// XXX CORBA reference to root HA object to prevent _unrefernced()
    260 	// from being called until get_root_obj() is called.
    261 	//
    262 	fs::mount_server_var		mount_server_v;
    263 
    264 	// Checkpoint proxy
    265 	repl_pxfs::mount_replica_ptr	_ckpt_proxy;
    266 };
    267 
    268 class mount_version_callback_impl :
    269     public McServerof<version_manager::upgrade_callback> {
    270 public:
    271 	mount_version_callback_impl(mount_replica_impl &p);
    272 	~mount_version_callback_impl();
    273 
    274 	void _unreferenced(unref_t);
    275 
    276 	// IDL methods.
    277 	void do_callback(const char *ucc_name,
    278 	    const version_manager::vp_version_t &new_version,
    279 	    Environment &_environment);
    280 
    281 private:
    282 	mount_replica_impl &prov;
    283 };
    284 
    285 #endif	// _MOUNT_REPLICA_IMPL_H
    286