├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── admin ├── Ganesha │ ├── __init__.py │ ├── config_editor.py │ ├── ganesha_mgr_utils.py │ ├── ganesha_stats.py │ └── glib_dbus_stats.py ├── bcache.py ├── bcache_manage.py ├── buddha │ ├── __init__.py │ ├── color_output.py │ ├── fileutil.py │ ├── lichbd.py │ ├── lsb.py │ ├── smart.py │ ├── snapshot.py │ └── utils.py ├── check_domain.py ├── cleancore.sh ├── cleanlog.sh ├── cluster.py ├── cluster_conf.py ├── color_output.py ├── config.py ├── create_access_relation.py ├── ctdb_config_update.py ├── daemon.py ├── data_transfer.py ├── disk.py ├── disk_light.py ├── disk_manage.py ├── drbd.py ├── etcd_manage.py ├── fence_test.py ├── ftp.py ├── getconf.py ├── hp_raid.py ├── instence.py ├── kerb.py ├── license.py ├── lvm.py ├── manage_config.py ├── mdsize.py ├── mdsize_redis.py ├── mega_raid.py ├── meta_update_from_apple_to_2017Q3.py ├── minio.py ├── mon.py ├── mon_data.py ├── node.py ├── nsswitch-conf-update.py ├── nsswitch-conf-update_ldap.py ├── password-auth-ac-config-update.py ├── raid.py ├── redisd.py ├── samba.py ├── samba_config_update.py ├── sdfs.py ├── set-nodes-info.py ├── test_uss_rm.py ├── test_uss_touch.py ├── testfile.py ├── uss_samba_init_centos_6 ├── uss_samba_init_centos_7 ├── uss_samba_init_ubuntu ├── uss_ucarp_init_centos_6 ├── uss_ucarp_init_centos_7 ├── uss_ucarp_init_ubuntu ├── uss_vip_init_centos_6 ├── uss_vip_init_centos_7 ├── uss_vip_init_ubuntu ├── ussd_init_centos_6 ├── ussd_init_centos_7 ├── ussd_init_ubuntu ├── utils.py ├── vip.py ├── vipconf.py └── worm.py ├── cds ├── cds_rpc.c ├── cds_rpc.h ├── diskio.c ├── diskio.h ├── replica.c └── replica.h ├── doc ├── load balance.docx └── vip.docx ├── etc ├── Makefile ├── clean_cluster.sh ├── cluster.conf ├── config.json ├── exports.conf ├── ftp.conf ├── install.sh ├── named.conf ├── redis.conf.tpl ├── redis.conf.tpl.bak ├── sdfs.conf ├── uss.conf.example ├── uss.conf.tpl └── yfs-shell.conf ├── include ├── Makefile.am ├── cmakeconfig.h.ini ├── configure.h ├── get_version.cmake ├── mem_hugepage.h ├── redis.h ├── sdfs_api_old.h ├── sdfs_buffer.h ├── sdfs_conf.h ├── sdfs_ec.h ├── sdfs_id.h ├── sdfs_lib.h ├── sdfs_list.h ├── sdfs_quota.h ├── sdfs_share.h └── sdfs_worm.h ├── itest ├── include │ ├── ycommands.h │ └── yutils.h ├── yfs │ ├── CMakeLists.txt │ └── yshell.cc └── ylib │ ├── CMakeLists.txt │ ├── aio_sync_test.c │ ├── bigfile_4g+.c │ ├── functest.c │ ├── functest.h │ ├── iotest.c │ ├── iotest.h │ ├── itest_bitmap.cc │ ├── itest_ylib.cc │ ├── md5.c │ ├── md5.h │ ├── test_bitmap.c │ ├── test_ec.c │ ├── test_fuse.c │ ├── test_seek.c │ ├── test_skiplist.c │ └── ynfs_iotest.c ├── license ├── include │ ├── aes.h │ └── license_helper.h └── src │ ├── aes.c │ └── license_helper.c ├── mds ├── .gitignore ├── Makefile.am ├── configure.in ├── docs │ ├── arch.txt │ ├── mds_ha_arch.fig │ └── pool.txt ├── include │ ├── Makefile.am │ └── yfsmds_conf.h ├── mds │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── disk.c │ ├── diskpool.c │ ├── diskpool.h │ ├── main.c │ ├── mds.c │ ├── mds.h │ ├── mds_license.c │ ├── mds_main.c │ ├── mds_main.h │ ├── nodepool.c │ ├── nodepool.h │ ├── nodepool_hdd.c │ └── nodepool_ssd.c └── todo ├── metadata ├── chunk_redis.c ├── dir.h ├── dir_redis.c ├── inode_redis.c ├── kv_redis.c ├── md.c ├── md.h ├── md_attr.c ├── md_attr.h ├── md_chunk.c ├── md_db.h ├── md_dir.c ├── md_file.c ├── md_group.c ├── md_lib.h ├── md_node.c ├── md_quota.c ├── md_root.c ├── md_root.h ├── md_share.c ├── md_user.c ├── md_vol.c ├── quota.h ├── redis.c ├── redis_co.c ├── redis_co.h ├── redis_conn.c ├── redis_conn.h ├── redis_pipeline.c ├── redis_pipeline.h └── redis_vol.c ├── mond ├── mond_kv.c ├── mond_kv.h ├── mond_rpc.c └── mond_rpc.h ├── nfs ├── CMakeLists.txt ├── Makefile.am ├── attr.c ├── attr.h ├── error.c ├── error.h ├── hostcache.c ├── hostcache.h ├── main.c ├── mountlist.c ├── nfs3.c ├── nfs3.h ├── nfs_args.h ├── nfs_conf.h ├── nfs_events.c ├── nfs_events.h ├── nfs_mount.c ├── nfs_remove.c ├── nlm4.c ├── nlm_async.c ├── nlm_async.h ├── nlm_events.c ├── nlm_events.h ├── nlm_job_context.h ├── nlm_lkcache.c ├── nlm_lkcache.h ├── nlm_nsm.c ├── nlm_nsm.h ├── nlm_state_machine.h ├── readdir.c ├── readdir.h ├── session.c ├── sunrpc_passive.c ├── sunrpc_proto.c ├── sunrpc_reply.c ├── xdr.c ├── xdr_nfs.c ├── xdr_nfs.h ├── xdr_nlm.c └── xdr_nlm.h ├── parser ├── CMakeLists.txt ├── Makefile.am ├── configure.in ├── include │ └── Makefile.am └── lib │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── configure.c │ ├── confl.l │ └── confy.y ├── schedule ├── aio.c ├── aio.h ├── co_mq.c ├── core.c ├── core.h ├── corenet.h ├── corenet_connect.h ├── corenet_connect_rdma.c ├── corenet_connect_tcp.c ├── corenet_maping.c ├── corenet_maping.h ├── corenet_rdma.c ├── corenet_tcp.c ├── corerpc.c ├── corerpc.h ├── coroutine.c ├── cpuset.c ├── cpuset.h ├── gettime.c ├── rdma_event.c ├── schedule.c ├── schedule.h ├── schedule_thread.c ├── schedule_thread.h ├── spdk.c ├── spdk.h ├── spdk_extra.h ├── uss_aio.h ├── variable.c ├── variable.h ├── vm.c ├── vm.h └── volume.h ├── scripts ├── Makefile ├── color_output.py ├── delchk.py ├── gen_data.py ├── gen_sshkey.sh ├── install.sh ├── local_startup.tpl ├── path2fid.py ├── taillog.sh └── yfs-shell.py ├── sdfs ├── allocator.c ├── allocator.h ├── attr_queue.c ├── attr_queue.h ├── io_analysis.c ├── io_analysis.h ├── sdfs.c ├── sdfs_chunk.c ├── sdfs_chunk.h ├── sdfs_chunk_recovery.c ├── sdfs_dir.c └── sdfs_inode.c ├── test ├── Makefile.am ├── cluster.conf ├── configure.in ├── exports.conf ├── ftp.conf ├── fuse_test.py ├── include │ └── keep ├── locks │ ├── locktests │ └── locktests.c ├── make_test.sh ├── nfs_conf │ ├── common.conf │ ├── ganesha.conf │ ├── nfs-ganesha │ ├── nfs-ganesha-config.service │ ├── nfs-ganesha-config.sh │ ├── nfs-ganesha-lock.service │ └── nfs-ganesha.service ├── redis.conf.tpl ├── run.sh ├── script │ ├── flock.py │ ├── ftp_test.py │ ├── group_test.py │ ├── nfs_test.py │ ├── quota_test.py │ ├── share_test.py │ └── user_test.py ├── sdfs.conf ├── shell │ ├── iops.sh │ ├── mirror_R.sh │ ├── mk2list.sh │ ├── webdownload.sh │ └── yftp_cmp.sh ├── src │ ├── Makefile.am │ ├── aio_sync_test.c │ ├── bigfile_4g+.c │ ├── io_test.c │ ├── md5.c │ ├── md5.h │ ├── pread_test.c │ ├── python │ │ ├── disk_check.py │ │ ├── merge_chunk.py │ │ ├── test_ls.py │ │ ├── test_symlink.py │ │ ├── yfs_clear.sh │ │ ├── yfs_iotest.py │ │ ├── yfs_mount.sh │ │ └── ynfs.py │ ├── test_aio.c │ ├── test_aio_lib.c │ ├── test_bitmap.c │ ├── test_fuse.c │ ├── test_seek.c │ ├── test_skiplist.c │ ├── testlock.c │ ├── yfsclitest.c │ ├── yftptest.c │ └── ynfs_iotest.c ├── test.py └── test_list.py ├── tools ├── Makefile.gcov ├── app_tar.sh ├── autogen.sh ├── conf.sh ├── delsvn.sh ├── get_version.base ├── get_version.sh ├── getlines.sh ├── mktags.sh ├── ocat.py ├── replice.sh ├── startup.sh ├── tagit.sh ├── trunk_version.sh └── whereis.sh ├── yfs ├── CMakeLists.txt ├── Makefile.am ├── cds │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── cds.c │ ├── cds.h │ ├── cds_hb.c │ ├── cds_hb.h │ ├── cds_lib.c │ ├── cds_lib.h │ ├── cds_volume.c │ ├── cds_volume.h │ ├── chkinfo.c │ ├── chkinfo.h │ ├── disk.c │ ├── disk.h │ ├── dpool.c │ ├── dpool.h │ ├── hb.h │ └── main.c ├── configure.in ├── include │ ├── Makefile.am │ ├── cd_proto.h │ ├── chk_meta.h │ ├── chk_proto.h │ ├── chunk_journal.h │ ├── directory_quota_cache.h │ ├── disk_proto.h │ ├── file_proto.h │ ├── file_table.h │ ├── flock.h │ ├── group.h │ ├── group_quota_cache.h │ ├── inodec.h │ ├── md_proto.h │ ├── node_proto.h │ ├── option.h │ ├── rep_proto.h │ ├── user.h │ ├── user_quota_cache.h │ ├── uss_sysstat.h │ ├── worm_cli_lib.h │ ├── write_crc.h │ ├── xattr.h │ ├── yfs_chunk.h │ ├── yfs_conf.h │ ├── yfs_dir.h │ ├── yfs_file.h │ ├── yfs_limit.h │ ├── yfs_md.h │ ├── yfscds_conf.h │ └── yfscli_conf.h ├── libyfs │ ├── dir.c │ ├── file.c │ ├── file_table.c │ ├── flock.c │ ├── group.c │ ├── node.c │ ├── posix_acl.c │ ├── posix_acl.h │ ├── quota.c │ ├── raw.c │ ├── super.c │ ├── user.c │ ├── worm_cli_lib.c │ └── yfs_lib.c ├── python │ ├── cds_robot │ │ ├── cds_robot.py │ │ └── conf.py │ ├── libs │ │ └── daemon.py │ ├── libyfs │ │ ├── Makefile │ │ └── yfs.c │ └── test │ │ └── test_yfs.py ├── tests │ ├── Makefile.am │ └── yfs_sanity.c └── utils │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── cdsop_read.c │ ├── cmd.c │ ├── jnlfind.c │ ├── leveldb_test.c │ ├── mds_deletedjnl.c │ ├── mdsop_read.c │ ├── newrep.c │ ├── option.c │ ├── rebud_cds_jnl.py │ ├── rebuild_cds_jnl.py │ ├── rebuild_cdsjnl.c │ ├── rebuild_file.c │ ├── recycle.c │ ├── sdfs.health.c │ ├── sdfs.mon.c │ ├── snap_rollback.c │ ├── uss.admin.c │ ├── uss.attr.c │ ├── uss.cat.c │ ├── uss.cdstat.c │ ├── uss.chkstat.c │ ├── uss.chmod.c │ ├── uss.chown.c │ ├── uss.clone.c │ ├── uss.configdump.c │ ├── uss.cp.c │ ├── uss.du.c │ ├── uss.fallocate.c │ ├── uss.ffc.c │ ├── uss.group.c │ ├── uss.hsm.c │ ├── uss.license.c │ ├── uss.ln.c │ ├── uss.lobjck.c │ ├── uss.ls.c │ ├── uss.md5sum.c │ ├── uss.mdsdrop.c │ ├── uss.mdstat.c │ ├── uss.mkdir.c │ ├── uss.mv.c │ ├── uss.ns.c │ ├── uss.objmv.c │ ├── uss.perf.c │ ├── uss.perf_mds.c │ ├── uss.prof.c │ ├── uss.quota.c │ ├── uss.rm.c │ ├── uss.rmdir.c │ ├── uss.share.c │ ├── uss.stat.c │ ├── uss.statvfs.c │ ├── uss.sysop.c │ ├── uss.tgtadm.c │ ├── uss.touch.c │ ├── uss.truncate.c │ ├── uss.user.c │ ├── uss.worm.c │ ├── uss.write.c │ ├── uss.zk.c │ ├── ycdsfsck.c │ ├── ychk_rep_check.c │ ├── ychkcp.c │ ├── ychkstat.c │ ├── ychktable_print.c │ ├── ychunk_check.c │ ├── ychunk_merge.c │ ├── ycmd.c │ ├── ycompact.c │ ├── yfsck.c │ ├── ylogin.c │ ├── yls.c │ ├── ylvm.c │ ├── ymkdir.c │ ├── ypasswd.c │ ├── yping.c │ ├── yread_mdsjnl.c │ ├── yrecover.c │ ├── yrecycle.c │ ├── yrep.c │ ├── yrm.c │ ├── yrmdir.c │ ├── yshutdown.c │ ├── ystat.c │ ├── ystatchk.c │ ├── ysync_mdsjnl.c │ ├── ytruncate.c │ └── yuser.c ├── yftp ├── CMakeLists.txt ├── Makefile.am ├── configure.in ├── include │ ├── Makefile.am │ └── yftp_conf.h └── src │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── cmdio.c │ ├── cmdio.h │ ├── dataio.c │ ├── dataio.h │ ├── ftpcodes.h │ ├── ftpfeatures.c │ ├── ftpfeatures.h │ ├── main.c │ ├── postlogin.c │ ├── postlogin.h │ ├── prelogin.c │ ├── prelogin.h │ ├── session.c │ └── session.h ├── yfuse ├── Makefile.am ├── configure.in ├── include │ └── Makefile.am ├── readme └── src │ ├── Makefile.am │ └── main.c ├── yfuse3 ├── Makefile.am ├── configure.in ├── include │ └── Makefile.am ├── readme └── src │ ├── Makefile.am │ └── main.c ├── ylib ├── CMakeLists.txt ├── Makefile.am ├── configure.in ├── include │ ├── Makefile.am │ ├── adt.h │ ├── analysis.h │ ├── array_table.h │ ├── base64_urlsafe.h │ ├── bh.h │ ├── bmap.h │ ├── cJSON.h │ ├── cache.h │ ├── dbg.h │ ├── dbg_message.h │ ├── dbg_proto.h │ ├── errno_extern.h │ ├── etcd-api.h │ ├── etcd.h │ ├── fnotify.h │ ├── hash_table.h │ ├── heap.h │ ├── htable.h │ ├── jnl_proto.h │ ├── job.h │ ├── job_dock.h │ ├── job_tracker.h │ ├── kv.h │ ├── ll.h │ ├── md5.h │ ├── mem_cache.h │ ├── mem_pool.h │ ├── mini_hashtb.h │ ├── newdef.h │ ├── nls.h │ ├── nodectl.h │ ├── pipe_pool.h │ ├── plock.h │ ├── privilege.h │ ├── proc.h │ ├── redis_util.h │ ├── removed.h │ ├── round_journal.h │ ├── skiplist.h │ ├── squeue.h │ ├── stdatomic.h │ ├── sysutil.h │ ├── timer.h │ ├── tpool.h │ ├── worker.h │ ├── xdr.h │ ├── yatomic.h │ ├── ylib.h │ ├── ylock.h │ ├── ylog.h │ ├── ypath.h │ └── ytime.h ├── lib │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── analysis.c │ ├── array_table.c │ ├── auth.c │ ├── base64.c │ ├── base64_urlsafe.c │ ├── bh.c │ ├── bmap.c │ ├── buffer.c │ ├── cJSON.c │ ├── cache.c │ ├── cmp.c │ ├── config.c │ ├── crc32.c │ ├── crcrs.c │ ├── daemon.c │ ├── dbg.c │ ├── ec_isa_l.c │ ├── etcd-api.c │ ├── etcd.c │ ├── fnotify.c │ ├── hash.c │ ├── hash_table.c │ ├── heap.c │ ├── htable.c │ ├── job_dock.c │ ├── job_tracker.c │ ├── journal.c │ ├── kv.c │ ├── ll.c │ ├── lock.c │ ├── md5.c │ ├── mem.c │ ├── mem_cache.c │ ├── mem_hugepage.c │ ├── mem_pool.c │ ├── mini_hashtb.c │ ├── nls.c │ ├── nls │ │ └── nls_cp936.c │ ├── nodectl.c │ ├── path.c │ ├── plock.c │ ├── privilege.c │ ├── redis_util.c │ ├── removed.c │ ├── skiplist.c │ ├── squeue.c │ ├── stat.c │ ├── str.c │ ├── sysutil.c │ ├── timer.c │ ├── tpool.c │ ├── worker.c │ ├── ylog.c │ └── ytime.c └── tests │ ├── Makefile.am │ ├── array_test.c │ ├── cache_test.c │ ├── cmd_test.c │ ├── crc32.c │ ├── heap_test.c │ ├── jnl_test.c │ ├── path.c │ ├── skiplist_test.c │ └── splice.c ├── ynet ├── CMakeLists.txt ├── Makefile.am ├── configure.in ├── include │ ├── Makefile.am │ ├── conn.h │ ├── main_loop.h │ ├── maping.h │ ├── msgqueue.h │ ├── net_global.h │ ├── net_proto.h │ ├── net_table.h │ ├── netbios_passive.h │ ├── netbios_proto.h │ ├── netbios_reply.h │ ├── network.h │ ├── nodeid.h │ ├── rpc_table.h │ ├── sdevent.h │ ├── sunrpc_passive.h │ ├── sunrpc_proto.h │ ├── sunrpc_reply.h │ ├── ynet.h │ ├── ynet_conf.h │ ├── ynet_net.h │ └── ynet_rpc.h ├── net │ ├── conn.c │ ├── heartbeat.c │ ├── heartbeat.h │ ├── main_loop.c │ ├── maping.c │ ├── net_crc.c │ ├── net_events.c │ ├── net_events.h │ ├── net_lib.c │ ├── net_passive.c │ ├── net_rpc.c │ ├── net_rpc.h │ ├── net_table.c │ ├── net_xmit.c │ ├── net_xnect.c │ ├── network.c │ ├── nodeid.c │ ├── xnect.c │ └── xnect.h ├── netbios │ ├── netbios_passive.c │ ├── netbios_proto.c │ └── netbios_reply.c ├── rpc │ ├── msgqueue.c │ ├── rpc_lib.c │ ├── rpc_passive.c │ ├── rpc_proto.c │ ├── rpc_proto.h │ ├── rpc_reply.c │ ├── rpc_request.c │ ├── rpc_table.c │ ├── rpc_xmit.c │ └── rpc_xnect.c ├── sock │ ├── sdevent.c │ ├── sock_buffer.c │ ├── sock_buffer.h │ ├── sock_passive.c │ ├── sock_tcp.c │ ├── sock_tcp.h │ ├── sock_udp.c │ ├── sock_udp.h │ ├── sock_unix.c │ ├── sock_xmit.c │ ├── sock_xnect.c │ └── ynet_sock.h └── tests │ ├── Makefile.am │ ├── listener.c │ ├── msgqueue_cp.c │ ├── msgqueue_read.c │ ├── msgqueue_write.c │ ├── proxy.c │ └── speaker.c └── yweb ├── CMakeLists.txt ├── Makefile.am ├── configure.in ├── include ├── Makefile.am ├── http_state_machine.h └── yweb_conf.h ├── src ├── CMakeLists.txt ├── Makefile.am ├── http_ops.c ├── http_ops.h ├── http_proto.c ├── http_proto.h ├── http_readdir.c ├── http_state_machine.c ├── http_state_machine.h ├── main.c ├── match.c ├── match.h ├── mime.c ├── mime.h ├── mime_encodings.txt ├── mime_types.txt ├── request.c ├── request.h ├── response.c ├── response.h ├── str.c ├── str.h ├── tdate_parse.c └── tdate_parse.h └── tests └── wget.sh /admin/Ganesha/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | -------------------------------------------------------------------------------- /admin/buddha/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/admin/buddha/__init__.py -------------------------------------------------------------------------------- /admin/buddha/fileutil.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | 5 | from utils import _str2dict 6 | 7 | 8 | class LichFile(object): 9 | def __init__(self, filename=None): 10 | self.filename = filename 11 | 12 | @staticmethod 13 | def read_int(filename): 14 | with open(filename) as f: 15 | res = f.read() 16 | return int(res.strip('\n').strip('\0')) 17 | 18 | @staticmethod 19 | def write_int(filename, n): 20 | with open(filename, 'w') as f: 21 | f.write('%d\n' % n) 22 | f.flush() 23 | 24 | @staticmethod 25 | def read_dict(filename): 26 | with open(filename) as f: 27 | res = f.read() 28 | return _str2dict(res) 29 | -------------------------------------------------------------------------------- /admin/buddha/lsb.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import platform 3 | 4 | def check_lsb_release(): 5 | """ 6 | Verify if lsb_release command is available 7 | """ 8 | args = [ 'which', 'lsb_release', ] 9 | process = subprocess.Popen( 10 | args=args, 11 | stdout=subprocess.PIPE, 12 | ) 13 | lsb_release_path, _ = process.communicate() 14 | ret = process.wait() 15 | if ret != 0: 16 | raise RuntimeError('The lsb_release command was not found on remote host. Please install the lsb-release package.') 17 | 18 | def lsb_release(): 19 | """ 20 | Get LSB release information from platform. 21 | 22 | Returns truple with distro, release and codename. 23 | """ 24 | distro, release, codename = platform.dist() 25 | if distro == 'centos': 26 | distro = 'CentOS' 27 | return (str(distro).rstrip(), str(release).rstrip(), str(codename).rstrip()) 28 | 29 | def choose_init(distro, codename): 30 | """ 31 | Select a init system for a given distribution. 32 | 33 | Returns the name of a init system (upstart, sysvinit ...). 34 | """ 35 | if distro == 'Ubuntu': 36 | return 'upstart' 37 | return 'sysvinit' 38 | 39 | if __name__ == '__main__': 40 | lsb_release = lsb_release() 41 | print lsb_release 42 | print choose_init('Ubuntu', 400) 43 | -------------------------------------------------------------------------------- /admin/create_access_relation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | import os 4 | def create_access_relation(): 5 | if os.path.exists("/lib64/libnss_winbind.so"): 6 | os.remove("/lib64/libnss_winbind.so") 7 | os.system("ln -s /usr/local/samba/lib/libnss_winbind.so /lib64") 8 | print "recreate libnss_winbind.so ok" 9 | else: 10 | os.system("ln -s /usr/local/samba/lib/libnss_winbind.so /lib64") 11 | print "create libnss_winbind.so ok" 12 | if os.path.exists("/lib64/libnss_winbind.so.2"): 13 | os.remove("/lib64/libnss_winbind.so.2") 14 | os.system("ln -s /lib64/libnss_winbind.so /lib64/libnss_winbind.so.2") 15 | print "recreate libnss_winbind.so.2 ok" 16 | else: 17 | os.system("ln -s /lib64/libnss_winbind.so /lib64/libnss_winbind.so.2") 18 | print "create libnss_winbind.so.2" 19 | if os.path.exists("/lib64/security/pam_winbind.so"): 20 | os.remove("/lib64/security/pam_winbind.so") 21 | os.system("ln -s /usr/local/samba/lib/security/pam_winbind.so /lib64/security") 22 | print "recreate security ok" 23 | else: 24 | os.system("ln -s /usr/local/samba/lib/security/pam_winbind.so /lib64/security") 25 | print "create security ok" 26 | if __name__ == "__main__": 27 | create_access_relation() -------------------------------------------------------------------------------- /admin/set-nodes-info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | import os 4 | 5 | def exec_cmd(cmd): 6 | ip_list = [] 7 | r = os.popen(cmd).readlines() 8 | for item in r: 9 | if item != "\n": 10 | if item.split(":")[0] == "stat host": 11 | ip_list.append(item.split(":")[1].strip("\n").strip()) 12 | return ip_list 13 | 14 | def write_data(): 15 | for i in result: 16 | with open("/usr/local/samba/etc/ctdb/nodes",mode="a") as fw: 17 | fw.write(i) 18 | fw.write("\n") 19 | 20 | if __name__ == "__main__": 21 | result=exec_cmd("uss.cluster list") 22 | if os.path.exists("/usr/local/samba/etc/ctdb/nodes"): 23 | os.system('rm -rf /usr/local/samba/etc/ctdb/nodes') 24 | write_data() 25 | else: 26 | write_data() -------------------------------------------------------------------------------- /admin/test_uss_touch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | import os 5 | import sys 6 | import errno 7 | 8 | from config import Config 9 | from utils import Exp, exec_shell, dwarn, dmsg 10 | 11 | def test_mkdir(config): 12 | try: 13 | _exec_mkdir = "%s /zz" % (config.uss_mkdir) 14 | exec_shell(_exec_mkdir) 15 | _exec_stat = "%s /zz" % (config.uss_stat) 16 | exec_shell(_exec_stat) 17 | except Exp, err: 18 | dmsg("test_mkdir or test_stat failed\n") 19 | sys.exit(-1); 20 | 21 | def test_touch(config): 22 | for i in range(100): 23 | try: 24 | _exec_touch = "%s /zz/zz%d" % (config.uss_touch, i) 25 | exec_shell(_exec_touch) 26 | _exec_stat = "%s /zz/zz%d" % (config.uss_stat, i) 27 | exec_shell(_exec_stat) 28 | _exec_rm = "%s /zz/zz%d" % (config.uss_rm, i) 29 | exec_shell(_exec_rm) 30 | except Exp, err: 31 | dmsg("test_touch or test_stat failed\n") 32 | sys.exit(-1); 33 | 34 | if __name__ == "__main__": 35 | config = Config(); 36 | test_mkdir(config) 37 | test_touch(config) 38 | -------------------------------------------------------------------------------- /admin/uss_samba_init_centos_6: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #chkconfig: 2345 42 42 3 | #description: uss_ucarp service 4 | 5 | RETVAL=0 6 | case "$1" in 7 | start) 8 | /opt/fusionnas/app/admin/samba.py start 9 | ;; 10 | stop) 11 | /opt/fusionnas/app/admin/samba.py stop 12 | ;; 13 | restart) 14 | /opt/fusionnas/app/admin/samba.py stop 15 | /opt/fusionnas/app/admin/samba.py start 16 | ;; 17 | *) 18 | echo $"Usage: $0 {start|stop|restart}" 19 | RETVAL=2 20 | esac 21 | exit $RETVAL 22 | -------------------------------------------------------------------------------- /admin/uss_samba_init_centos_7: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=uss_samba 3 | DefaultDependencies=no 4 | After=network.target local-fs.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/opt/fusionnas/app/admin/samba.py start 9 | ExecReload=/opt/fusionnas/app/admin/samba.py reload 10 | ExecStop=/opt/fusionnas/app/admin/samba.py stop 11 | TimeoutStartSec=3600 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /admin/uss_samba_init_ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # upstart-job 3 | # 4 | # Symlink target for initscripts that have been converted to Upstart. 5 | 6 | set -e 7 | 8 | INITSCRIPT="$(basename "$0")" 9 | JOB="${INITSCRIPT%.sh}" 10 | 11 | if [ "$JOB" = "upstart-job" ]; then 12 | if [ -z "$1" ]; then 13 | echo "Usage: upstart-job JOB COMMAND" 1>&2 14 | exit 1 15 | fi 16 | 17 | JOB="$1" 18 | INITSCRIPT="$1" 19 | shift 20 | else 21 | if [ -z "$1" ]; then 22 | echo "Usage: $0 COMMAND" 1>&2 23 | exit 1 24 | fi 25 | fi 26 | 27 | COMMAND="$1" 28 | shift 29 | 30 | if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then 31 | ECHO=echo 32 | else 33 | ECHO=: 34 | fi 35 | 36 | case $COMMAND in 37 | start) 38 | /opt/fusionnas/app/admin/samba.py start 39 | ;; 40 | stop) 41 | /opt/fusionnas/app/admin/samba.py stop 42 | ;; 43 | restart) 44 | /opt/fusionnas/app/admin/samba.py stop 45 | /opt/fusionnas/app/admin/samba.py start 46 | ;; 47 | *) 48 | $ECHO "Crazy" 49 | exit 1 50 | esac 51 | -------------------------------------------------------------------------------- /admin/uss_ucarp_init_centos_6: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #chkconfig: 2345 42 42 3 | #description: uss_ucarp service 4 | 5 | RETVAL=0 6 | case "$1" in 7 | start) 8 | uss.node ucarpstart 9 | ;; 10 | stop) 11 | uss.node ucarpstop 12 | ;; 13 | restart) 14 | uss.node ucarpstop 15 | uss.node ucarpstart 16 | ;; 17 | *) 18 | echo $"Usage: $0 {start|stop|restart}" 19 | RETVAL=2 20 | esac 21 | exit $RETVAL 22 | -------------------------------------------------------------------------------- /admin/uss_ucarp_init_centos_7: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=uss_ucarp 3 | DefaultDependencies=no 4 | After=network.target local-fs.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/opt/fusionnas/app/bin/uss.node ucarpstart 9 | TimeoutStartSec=3600 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /admin/uss_ucarp_init_ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # upstart-job 3 | # 4 | # Symlink target for initscripts that have been converted to Upstart. 5 | 6 | set -e 7 | 8 | INITSCRIPT="$(basename "$0")" 9 | JOB="${INITSCRIPT%.sh}" 10 | 11 | if [ "$JOB" = "upstart-job" ]; then 12 | if [ -z "$1" ]; then 13 | echo "Usage: upstart-job JOB COMMAND" 1>&2 14 | exit 1 15 | fi 16 | 17 | JOB="$1" 18 | INITSCRIPT="$1" 19 | shift 20 | else 21 | if [ -z "$1" ]; then 22 | echo "Usage: $0 COMMAND" 1>&2 23 | exit 1 24 | fi 25 | fi 26 | 27 | COMMAND="$1" 28 | shift 29 | 30 | if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then 31 | ECHO=echo 32 | else 33 | ECHO=: 34 | fi 35 | 36 | case $COMMAND in 37 | start) 38 | uss.node ucarpstart 39 | ;; 40 | stop) 41 | uss.node ucarpstop 42 | ;; 43 | restart) 44 | uss.node ucarpstop 45 | uss.node ucarpstart 46 | ;; 47 | *) 48 | $ECHO "Crazy" 49 | exit 1 50 | esac 51 | -------------------------------------------------------------------------------- /admin/uss_vip_init_centos_6: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #chkconfig: 2345 42 42 3 | #description: uss_vip service 4 | 5 | RETVAL=0 6 | case "$1" in 7 | start) 8 | uss.node vipstart 9 | ;; 10 | stop) 11 | uss.node vipstop 12 | ;; 13 | restart) 14 | uss.node vipstop 15 | uss.node vipstart 16 | ;; 17 | *) 18 | echo $"Usage: $0 {start|stop|restart}" 19 | RETVAL=2 20 | esac 21 | exit $RETVAL 22 | -------------------------------------------------------------------------------- /admin/uss_vip_init_centos_7: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=uss_vip 3 | DefaultDependencies=no 4 | After=network.target local-fs.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/opt/fusionnas/app/bin/uss.node vipstart 9 | ExecStop=/opt/fusionnas/app/bin/uss.node vipstop 10 | TimeoutStartSec=3600 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /admin/uss_vip_init_ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # upstart-job 3 | # 4 | # Symlink target for initscripts that have been converted to Upstart. 5 | 6 | set -e 7 | 8 | INITSCRIPT="$(basename "$0")" 9 | JOB="${INITSCRIPT%.sh}" 10 | 11 | if [ "$JOB" = "upstart-job" ]; then 12 | if [ -z "$1" ]; then 13 | echo "Usage: upstart-job JOB COMMAND" 1>&2 14 | exit 1 15 | fi 16 | 17 | JOB="$1" 18 | INITSCRIPT="$1" 19 | shift 20 | else 21 | if [ -z "$1" ]; then 22 | echo "Usage: $0 COMMAND" 1>&2 23 | exit 1 24 | fi 25 | fi 26 | 27 | COMMAND="$1" 28 | shift 29 | 30 | if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then 31 | ECHO=echo 32 | else 33 | ECHO=: 34 | fi 35 | 36 | case $COMMAND in 37 | start) 38 | uss.node vipstart 39 | ;; 40 | stop) 41 | uss.node vipstop 42 | ;; 43 | restart) 44 | uss.node vipstop 45 | uss.node vipstart 46 | ;; 47 | *) 48 | $ECHO "Crazy" 49 | exit 1 50 | esac 51 | -------------------------------------------------------------------------------- /admin/ussd_init_centos_6: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #chkconfig: 2345 42 42 3 | #description: lichd service 4 | 5 | RETVAL=0 6 | case "$1" in 7 | status) 8 | lich.node --stat 9 | ;; 10 | start) 11 | lich.node --start 12 | ;; 13 | stop) 14 | lich.node --stop 15 | ;; 16 | restart) 17 | lich.node --stop 18 | lich.node --start 19 | ;; 20 | *) 21 | echo $"Usage: $0 {start|stop|restart|status}" 22 | RETVAL=2 23 | esac 24 | exit $RETVAL 25 | -------------------------------------------------------------------------------- /admin/ussd_init_centos_7: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=uss_node 3 | DefaultDependencies=no 4 | After=network.target local-fs.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/opt/fusionnas/app/bin/uss.node start 9 | ExecStop=/opt/fusionnas/app/bin/uss.node stop 10 | TimeoutStartSec=3600 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /admin/ussd_init_ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # upstart-job 3 | # 4 | # Symlink target for initscripts that have been converted to Upstart. 5 | 6 | set -e 7 | 8 | INITSCRIPT="$(basename "$0")" 9 | JOB="${INITSCRIPT%.sh}" 10 | 11 | if [ "$JOB" = "upstart-job" ]; then 12 | if [ -z "$1" ]; then 13 | echo "Usage: upstart-job JOB COMMAND" 1>&2 14 | exit 1 15 | fi 16 | 17 | JOB="$1" 18 | INITSCRIPT="$1" 19 | shift 20 | else 21 | if [ -z "$1" ]; then 22 | echo "Usage: $0 COMMAND" 1>&2 23 | exit 1 24 | fi 25 | fi 26 | 27 | COMMAND="$1" 28 | shift 29 | 30 | if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then 31 | ECHO=echo 32 | else 33 | ECHO=: 34 | fi 35 | 36 | case $COMMAND in 37 | status) 38 | lich.node --stat 39 | ;; 40 | start) 41 | lich.node --start 42 | ;; 43 | stop) 44 | lich.node --stop 45 | ;; 46 | restart) 47 | lich.node --stop 48 | lich.node --start 49 | ;; 50 | *) 51 | $ECHO "Crazy" 52 | exit 1 53 | esac 54 | -------------------------------------------------------------------------------- /cds/cds_rpc.h: -------------------------------------------------------------------------------- 1 | #ifndef __CDS_RPC_H__ 2 | #define __CDS_RPC_H__ 3 | 4 | 5 | static inline void io_init(io_t *io, const chkid_t *chkid, 6 | uint32_t size, uint64_t offset, uint32_t flags) 7 | { 8 | memset(io, 0 ,sizeof(io_t)); 9 | 10 | if(chkid) 11 | io->id = *chkid; 12 | 13 | io->offset = offset; 14 | io->size = size; 15 | io->flags = flags; 16 | io->lsn = 0; 17 | io->lease = -1; 18 | io->snapvers = 0; 19 | } 20 | 21 | int cds_rpc_init(); 22 | int cds_rpc_read(const nid_t *nid, const io_t *io, buffer_t *_buf); 23 | int cds_rpc_write(const nid_t *nid, const io_t *io, const buffer_t *_buf); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /cds/diskio.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISKIO_H__ 2 | #define __DISKIO_H__ 3 | 4 | #include 5 | #include "ylib.h" 6 | 7 | int diskio_submit(struct iocb *iocb, func1_t func); 8 | int diskio_init(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /cds/replica.h: -------------------------------------------------------------------------------- 1 | #ifndef __REPLICA_IO_H__ 2 | #define __REPLICA_IO_H__ 3 | 4 | #include "sdfs_lib.h" 5 | #include "ylib.h" 6 | #include "net_global.h" 7 | 8 | static inline void chkid2path(const chkid_t *chkid, uint64_t snapvers, char *path) 9 | { 10 | char cpath[MAX_PATH_LEN]; 11 | 12 | (void) cascade_id2path(cpath, MAX_PATH_LEN, chkid->id); 13 | 14 | (void) snprintf(path, MAX_PATH_LEN, "%s/volume/%ju/%ju/%s/%u.chunk", 15 | ng.home, chkid->volid, snapvers, cpath, chkid->idx); 16 | 17 | } 18 | 19 | int IO_FUNC replica_read(const io_t *io, buffer_t *buf); 20 | int IO_FUNC replica_write(const io_t *io, const buffer_t *buf); 21 | int replica_init(); 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /doc/load balance.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/doc/load balance.docx -------------------------------------------------------------------------------- /doc/vip.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/doc/vip.docx -------------------------------------------------------------------------------- /etc/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | ./install.sh -i 3 | 4 | uninstall: 5 | ./install.sh -e 6 | -------------------------------------------------------------------------------- /etc/clean_cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | nodes=`cat /opt/sdfs/etc/cluster.conf |awk '{print $1}'` 4 | 5 | /opt/sdfs/app/admin/cluster.py stop 6 | 7 | for n in $nodes 8 | do 9 | echo "clean " $n 10 | ssh $n 'systemctl stop etcd' 11 | ssh $n 'pkill -9 sdfs' 12 | ssh $n 'pkill -9 redis' 13 | ssh $n 'pkill -9 python' 14 | ssh $n 'rm -rf /opt/sdfs/data/mond/*/*' 15 | ssh $n 'rm -rf /opt/sdfs/data/etcd/*' 16 | ssh $n 'rm -rf /opt/sdfs/data/redis/*/*' 17 | ssh $n 'rm -rf /opt/sdfs/data/cds/*/*' 18 | ssh $n 'rm -rf /opt/sdfs/data/fuse/*' 19 | ssh $n 'rm -rf /opt/sdfs/data/fuse3/*' 20 | ssh $n 'rm -rf /opt/sdfs/data/ftp/*' 21 | ssh $n 'rm -rf /opt/sdfs/data/nfs/*' 22 | ssh $n 'rm -rf /opt/sdfs/data/fsal_sdfs/*' 23 | ssh $n 'rm -rf /opt/sdfs/core/*' 24 | ssh $n 'rm -rf /opt/sdfs/log/*' 25 | ssh $n 'rm -rf /opt/sdfs/etc/cluster.conf' 26 | ssh $n 'rm -rf /dev/shm/sdfs/*' 27 | done 28 | 29 | 30 | -------------------------------------------------------------------------------- /etc/cluster.conf: -------------------------------------------------------------------------------- 1 | auto1.host155.vmnode31 redis[0,1] mond[0] cds[0,1,2,3,4,5,6] nfs[0] 2 | auto1.host155.vmnode32 redis[0,1] mond[0] cds[0,1,2,3,4,5,6] nfs[0] 3 | auto1.host155.vmnode33 redis[0,1] mond[0] cds[0,1,2,3,4,5,6] nfs[0] 4 | -------------------------------------------------------------------------------- /etc/exports.conf: -------------------------------------------------------------------------------- 1 | ynfs { 2 | use_export off; 3 | export { 4 | /default 127.0.0.1 (rw); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /etc/ftp.conf: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /etc/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CONF_DIR="/sysy/yfs/etc" 4 | YFSCONF="yfs.conf" 5 | CLUSTER="cluster.conf" 6 | 7 | usage() 8 | { 9 | echo "Usage: $0 [OPTIONS]" 10 | echo "-i install" 11 | echo "-e remove" 12 | 13 | exit 1 14 | } 15 | 16 | install() 17 | { 18 | 19 | if [ -e $CONF_DIR ]; 20 | then 21 | echo "$CONF_DIR exists, ingore" 22 | else 23 | mkdir -p $CONF_DIR 24 | 25 | cp $YFSCONF $CONF_DIR 26 | 27 | cp $CLUSTER $CONF_DIR 28 | fi 29 | } 30 | 31 | remove() 32 | { 33 | echo "remove $CONF_DIR" 34 | rm -fr $CONF_DIR 35 | } 36 | 37 | if [ $# -lt 1 ] 38 | then 39 | usage 40 | fi 41 | 42 | while getopts ieh options 43 | do 44 | case $options in 45 | i) 46 | echo "install conf" 47 | install 48 | ;; 49 | e) 50 | echo "remove conf" 51 | remove 52 | ;; 53 | h) 54 | usage 55 | ;; 56 | \?) 57 | usage 58 | ;; 59 | esac 60 | done 61 | 62 | -------------------------------------------------------------------------------- /etc/redis.conf.tpl: -------------------------------------------------------------------------------- 1 | daemonize yes 2 | tcp-backlog 511 3 | unixsocketperm 700 4 | timeout 0 5 | tcp-keepalive 0 6 | loglevel notice 7 | databases 16 8 | save 900 1 9 | save 300 10 10 | save 60 10000 11 | stop-writes-on-bgsave-error yes 12 | rdbcompression yes 13 | rdbchecksum yes 14 | dbfilename dump.rdb 15 | slave-serve-stale-data yes 16 | slave-read-only yes 17 | repl-diskless-sync no 18 | repl-diskless-sync-delay 5 19 | repl-disable-tcp-nodelay no 20 | slave-priority 100 21 | appendonly yes 22 | appendfilename "appendonly.aof" 23 | #appendfsync always 24 | appendfsync everysec 25 | no-appendfsync-on-rewrite no 26 | auto-aof-rewrite-percentage 150 27 | auto-aof-rewrite-min-size 64mb 28 | aof-load-truncated yes 29 | lua-time-limit 5000 30 | slowlog-log-slower-than 10000 31 | slowlog-max-len 128 32 | latency-monitor-threshold 0 33 | notify-keyspace-events "" 34 | hash-max-ziplist-entries 512 35 | hash-max-ziplist-value 64 36 | list-max-ziplist-entries 512 37 | list-max-ziplist-value 64 38 | set-max-intset-entries 512 39 | zset-max-ziplist-entries 128 40 | zset-max-ziplist-value 64 41 | hll-sparse-max-bytes 3000 42 | activerehashing yes 43 | client-output-buffer-limit normal 0 0 0 44 | client-output-buffer-limit slave 256mb 64mb 60 45 | client-output-buffer-limit pubsub 32mb 8mb 60 46 | hz 10 47 | aof-rewrite-incremental-fsync yes 48 | -------------------------------------------------------------------------------- /etc/sdfs.conf: -------------------------------------------------------------------------------- 1 | globals { 2 | chunk_rep 2; 3 | rpc_timeout 20; 4 | performance_analysis 1; 5 | 6 | redis_sharding 1; 7 | redis_replica 2; 8 | check_mountpoint off; 9 | check_version off; 10 | home /opt/sdfs/data; 11 | polling_timeout 1; 12 | polling_core 1; 13 | 14 | #maxcore on; 15 | #nfs ganesha; 16 | 17 | networks { 18 | 127.100.0.0/24; 19 | } 20 | } 21 | 22 | mds { 23 | disk_keep 10G; 24 | redis_thread off; 25 | } 26 | 27 | cds { 28 | io_sync on; 29 | aio_thread off; 30 | cds_polling off; 31 | } -------------------------------------------------------------------------------- /etc/yfs-shell.conf: -------------------------------------------------------------------------------- 1 | # mds server 2 | # example: 3 | [net] 4 | #net=192.168.1.2 5 | #mask=255.255.255.0 6 | 7 | [master] 8 | mds=127.0.0.1 9 | 10 | [slaves] 11 | cds=(127.0.0.1:3), 12 | 13 | [client] 14 | yiscsi=127.0.0.1 15 | #ynfs=127.0.0.1 16 | 17 | [backup] 18 | log=/var/log/yfs_log_backup 19 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/include/Makefile.am -------------------------------------------------------------------------------- /include/cmakeconfig.h.ini: -------------------------------------------------------------------------------- 1 | #define SDFS_HOME "@SDFS_HOME@" 2 | #define USE_EPOLL @USE_EPOLL@ 3 | -------------------------------------------------------------------------------- /include/mem_hugepage.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEM_HUGEPAGE_H_ 2 | #define __MEM_HUGEPAGE_H_ 3 | 4 | #include "sdfs_buffer.h" 5 | 6 | int mem_hugepage_init(); 7 | int mem_hugepage_private_init(); // used by core thread mbuffer_t 8 | int mem_hugepage_private_destoy(); 9 | 10 | int mem_hugepage_new(uint32_t size, mem_handler_t *mem_handler); 11 | 12 | int mem_hugepage_ref(mem_handler_t *mem_handler); 13 | int mem_hugepage_deref(mem_handler_t *mem_handler); 14 | void mem_hugepage_private_dump(); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/sdfs_ec.h: -------------------------------------------------------------------------------- 1 | #ifndef __EC_H__ 2 | #define __EC_H__ 3 | 4 | 5 | #include "sdfs_conf.h" 6 | #include "sdfs_buffer.h" 7 | 8 | //m = k + r 9 | #define EC_MMAX YFS_CHK_REP_MAX 10 | #define EC_KMAX YFS_CHK_REP_MAX 11 | 12 | #define STRIP_BLOCK 4096 13 | #define STRIP_ALIGN 64 14 | #define STRIP_MAX (YFS_CHK_SIZE/STRIP_BLOCK) 15 | 16 | typedef enum { 17 | PLUGIN_NULL, 18 | PLUGIN_EC_ISA, 19 | PLGUIN_MAX 20 | } ec_plugin_t; 21 | 22 | typedef enum { 23 | TECH_NULL, 24 | TECH_ISA_SSE, 25 | } ec_technique_t; 26 | 27 | typedef struct { 28 | uint8_t plugin; 29 | uint8_t tech; 30 | uint8_t k; 31 | uint8_t m; 32 | } ec_t; 33 | 34 | typedef struct { 35 | uint8_t idx; 36 | uint32_t offset; 37 | uint32_t count; 38 | buffer_t buf; 39 | } ec_strip_t; 40 | 41 | int ec_encode(char **data, char **coding, int blocksize, int m, int k); 42 | int ec_decode(unsigned char *src_in_err, char **data, char **coding, int blocksize, int m, int k); 43 | 44 | //uint8_t technique=reed_sol_van; 45 | #endif 46 | -------------------------------------------------------------------------------- /include/sdfs_worm.h: -------------------------------------------------------------------------------- 1 | #ifndef _WORM_H_ 2 | #define _WORM_H_ 3 | 4 | #define WORM_ARG_MIN_PROTECT 0x00000001 5 | #define WORM_ARG_MAX_PROTECT 0x00000002 6 | #define WORM_ARG_DEFAULT_PROTECT 0x00000004 7 | #define WORM_ARG_AUTO_LOCK 0x00000008 8 | #define WORM_ARG_PATH 0x0000000A 9 | 10 | #define WORM_CLOCKDIR "/WORM_CLOCK" 11 | #define WORM_FID_NULL 0 12 | 13 | #define WORM_ATTR_KEY "uss_system_worm_attr" 14 | #define WORM_FILE_KEY "uss_system_worm_file" 15 | #define WORM_CLOCK_KEY "uss_system_worm_clock" 16 | 17 | #define WORM_ADMIN_USER "wormadmin" 18 | #define WORM_ADMIN_PASS "wormadmin" 19 | #define WORM_ADMIN_LEN 9 20 | 21 | #define ONE_HOUR (3600) 22 | 23 | typedef enum { 24 | WORM_BEFORE_PROTECT = 1, 25 | WORM_IN_PROTECT, 26 | WORM_AFTER_PROTECT, 27 | WORM_NOT_SET 28 | }worm_status_t; 29 | 30 | typedef enum { 31 | WORM_ROOT = 1, 32 | WORM_SUBDIR, 33 | WORM_FILE 34 | } worm_type_t; 35 | 36 | typedef struct { 37 | worm_type_t worm_type; 38 | fileid_t fileid; 39 | uint32_t min_protect_period; 40 | uint32_t max_protect_period; 41 | uint32_t default_protect_period; 42 | uint32_t auto_lock_period; 43 | char path[MAX_NAME_LEN]; 44 | }worm_t; 45 | 46 | typedef struct { 47 | char status[MAX_NAME_LEN]; 48 | uint32_t set_atime; 49 | }worm_file_t; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /itest/include/yutils.h: -------------------------------------------------------------------------------- 1 | #ifndef __YUTILS_H 2 | #define __YUTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef std::vector StringVector; 9 | 10 | static inline int split(char *str, StringVector& args) { 11 | char *token; 12 | 13 | token = strtok(str, " "); 14 | while (token) { 15 | args.push_back(std::string(token)); 16 | token = strtok(NULL, " "); 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | /* Strip whitespace from the start and end of STRING. Return a pointer 23 | into STRING. */ 24 | static inline char* stripwhite (char *string) { 25 | register char *s, *t; 26 | 27 | for (s = string; isspace (*s); s++) 28 | ; 29 | 30 | if (*s == 0) 31 | return (s); 32 | 33 | t = s + strlen (s) - 1; 34 | while (t > s && isspace (*t)) 35 | t--; 36 | *++t = '\0'; 37 | 38 | return s; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /itest/ylib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | # ${PROJECT_SOURCE_DIR}/itest/gtest/include 7 | ) 8 | link_directories(${PROJECT_BINARY_DIR}/lib 9 | # ${PROJECT_SOURCE_DIR}/itest/gtest/build 10 | ) 11 | 12 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/itest/bin) 13 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 14 | 15 | set(EXTRA_LIBS uuid crypt pthread aio ssl parser ylib ynet yfs) 16 | 17 | set(TESTS 18 | test_bitmap 19 | test_skiplist 20 | ) 21 | 22 | foreach(t ${TESTS}) 23 | message(STATUS "Test " ${t}) 24 | add_executable(${t} ${t}.c) 25 | target_link_libraries(${t} ${EXTRA_LIBS}) 26 | endforeach() 27 | 28 | # gtest 29 | set(GTESTS 30 | itest_ylib) 31 | 32 | foreach(t ${GTESTS}) 33 | message(STATUS "Test " ${t}) 34 | add_executable(${t} ${t}.cc) 35 | target_link_libraries(${t} gtest ${EXTRA_LIBS}) 36 | endforeach() 37 | 38 | install(TARGETS ${TESTS} 39 | RUNTIME DESTINATION app/itest) 40 | -------------------------------------------------------------------------------- /itest/ylib/functest.h: -------------------------------------------------------------------------------- 1 | #ifndef __YNFS_IOTEST_H__ 2 | #define __YNFS_IOTEST_H__ 3 | 4 | #define RED "\033[31m" 5 | #define GREEN "\033[32m" 6 | #define NORMAL "\033[0m" 7 | 8 | #define CREATE_DIR_TRUE 1 9 | #define CREATE_DIR_FALSE 0 10 | 11 | void make_test_file(unsigned, const char *); 12 | 13 | void prepare_env(const char *, int); 14 | void write_log(const char *); 15 | 16 | void test_dir(const char *); 17 | void test_mv(const char *); 18 | void test_cp(const char *); 19 | void test_split(const char *); 20 | void test_longname(const char *); 21 | void test_file(const char *); 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /itest/ylib/iotest.h: -------------------------------------------------------------------------------- 1 | #ifndef __IOTEST_H__ 2 | #define __IOTEST_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct _arg { 9 | char *dir; 10 | int number; 11 | int size; 12 | uint64_t total; 13 | } pthread_arg; 14 | 15 | void *thr_fn(void *); 16 | 17 | void write_test(char *, int, int); 18 | void read_test (char *); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /itest/ylib/itest_bitmap.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern "C" { 6 | #include "bmap.h" 7 | } 8 | 9 | #define N 10 10 | 11 | TEST(Bitmap, Bitmap) { 12 | int i; 13 | bmap_t *bmap; 14 | 15 | assert((1<<2) == 4); 16 | assert((1<<3) == 8); 17 | 18 | bmap_create(&bmap, N); 19 | 20 | for (i = 0; i < N; i+=2) { 21 | bmap_set(bmap, i); 22 | } 23 | 24 | for (i = 0; i < N; ++i) { 25 | if (i % 2 == 0) 26 | EXPECT_TRUE(bmap_get(bmap, i)); 27 | else 28 | EXPECT_TRUE(!bmap_get(bmap, i)); 29 | } 30 | 31 | for (i = 0; i < N; ++i) 32 | bmap_del(bmap, i); 33 | 34 | for (i = 0; i < N; i++) { 35 | EXPECT_TRUE(!bmap_get(bmap, i)); 36 | } 37 | 38 | bmap_destroy(&bmap); 39 | } 40 | -------------------------------------------------------------------------------- /itest/ylib/itest_ylib.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "itest_bitmap.cc" 5 | 6 | TEST(TestSuite, testCase1) { 7 | EXPECT_TRUE(1); 8 | } 9 | 10 | TEST(TestSuite, testCase2) { 11 | EXPECT_EQ(1, 1); 12 | EXPECT_TRUE(1); 13 | } 14 | 15 | TEST(TestSuite, testCase3) { 16 | EXPECT_FALSE(0); 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | testing::InitGoogleTest(&argc, argv); 21 | return RUN_ALL_TESTS(); 22 | } 23 | -------------------------------------------------------------------------------- /itest/ylib/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD5_H__ 2 | #define __MD5_H__ 3 | 4 | #include 5 | 6 | typedef unsigned char *POINTER; /* POINTER defines a generic pointer type */ 7 | typedef unsigned short int UINT2; /* UINT2 defines a two byte word */ 8 | typedef unsigned long int UINT4; /* UINT4 defines a four byte word */ 9 | 10 | typedef struct { 11 | UINT4 state[4]; /* state (ABCD) */ 12 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 13 | unsigned char buffer[64]; /* input buffer */ 14 | } MD5_CTX; 15 | 16 | extern void MD5Init (MD5_CTX *context); 17 | extern void MD5Update(MD5_CTX *context, unsigned char *input,unsigned int inputLen); 18 | 19 | extern void MD5Final (unsigned char digest[16], MD5_CTX *context); 20 | 21 | extern char* MDString(char *); 22 | extern char* MDFile(char *); 23 | extern char* hmac_md5(char* text, char* key); 24 | char* MDFile1(char *filename, char *output, uint64_t offset); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /itest/ylib/test_bitmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bmap.h" 5 | 6 | #define N 10 7 | 8 | int main() 9 | { 10 | int i; 11 | bmap_t *bmap; 12 | 13 | assert((1<<2) == 4); 14 | assert((1<<3) == 8); 15 | 16 | bmap_create(&bmap, N); 17 | 18 | for (i = 0; i < N; i+=2) { 19 | bmap_set(bmap, i); 20 | } 21 | 22 | for (i = 0; i < N; ++i) { 23 | if (i % 2 == 0) 24 | assert(bmap_get(bmap, i)); 25 | else 26 | assert(!bmap_get(bmap, i)); 27 | } 28 | 29 | for (i = 0; i < N; ++i) 30 | bmap_del(bmap, i); 31 | 32 | for (i = 0; i < N; i++) { 33 | assert(!bmap_get(bmap, i)); 34 | } 35 | 36 | bmap_destroy(&bmap); 37 | 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /license/include/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef _AES_H_ 2 | #define _AES_H_ 3 | #include 4 | #include 5 | 6 | //add for bug #11160 7 | #define BUF_SIZE_4K (1024 * 4) 8 | 9 | int str2hex(const uint8_t *str, size_t slen, uint8_t *hex, size_t hlen); 10 | int hex2str(const uint8_t *hex, size_t hlen, uint8_t *str, size_t *slen); 11 | int encrypt_aes(unsigned char *plaintext, int plaintext_len, unsigned char *key, 12 | unsigned char *iv, unsigned char *ciphertext); 13 | int decrypt_aes(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, 14 | unsigned char *iv, unsigned char *plaintext); 15 | int decrypt_with_final(unsigned char *ciphertext, int ciphertext_len, unsigned char *key, 16 | unsigned char *iv, unsigned char *plaintext); 17 | #endif 18 | -------------------------------------------------------------------------------- /license/include/license_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef _LICENSE_HELPER_H_ 2 | #define _LICENSE_HELPER_H_ 3 | 4 | #define FREE_LICENSE (60 * 60 * 24 * 30 * 3) 5 | 6 | int is_digit(const char *str); 7 | int is_startwith(const char *string, const char *substr); 8 | int string_split(char *string, const char *delim, unsigned char *outStr); 9 | int strip_newline(char *string); 10 | int get_secret_key(const char *info_file, unsigned char *_secret_key); 11 | int dump_mac(const char *license, unsigned char *secret_key, unsigned char *mac); 12 | int dump_time(const char *license_file, unsigned char *secret_key, time_t *time); 13 | int dump_capacity(const char *license_file, unsigned char *secret_key, 14 | unsigned long *cap); 15 | int uss_get_create_time(time_t *create_time); 16 | int check_mac_valid(const unsigned char *_mac); 17 | int check_time_valid(const time_t due_time); 18 | int check_cap_valid(const unsigned long cap); 19 | int check_license_valid(const char *license_file); 20 | int uss_license_check(const char *home); 21 | #endif 22 | -------------------------------------------------------------------------------- /mds/.gitignore: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | COPYING 3 | ChangeLog 4 | INSTALL 5 | NEWS 6 | README 7 | aclocal.m4 8 | .deps 9 | depcomp 10 | stamp-h1 11 | install-sh 12 | libtool 13 | ltmain.sh 14 | missing 15 | ylwrap 16 | config.h 17 | config.guess 18 | config.log 19 | config.status 20 | config.sub 21 | configure 22 | yfs/Makefile 23 | yfs/build/Makefile 24 | yfs/cds/Makefile 25 | yfs/include/Makefile 26 | yfs/tests/Makefile 27 | yfs/utils/Makefile 28 | yftp/Makefile 29 | yftp/include/Makefile 30 | yftp/src/Makefile 31 | yiscsi/Makefile 32 | yiscsi/include/Makefile 33 | yiscsi/src/Makefile 34 | ylib/Makefile 35 | ylib/include/Makefile 36 | ylib/lib/Makefile 37 | ylib/tests/Makefile 38 | ynet/Makefile 39 | ynet/build/Makefile 40 | ynet/include/Makefile 41 | ynet/tests/Makefile 42 | ynfs/Makefile 43 | *.o 44 | *.lo 45 | *.diff 46 | get_version.h 47 | .libs 48 | *.la 49 | autom4te.cache 50 | cscope.* 51 | lookup.db 52 | Makefile.in 53 | diff.sh 54 | make.sh 55 | *.swp 56 | *.diff 57 | tags 58 | filenametags 59 | GPATH 60 | GRTAGS 61 | GSYMS 62 | GTAGS 63 | gdb 64 | run 65 | .cache_file 66 | *~ 67 | .#* 68 | samba-* 69 | *.h.in 70 | cmd_test 71 | *_test 72 | *.beam 73 | *.so 74 | *.app 75 | Makefile 76 | include/Makefile 77 | mds/Makefile 78 | mds/yfs_mds 79 | 80 | -------------------------------------------------------------------------------- /mds/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /mds/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([yfs-mds],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -W -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -Wall -W -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../yfs/include -I../../ynet/include -I../../ylib/include/" 21 | 22 | LIBS=-lpthread 23 | 24 | AC_CHECK_FUNCS([pthread_rwlock_init]) 25 | 26 | subdirs=" \ 27 | include \ 28 | mds \ 29 | " 30 | 31 | AC_SUBST(subdirs) 32 | 33 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 34 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 35 | 36 | AC_CONFIG_FILES([ \ 37 | Makefile \ 38 | include/Makefile \ 39 | mds/Makefile \ 40 | ]) 41 | 42 | AC_OUTPUT 43 | -------------------------------------------------------------------------------- /mds/docs/arch.txt: -------------------------------------------------------------------------------- 1 | mdp chkget: 2 | 3 | 1, choose mds handler 4 | 5 | *serviceno = hash_str(chkget_req->path) % servicenum; 6 | 7 | 2, choose disk pool 8 | 9 | #if 0 10 | if (mds_info.diskid > (unsigned)dp->group) 11 | grp = chunkid.id % dp->group; 12 | else 13 | grp = (chunkid.id % mds_info.diskid) % dp->group; 14 | #else 15 | if (mds_info.diskid > (unsigned)dp->group) 16 | grp = random() % dp->group; 17 | else 18 | grp = (random() % dp->group) % dp->group; 19 | #endif 20 | 21 | mdp diskjoin: 22 | 23 | 1, choose mds handler 24 | 25 | *serviceno = diskjoin_req->img.diskid.id % servicenum; 26 | 27 | 2, choose disk pool 28 | 29 | grp = diskinfo->diskid.id % dp->group; 30 | -------------------------------------------------------------------------------- /mds/docs/pool.txt: -------------------------------------------------------------------------------- 1 | in mds image file 2 | 3 | file -> chunkid (md ops log) 4 | 5 | in mds mem 6 | 7 | filepool: 8 | 9 | file -> chunkid (skiplist) 10 | del_list (skiplist) 11 | delfile_list (list) 12 | 13 | chunkpool: 14 | 15 | chunkid -> file 16 | 17 | chunkid 18 | -------------------------------------------------------------------------------- /mds/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/mds/include/Makefile.am -------------------------------------------------------------------------------- /mds/include/yfsmds_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFSMDS_CONF_H__ 2 | #define __YFSMDS_CONF_H__ 3 | 4 | #include "yfs_conf.h" 5 | #include "job_tracker.h" 6 | #include "yfscli_conf.h" 7 | 8 | #define MDS_QLEN 256 9 | #define MDS_EPOLL_SIZE 1024 10 | 11 | #define MDS_SHADOW_HOST "mds_shadow" 12 | //#define MDS_SHADOW_SERVICE 10092 13 | #define MDS_SHADOW_QLEN 256 14 | 15 | #define MDS_NODEID_PATHLEVEL 5 16 | 17 | #define MDS_SHADOW_STOPCHECK_INTERVAL 3 18 | 19 | #define YFS_MDS_LOGFILE "/var/log/yfs_mds_%d.log" 20 | 21 | #define YFS_MDS_DIR_DISK_PRE "mond" 22 | #define YFS_MDS_DIR_JNL_PRE "jnl" 23 | #define YFS_MDS_DIR_LVM_PRE "lvm" 24 | #define YFS_MDS_DIR_DEL_PRE "deleted" 25 | 26 | #if 1 27 | /* seems shm doesn't support flock(2) */ 28 | 29 | #define YFS_MDS_DIR_LCK_PRE "/dev/shm/uss/yfs/mds/lock" 30 | #else 31 | #define YFS_MDS_DIR_LCK_PRE "/sysy/yfs/mds/lock" 32 | #endif 33 | 34 | #define YFS_XATTR_REPLICA "replica" 35 | #define YFS_XATTR_CHKLEN "chklen" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /mds/mds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../include 7 | ) 8 | link_directories(${PROJECT_BINARY_DIR}/lib) 9 | 10 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/sbin) 11 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 12 | 13 | set(MOD_EXTRA_LIBS pthread aio crypt uuid ssl parser ylib ynet yfs) 14 | 15 | set(MOD_SRCS 16 | mds_inode.c 17 | namei.c 18 | main.c 19 | mds.c 20 | mds_events.c 21 | mds_state_machine.c 22 | mirror.c 23 | dir.c 24 | disk.c 25 | super.c 26 | chunk.c 27 | img.c 28 | unlink.c 29 | diskpool.c 30 | nodepool.c 31 | lvs.c 32 | scan.c 33 | snapshot.c 34 | mds_newrep1.c) 35 | 36 | add_executable(yfs_mds ${MOD_SRCS}) 37 | target_link_libraries(yfs_mds ${MOD_EXTRA_LIBS}) 38 | 39 | install(TARGETS yfs_mds 40 | RUNTIME DESTINATION app/sbin) 41 | -------------------------------------------------------------------------------- /mds/mds/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS=yfs_mds 2 | 3 | yfs_mds_SOURCES = \ 4 | inode_proto.c \ 5 | mds_inode.c \ 6 | namei.c \ 7 | main.c \ 8 | mds.c \ 9 | mds_events.c \ 10 | mds_state_machine.c \ 11 | mirror.c \ 12 | dir.c \ 13 | disk.c \ 14 | super.c \ 15 | object.c \ 16 | img.c \ 17 | diskpool.c \ 18 | nodepool.c \ 19 | lvs.c \ 20 | namei_cache.c \ 21 | container.c \ 22 | election.c 23 | 24 | AM_LDFLAGS = @LDFLAGS@ \ 25 | -L../../parser/lib -lparser \ 26 | -L../../yfs/build -lyfs \ 27 | -L../../ynet/build -lynet \ 28 | -L../../ylib/lib -lylib \ 29 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl 30 | -------------------------------------------------------------------------------- /mds/mds/disk.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | #define DBG_SUBSYS S_YFSMDS 7 | 8 | #include "chk_proto.h" 9 | #include "disk_proto.h" 10 | #include "diskpool.h" 11 | #include "node_proto.h" 12 | #include "nodepool.h" 13 | #include "sdfs_id.h" 14 | #include "dbg.h" 15 | 16 | int mds_diskdead(const ynet_net_nid_t *nid, uuid_t *nodeid) 17 | { 18 | int ret; 19 | (void) nodeid; 20 | 21 | DBUG("mark peer dead "DISKID_FORMAT"\n", DISKID_ARG(nid)); 22 | 23 | (void) nodepool_diskdead(nid, TIER_ALL); 24 | 25 | ret = diskpool_dead(nid); 26 | if (ret) 27 | goto err_ret; 28 | 29 | return 0; 30 | err_ret: 31 | return ret; 32 | } 33 | -------------------------------------------------------------------------------- /mds/mds/mds.h: -------------------------------------------------------------------------------- 1 | #ifndef __MDS_H__ 2 | #define __MDS_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "diskpool.h" 8 | #include "jnl_proto.h" 9 | #include "nodepool.h" 10 | #include "sdfs_list.h" 11 | #include "ylock.h" 12 | #include "ynet_rpc.h" 13 | #include "yatomic.h" 14 | #include "file_proto.h" 15 | #include "yfs_conf.h" 16 | 17 | enum { 18 | MDS_NULL, 19 | MDS_PRIMARY, /* primary mds */ 20 | MDS_SHADOW, /* shadow mds, rd only, no cds info */ 21 | MDS_SHADOW_FORCE, 22 | }; 23 | 24 | typedef enum { 25 | MDS_SYNC_DONE = 0, 26 | MDS_SYNC_RUNNING, 27 | } mds_sync_status_t; 28 | 29 | typedef struct { 30 | int mds_type; 31 | time_t uptime; 32 | int metano; 33 | 34 | mds_sync_status_t status; 35 | 36 | yatomic_t fileid; 37 | uint64_t diskid_max; 38 | sy_spinlock_t diskid_lock; 39 | 40 | uint32_t version; 41 | 42 | struct disk_pool diskpool; /* diskid -> disk_info */ 43 | struct node_pool nodepool_hdd; /*hdd disk list */ 44 | struct node_pool nodepool_ssd; /*ssd disk list */ 45 | char consistent_leak[MAX_NAME_LEN]; 46 | int (*scan_continue)(); 47 | } mds_info_t; 48 | 49 | extern mds_info_t mds_info; 50 | 51 | int mds_request_table(char *req_buf, uint32_t reqlen, 52 | char *rep_buf, uint32_t *_replen, const nid_t *peer); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /mds/mds/mds_main.h: -------------------------------------------------------------------------------- 1 | #ifndef MDS_MAIN_H 2 | #define MDS_MAIN_H 3 | 4 | 5 | #include "configure.h" 6 | #include "net_global.h" 7 | #include "job_dock.h" 8 | #include "get_version.h" 9 | #include "ylib.h" 10 | #include "yfsmds_conf.h" 11 | #include "sdfs_lib.h" 12 | #include "ylog.h" 13 | #include "mds.h" 14 | #include "md_lib.h" 15 | #include "dbg.h" 16 | #include "fnotify.h" 17 | #include "sdfs_quota.h" 18 | #include "flock.h" 19 | 20 | typedef enum { 21 | ELECTION_NORMAL, 22 | ELECTION_INIT, 23 | ELECTION_SYNC, 24 | ELECTION_MASTER, 25 | } election_type_t; 26 | 27 | typedef struct { 28 | int daemon; 29 | int metano; 30 | election_type_t type; 31 | } mds_args_t; 32 | 33 | void mds_monitor_handler(int sig); 34 | void mds_signal_handler(int sig); 35 | int mds_primary(); 36 | int mds_init(const char *home, int metano); 37 | int mds_run(void *args); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /mds/todo: -------------------------------------------------------------------------------- 1 | mds/mem.c :: mem_diskjoin() mem_diskhb() 2 | -------------------------------------------------------------------------------- /metadata/dir.h: -------------------------------------------------------------------------------- 1 | #ifndef __DIR_H__ 2 | #define __DIR_H__ 3 | 4 | #include "md_proto.h" 5 | #include "file_proto.h" 6 | #include "sdfs_lib.h" 7 | 8 | #pragma pack(8) 9 | 10 | typedef struct { 11 | fileid_t fileid; 12 | //uint32_t d_off; 13 | //uint16_t d_reclen; 14 | uint16_t d_type; 15 | } dir_entry_t; 16 | 17 | #pragma pack() 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /metadata/md.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD_H__ 2 | #define __MD_H__ 3 | 4 | 5 | #include "md_attr.h" 6 | 7 | 8 | int md_newid(fidtype_t type, uint64_t *id); 9 | int md_init(); 10 | 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /metadata/md_attr.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD_ATTR_H__ 2 | #define __MD_ATTR_H__ 3 | 4 | #include "sdfs_lib.h" 5 | #include "yfs_md.h" 6 | 7 | #if 0 8 | #define MODE_MAX 01777 9 | #else 10 | #define MODE_MAX 07777 11 | #endif 12 | 13 | 14 | typedef enum { 15 | idtype_nid = 0, 16 | idtype_fileid = 1, 17 | idtype_max = 3, 18 | } fidtype_t; 19 | 20 | void setattr_init(setattr_t *setattr, uint32_t mode, 21 | int replica, const ec_t *ec, int uid, int gid, size_t size); 22 | void setattr_update_time(setattr_t *setattr, 23 | __time_how ahow, 24 | const struct timespec *atime, 25 | __time_how mhow, 26 | const struct timespec *mtime, 27 | __time_how chow, 28 | const struct timespec *ctime); 29 | 30 | void md_attr_inherit(md_proto_t *md, const md_proto_t *parent, const ec_t *ec, uint32_t mode); 31 | int md_attr_getid(fileid_t *fileid, const fileid_t *parent, uint32_t type, const volid_t *volid); 32 | int md_attr_init(md_proto_t *md, const setattr_t *setattr, uint32_t type, 33 | const md_proto_t *parent, const fileid_t *fileid); 34 | void md_attr_update(md_proto_t *md, const setattr_t *setattr); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /metadata/md_root.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD_ROOT_H__ 2 | #define __MD_ROOT_H__ 3 | 4 | 5 | typedef enum { 6 | roottype_user, 7 | roottype_group, 8 | roottype_share, 9 | roottype_quota, 10 | roottype_max, 11 | } root_type_t; 12 | 13 | 14 | const fileid_t *md_root_getid(root_type_t type); 15 | #if 0 16 | int md_root_isroot(const fileid_t *fileid); 17 | #endif 18 | int md_root_init(); 19 | int md_root_create(uint64_t volid); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /metadata/quota.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUOTA_H_ 2 | #define _QUOTA_H_ 3 | 4 | #include "sdfs_quota.h" 5 | #include "md_attr.h" 6 | 7 | // functions 8 | #if 0 9 | extern int quota_inode_check_and_inc(const fileid_t *quotaid, const uid_t uid, const gid_t gid, const fileid_t *fileid); 10 | extern int quota_space_check_and_inc(const fileid_t *quotaid, const uid_t uid, const gid_t gid, const fileid_t *fileid, const uint64_t space); 11 | extern int quota_inode_dec(const fileid_t *quotaid, const uid_t uid, const gid_t gid, const fileid_t *lvmid); 12 | extern int quota_space_dec(const fileid_t *quotaid, const uid_t uid, const gid_t gid, const fileid_t *lvmid, const uint64_t space); 13 | 14 | extern int quota_chown(const fileid_t *fileid, uid_t new_uid, gid_t new_gid); 15 | extern void quota_removeall(const fileid_t *dirid, const fileid_t *quotaid); 16 | #endif 17 | 18 | extern int quota_check_dec(const fileid_t *fileid); 19 | extern int quota_inode_increase(const fileid_t *fileid, const setattr_t *setattr); 20 | extern int quota_inode_decrease(const fileid_t *fileid, const setattr_t *setattr); 21 | extern int quota_space_increase(const fileid_t *fileid, uid_t uid, gid_t gid, uint64_t space); 22 | extern int quota_space_decrease(const fileid_t *fileid, uid_t uid, gid_t gid, uint64_t space); 23 | 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /metadata/redis_co.h: -------------------------------------------------------------------------------- 1 | #ifndef __REDIS_CO__ 2 | #define __REDIS_CO__ 3 | 4 | int redis_co_init(int polling); 5 | int redis_co_destroy(); 6 | int redis_co_run(void *ctx); 7 | int co_hget(const volid_t *volid, const fileid_t *fileid, const char *key, 8 | void *buf, size_t *len); 9 | int co_hset(const volid_t *volid, const fileid_t *fileid, const char *key, 10 | const void *value, size_t size, int flag); 11 | int co_hdel(const volid_t *volid, const fileid_t *fileid, const char *key); 12 | int co_hlen(const volid_t *volid, const fileid_t *fileid, uint64_t *count); 13 | int co_kget(const volid_t *volid, const fileid_t *fileid, void *buf, size_t *len); 14 | int co_kset(const volid_t *volid, const fileid_t *fileid, const void *value, 15 | size_t size, int flag, int _ttl); 16 | int co_kdel(const volid_t *volid, const fileid_t *fileid); 17 | int co_klock(const volid_t *volid, const fileid_t *fileid, int ttl, int block); 18 | int co_kunlock(const volid_t *volid, const fileid_t *fileid); 19 | int co_newsharing(const volid_t *volid, uint8_t *idx); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /metadata/redis_pipeline.h: -------------------------------------------------------------------------------- 1 | #ifndef __REDIS_PIPELINE__ 2 | #define __REDIS_PIPELINE__ 3 | 4 | int redis_pipeline_init(); 5 | int pipeline_hget(const volid_t *volid, const fileid_t *fileid, const char *key, void *buf, size_t *len); 6 | int pipeline_hset(const volid_t *volid, const fileid_t *fileid, const char *key, const void *value, size_t size, int flag); 7 | int pipeline_hdel(const volid_t *volid, const fileid_t *fileid, const char *key); 8 | int pipeline_hlen(const volid_t *volid, const fileid_t *fileid, uint64_t *count); 9 | int pipeline_kget(const volid_t *volid, const fileid_t *fileid, void *buf, size_t *len); 10 | int pipeline_kset(const volid_t *volid, const fileid_t *fileid, const void *value, 11 | size_t size, int flag, int _ttl); 12 | int pipeline_kdel(const volid_t *volid, const fileid_t *fileid); 13 | int pipeline_klock(const volid_t *volid, const fileid_t *fileid, int ttl, int block); 14 | int pipeline_kunlock(const volid_t *volid, const fileid_t *fileid); 15 | #endif 16 | -------------------------------------------------------------------------------- /mond/mond_kv.h: -------------------------------------------------------------------------------- 1 | #ifndef __MOND_KV_H__ 2 | #define __MOND_KV_H__ 3 | 4 | #include 5 | 6 | #include "disk_proto.h" 7 | #include "md_proto.h" 8 | 9 | int mond_kv_init(); 10 | int mond_kv_set(const char *key, const void *value, uint32_t valuelen); 11 | int mond_kv_get(const char *key, int offset, void *entry, uint32_t *valuelen); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /mond/mond_rpc.h: -------------------------------------------------------------------------------- 1 | #ifndef __MOND_RPC_H__ 2 | #define __MOND_RPC_H__ 3 | 4 | #include 5 | 6 | #include "disk_proto.h" 7 | #include "md_proto.h" 8 | 9 | typedef struct { 10 | nid_t nid; 11 | int online; 12 | } instat_t; 13 | 14 | typedef struct { 15 | int klen; 16 | int vlen; 17 | unsigned char type; 18 | unsigned char eof; 19 | uint64_t offset; 20 | char buf[0]; 21 | } mon_entry_t; 22 | 23 | 24 | #define MON_ENTRY_MAX (64 * 1024) 25 | 26 | int mond_rpc_init(); 27 | int mond_rpc_getstat(const nid_t *nid, instat_t *instat); 28 | int mond_rpc_diskhb(const nid_t *nid, int tier, const uuid_t *uuid, 29 | const diskinfo_stat_diff_t *diff, 30 | const volinfo_t *volinfo); 31 | int mond_rpc_statvfs(const nid_t *nid, const fileid_t *fileid, struct statvfs *stbuf); 32 | int mond_rpc_diskjoin(const nid_t *nid, uint32_t tier, const uuid_t *uuid, 33 | const diskinfo_stat_t *stat); 34 | int mond_rpc_newdisk(const nid_t *nid, uint32_t tier, uint32_t repnum, 35 | uint32_t hardend, diskid_t *disks); 36 | int mond_rpc_null(const nid_t *mond); 37 | int mond_rpc_set(const nid_t *nid, const char *path, const char *value, uint32_t valuelen); 38 | int mond_rpc_get(const nid_t *nid, const char *path, uint64_t offset, void *value, int *valuelen); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /nfs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | ${PROJECT_SOURCE_DIR}/ynfs/include 7 | ) 8 | link_directories(${PROJECT_BINARY_DIR}/lib /sysy/yfs/app/lib) 9 | 10 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/sbin) 11 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 12 | 13 | set(MOD_EXTRA_LIBS pthread aio crypt uuid ssl parser ylib ynet yfs) 14 | 15 | set(MOD_SRCS 16 | main.c 17 | attr.c 18 | error.c 19 | readdir.c 20 | nfs_events.c 21 | mountlist.c 22 | nfs_state_machine.c 23 | xdr_nfs.c 24 | nfs_proc.c) 25 | 26 | add_executable(ynfs_server ${MOD_SRCS}) 27 | target_link_libraries(ynfs_server ${MOD_EXTRA_LIBS}) 28 | 29 | install(TARGETS ynfs_server 30 | RUNTIME DESTINATION app/sbin) 31 | 32 | -------------------------------------------------------------------------------- /nfs/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS=ynfs_server\ 2 | nlm_server 3 | 4 | ynfs_server_SOURCES = \ 5 | attr.c \ 6 | error.c \ 7 | readdir.c \ 8 | nfs_events.c \ 9 | mountlist.c \ 10 | nfs_state_machine.c \ 11 | xdr_nfs.c \ 12 | nfs_proc.c \ 13 | main.c 14 | nlm_server_SOURCES = \ 15 | nlm_events.c\ 16 | nlm_state_machine.c\ 17 | xdr_nlm.c\ 18 | nlm_lkcache.c\ 19 | nlm_nsm.c\ 20 | hostcache.c\ 21 | mini_nlm.c 22 | 23 | AM_LDFLAGS = @LDFLAGS@ \ 24 | -L../../parser/lib -lparser \ 25 | -L../../yfs/build -lyfs \ 26 | -L../../ynet/build -lynet \ 27 | -L../../ylib/lib -lylib \ 28 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl 29 | -------------------------------------------------------------------------------- /nfs/attr.h: -------------------------------------------------------------------------------- 1 | #ifndef _YNFS_ATTR_H__ 2 | #define _YNFS_ATTR_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "nfs3.h" 10 | #include "file_proto.h" 11 | 12 | extern int get_postopattr(uint32_t dev, uint64_t ino, const char *path, 13 | post_op_attr *attr); 14 | extern int get_preopattr(uint32_t dev, uint64_t ino, mode_t mode, 15 | preop_attr *attr); 16 | extern int sattr_tomode(mode_t *, sattr *); 17 | extern int get_postopattr_stat(post_op_attr *, struct stat *); 18 | 19 | int sattr_utime(const fileid_t *fileid, int at, int mt, int ct); 20 | int sattr_set(const fileid_t *fileid, const sattr *attr, const nfs3_time *ctime); 21 | void get_preopattr1(const fileid_t *fileid, preop_attr *attr); 22 | void get_postopattr1(const fileid_t *fileid, post_op_attr *attr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nfs/error.h: -------------------------------------------------------------------------------- 1 | #ifndef __YNFS_ERROR_H__ 2 | #define __YNFS_ERROR_H__ 3 | 4 | #include "nfs3.h" 5 | 6 | extern nfs3_stat lookup_err(int syserr); 7 | extern nfs3_stat rename_err(int syserr); 8 | extern nfs3_stat read_err(int syserr); 9 | extern nfs3_stat write_err(int syserr); 10 | extern nfs3_stat create_err(int syserr); 11 | extern nfs3_stat mkdir_err(int syserr); 12 | extern nfs3_stat remove_err(int syserr); 13 | extern nfs3_stat rmdir_err(int syserr); 14 | extern nfs3_stat readdir_err(int syserr); 15 | extern nfs3_stat setattr_err(int syserr); 16 | extern nfs3_stat symlink_err(int syserr); 17 | extern nfs3_stat mknod_err(int syserr); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /nfs/hostcache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: hostcache.h 5 | * 6 | * Description: 7 | * 8 | * Version: 1.0 9 | * Created: 04/11/2011 05:51:58 PM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: YOUR NAME (), 14 | * Company: 15 | * 16 | * ===================================================================================== 17 | */ 18 | #ifndef HOST_CACHE_H_ 19 | #define HOST_CACHE_H_ 20 | #include "sdfs_lib.h" 21 | #include "ylib.h" 22 | #include "dbg.h" 23 | 24 | typedef struct hostentry_s { 25 | char *nm; 26 | int len; 27 | int lkn; 28 | } hostentry_t; 29 | 30 | typedef struct hostcache_s { 31 | hashtable_t hashtb; 32 | } hostcache_t; 33 | 34 | extern hostcache_t hostcache; 35 | 36 | int hostcache_compare(const void *d1, const void *d2); 37 | uint32_t hostcache_hash(const void *d1); 38 | int hostcache_init(hostcache_t *hostcache); 39 | int hostcache_insert(hostcache_t *hostcache, hostentry_t *ent); 40 | int hostcache_delete(hostcache_t *hostcache, hostentry_t *ent, hostentry_t **retval); 41 | void hostcache_find(hostcache_t *hostcache, hostentry_t *ent, hostentry_t **retval); 42 | int hostentry_destroy(hostentry_t *entry); 43 | #endif 44 | -------------------------------------------------------------------------------- /nfs/nfs_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __NFS_CONF_H__ 2 | #define __NFS_CONF_H__ 3 | 4 | #include "sdfs_conf.h" 5 | #include "yfscli_conf.h" 6 | 7 | typedef enum { 8 | ACCEPT_STATE_OK, /* 0 */ 9 | ACCEPT_STATE_ERROR, /* 1 */ 10 | } acceptstate_t; 11 | 12 | #define NFS_PATHLEN_MAX MAX_PATH_LEN 13 | 14 | #define FH_CACHE_MAX_ENTRY (NR_FILETABLE * 2) 15 | #define STAT_CACHE_MAX_ENTRY (NR_FILETABLE / 4) 16 | #define FD_CACHE_MAX_ENTRY (NR_FILETABLE / 2) 17 | 18 | //need by yproc 19 | #define YNFS_STATE "ynfs" 20 | 21 | // stat cache timeout 22 | #define STAT_CACHE_EXPIRE EXPIRED_TIME 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nfs/nfs_events.h: -------------------------------------------------------------------------------- 1 | #ifndef __NFS_EVENTS_H__ 2 | #define __NFS_EVENTS_H__ 3 | 4 | 5 | 6 | 7 | 8 | #include "job.h" 9 | #include "nfs_args.h" 10 | #include "sunrpc_proto.h" 11 | 12 | typedef int (*hash_args_t)(void*); 13 | 14 | extern int mnt_event_handler(job_t *); 15 | extern int nfs_event_handler(job_t *); 16 | extern int acl_event_handler(job_t *); 17 | 18 | typedef int (*nfs_handler)(const sockid_t *sockid, const sunrpc_request_t *req, 19 | uid_t uid, gid_t gid, nfsarg_t *arg, buffer_t *buf); 20 | 21 | extern int nfs_mount(const sockid_t *sockid, const sunrpc_request_t *req, 22 | uid_t uid, gid_t gid, buffer_t *buf); 23 | extern int nfs_ver3(const sockid_t *sockid, const sunrpc_request_t *req, 24 | uid_t uid, gid_t gid, buffer_t *buf); 25 | extern int nfs_nlm4(const sockid_t *sockid, const sunrpc_request_t *req, 26 | uid_t uid, gid_t gid, buffer_t *buf); 27 | 28 | 29 | void nfs_newtask(const sockid_t *sockid, const sunrpc_request_t *req, 30 | uid_t uid, gid_t gid, buffer_t *buf); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /nfs/nlm_async.h: -------------------------------------------------------------------------------- 1 | #ifndef __NLM4_ASYNC_H__ 2 | #define __NLM4_ASYNC_H__ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | #define DBG_SUBSYS S_YNFS 20 | 21 | #include "yfs_conf.h" 22 | #include "ylib.h" 23 | #include "sdfs_lib.h" 24 | 25 | typedef struct { 26 | int uppid; 27 | int ownerlen; 28 | int callerlen; 29 | char buf[0]; 30 | } nlm_ext_t; 31 | 32 | #define MAX_LOCK_LEN (sizeof(sdfs_lock_t) + sizeof(nlm_ext_t) + 2048) 33 | 34 | int nlm4_async_init(); 35 | int nlm4_async_unreg(const fileid_t *fileid, const sdfs_lock_t *lock); 36 | int nlm4_async_reg(const fileid_t *fileid, const sdfs_lock_t *lock); 37 | int nlm4_async_canceled(const fileid_t *fileid, const sdfs_lock_t *lock); 38 | int nlm4_async_cancel(const fileid_t *fileid, const sdfs_lock_t *lock); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /nfs/nlm_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: nlm_events.h 5 | * 6 | * Description: 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/2011 10:22:12 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: YOUR NAME (), 14 | * Company: 15 | * 16 | * ===================================================================================== 17 | */ 18 | #ifndef __NLM_EVENTS_H__ 19 | #define __NLM_EVENTS_H__ 20 | 21 | 22 | #include "job.h" 23 | extern int nlm_event_handler(job_t *); 24 | #endif 25 | -------------------------------------------------------------------------------- /nfs/nlm_job_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ===================================================================================== 3 | * 4 | * Filename: nlm_job_context.h 5 | * 6 | * Description: 7 | * 8 | * Version: 1.0 9 | * Created: 04/07/2011 10:39:10 AM 10 | * Revision: none 11 | * Compiler: gcc 12 | * 13 | * Author: YOUR NAME (), 14 | * Company: 15 | * 16 | * ===================================================================================== 17 | */ 18 | #ifndef __NLM_JOB_CONTEXT_H__ 19 | #define __NLM_JOB_CONTEXT_H__ 20 | 21 | 22 | #include "xdr_nlm.h" 23 | 24 | #include "sdfs_buffer.h" 25 | #include "file_proto.h" 26 | 27 | typedef union { 28 | nlm_lockargs lockargs; 29 | nlm_cancargs cancargs; 30 | nlm_testargs testargs; 31 | nlm_unlockargs unlockargs; 32 | nlm_notifyargs notifyargs; 33 | } arg_t; 34 | 35 | typedef union { 36 | nlm_res res; 37 | nlm_testres testres; 38 | } ret_t; 39 | 40 | typedef struct { 41 | arg_t arg; 42 | int eof; /*read eof*/ 43 | fileid_t fileid; 44 | buffer_t buf; 45 | } nlm_job_context_t; 46 | 47 | /*************new struct************/ 48 | #endif 49 | -------------------------------------------------------------------------------- /nfs/readdir.h: -------------------------------------------------------------------------------- 1 | #ifndef __READ_DIR_H__ 2 | #define __READ_DIR_H__ 3 | 4 | #include 5 | 6 | #include "attr.h" 7 | #include "sdfs_lib.h" 8 | #include "nfs3.h" 9 | 10 | #define MAX_ENTRIES MAX_READDIR_ENTRIES 11 | #define MAX_DIRPLUS_ENTRIES MAX_READDIR_ENTRIES 12 | 13 | int read_dir(sdfs_ctx_t *ctx, const fileid_t *fileid, uint64_t offset, char *verf, 14 | uint32_t count, readdir_ret *res, entry *entrys, 15 | char *obj); 16 | 17 | int readdirplus(sdfs_ctx_t *ctx, const fileid_t *fileid, uint64_t offset, char *verf, 18 | uint32_t count, readdirplus_ret *res, entryplus *_entryplus, 19 | char *obj, fileid_t *fharray); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /nfs/session.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define DBG_SUBSYS S_YNFS 6 | 7 | #include "adt.h" 8 | #include "error.h" 9 | #include "readdir.h" 10 | #include "nfs_conf.h" 11 | #include "ylib.h" 12 | #include "sdfs_lib.h" 13 | #include "network.h" 14 | #include "yfs_md.h" 15 | #include "dbg.h" 16 | 17 | typedef struct { 18 | int fd; 19 | uint32_t sessid; 20 | volid_t volid; 21 | char path[MAX_PATH_LEN]; 22 | char host[MAX_PATH_LEN]; 23 | } nfs_session_t; 24 | 25 | int nfs_session_create(int fd, const char *path, const char *host, uint32_t *sessid) 26 | { 27 | 28 | } 29 | 30 | int nfs_session_destroy(int fd, const char *path) 31 | { 32 | 33 | } 34 | 35 | int nfs_session_get(int fd, int sessid, volid_t *volid) 36 | { 37 | 38 | } 39 | 40 | int nfs_session_init() 41 | { 42 | } 43 | -------------------------------------------------------------------------------- /parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(lib) 2 | 3 | -------------------------------------------------------------------------------- /parser/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /parser/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([parser],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_YACC 8 | AM_PROG_LEX 9 | AC_PROG_LIBTOOL 10 | AC_PROG_INSTALL 11 | 12 | AM_MAINTAINER_MODE([enable]) 13 | 14 | case $target_os in 15 | *linux*) arch=linux;; 16 | *bsd*) arch=bsd;; 17 | *) arch=unknown;; 18 | esac 19 | 20 | if test "$ac_env_CFLAGS_set" != set; then 21 | CFLAGS="-Wall -W -g" 22 | fi 23 | 24 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../ylib/include/" 25 | 26 | LIBS="-lpthread" 27 | 28 | AC_CHECK_FUNCS([pthread_rwlock_init]) 29 | 30 | subdirs=" \ 31 | include \ 32 | lib \ 33 | " 34 | 35 | AC_SUBST(subdirs) 36 | 37 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 38 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 39 | 40 | AC_CONFIG_FILES([ \ 41 | Makefile \ 42 | include/Makefile \ 43 | lib/Makefile 44 | ]) 45 | 46 | AC_OUTPUT 47 | -------------------------------------------------------------------------------- /parser/include/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = \ 2 | README* 3 | -------------------------------------------------------------------------------- /parser/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(FLEX) 2 | find_package(BISON) 3 | 4 | include_directories( 5 | ${PROJECT_SOURCE_DIR}/parser/include 6 | ${PROJECT_SOURCE_DIR}/ylib/include 7 | ) 8 | 9 | message(STATUS "CMAKE_CURRENT_SOURCE_DIR" ${CMAKE_CURRENT_SOURCE_DIR}) 10 | message(STATUS "CMAKE_CURRENT_BINARY_DIR" ${CMAKE_CURRENT_BINARY_DIR}) 11 | 12 | add_custom_command( 13 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/confl.c 14 | COMMAND flex -o${CMAKE_CURRENT_SOURCE_DIR}/confl.c ${CMAKE_CURRENT_SOURCE_DIR}/confl.l 15 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/confl.l 16 | ) 17 | 18 | add_custom_command( 19 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/confy.c ${CMAKE_CURRENT_SOURCE_DIR}/confy.h 20 | COMMAND bison -o ${CMAKE_CURRENT_SOURCE_DIR}/confy.c ${CMAKE_CURRENT_SOURCE_DIR}/confy.y 21 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/confy.y 22 | ) 23 | 24 | set(MOD_SRCS 25 | confl.c 26 | confy.c 27 | configure.c) 28 | 29 | # add_library(parser ${MOD_SRCS}) 30 | 31 | add_library(parser ${MOD_SRCS}) 32 | set_target_properties(parser PROPERTIES OUTPUT_NAME "parser") 33 | set_target_properties(parser PROPERTIES VERSION 1.0 SOVERSION 1) 34 | 35 | install(TARGETS parser 36 | ARCHIVE DESTINATION app/lib 37 | LIBRARY DESTINATION app/lib 38 | RUNTIME DESTINATION app/sbin 39 | ) 40 | -------------------------------------------------------------------------------- /parser/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libparser.la 2 | 3 | BUILT_SOURCES = confl.c confy.c confy.h 4 | 5 | libparser_la_SOURCES = \ 6 | confl.l \ 7 | confy.y \ 8 | configure.c 9 | 10 | AM_YFLAGS = -d 11 | 12 | clean-local: 13 | -rm -f confl.c confy.c confy.h 14 | 15 | -------------------------------------------------------------------------------- /schedule/corenet_connect.h: -------------------------------------------------------------------------------- 1 | #ifndef __CORENET_CONNECT_H__ 2 | #define __CORENET_CONNECT_H__ 3 | 4 | 5 | int corenet_tcp_connect(const nid_t *nid, uint32_t addr, uint32_t port, sockid_t *sockid); 6 | int corenet_tcp_passive(); 7 | int corenet_tcp_getinfo(char *infobuf, uint32_t *infobuflen); 8 | 9 | #if ENABLE_RDMA 10 | int corenet_rdma_connect(const nid_t *nid, uint32_t addr, sockid_t *sockid); 11 | int corenet_rdma_passive(); 12 | #endif 13 | /** @file 不同节点上多个core间的RPC. 14 | * 15 | * CORE地址: 16 | * 17 | * 本地缓存了CORE地址到sockid的映射关系。 18 | * 19 | * 如需要支持跨集群,还需把集群ID编入CORE地址。 20 | */ 21 | 22 | #if 0 23 | int corenet_connect_host(const char *host, sockid_t *sockid); 24 | #endif 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /schedule/corenet_maping.h: -------------------------------------------------------------------------------- 1 | #ifndef __CORENET_MAPING_H__ 2 | #define __CORENET_MAPING_H__ 3 | 4 | #include "core.h" 5 | 6 | #define CORENET_DEV_MAX 10 7 | 8 | typedef struct { 9 | nid_t nid; 10 | int count; 11 | int cur; 12 | sockid_t sockid[CORENET_DEV_MAX]; 13 | sy_spinlock_t lock; 14 | struct list_head list; 15 | char loading; 16 | } corenet_maping_t; 17 | 18 | int corenet_maping_init(corenet_maping_t **_maping); 19 | int corenet_maping(void *ctx, const nid_t *nid, sockid_t *sockid); 20 | int corenet_maping_loading(const nid_t *nid); 21 | int corenet_maping_accept(core_t *core, const nid_t *nid, const sockid_t *sockid, int count); 22 | void corenet_maping_close(const nid_t *nid, const sockid_t *sockid); 23 | void corenet_maping_check(const ynet_net_info_t *info); 24 | void corenet_maping_destroy(corenet_maping_t **maping); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /schedule/coroutine.c: -------------------------------------------------------------------------------- 1 | #include "coroutine.h" 2 | #include "functools.h" 3 | 4 | 5 | int co_worker_init(co_worker_t **worker, squeue_cmp_func cmp_func) 6 | { 7 | int ret; 8 | co_worker_t *_worker; 9 | 10 | *worker = NULL; 11 | 12 | ret = ymalloc((void **)&_worker, sizeof(co_worker_t)); 13 | if (unlikely(ret)) 14 | GOTO(err_ret, ret); 15 | 16 | ret = sy_spin_init(&_worker->lock); 17 | if (unlikely(ret)) 18 | GOTO(err_free, ret); 19 | 20 | ret = squeue_init(&_worker->queue, 1024, cmp_func, chkid_hash_func); 21 | if (unlikely(ret)) 22 | GOTO(err_ret, ret); 23 | 24 | *worker = _worker; 25 | return 0; 26 | err_free: 27 | yfree((void **)&worker); 28 | err_ret: 29 | return ret; 30 | 31 | } 32 | 33 | #if 0 34 | int co_worker_destroy(co_worker_t *worker) 35 | { 36 | // TODO 37 | return 0; 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /schedule/cpuset.h: -------------------------------------------------------------------------------- 1 | #ifndef __CPUSET_H__ 2 | #define __CPUSET_H__ 3 | 4 | #define MAX_CPU_COUNT 256 5 | 6 | typedef struct { 7 | int cpu_id; 8 | int core_id; 9 | int node_id; ///< NUMA node id 10 | int physical_package_id; ///< socket 11 | int used; 12 | int lockfd; 13 | } coreinfo_t; 14 | 15 | 16 | int cpuset_init(); 17 | 18 | int get_cpunode_count(); 19 | 20 | int cpuset_useable(); 21 | void cpuset_getcpu(coreinfo_t **master, int *slave); 22 | int cpuset(const char *name, int cpu); 23 | void cpuset_unset(int cpu); 24 | 25 | 26 | void cpuset_getcpu_by_physical_id(int *master, int *slave, int physical_package_id); 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /schedule/schedule_thread.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCHEDULE_THREAD__ 2 | #define __SCHEDULE_THREAD__ 3 | 4 | 5 | #define __SCHE_THREAD_MAX__ 64 6 | 7 | typedef enum { 8 | SCHE_THREAD_MISC, 9 | SCHE_THREAD_ETCD, 10 | SCHE_THREAD_REDIS, 11 | SCHE_THREAD_REPLICA, 12 | SCHE_THREAD_MAX, 13 | } sche_thread_type_t; 14 | 15 | struct sche_thread_ops { 16 | sche_thread_type_t type; 17 | int off; 18 | int size; 19 | 20 | void (*begin_trans)(int idx); 21 | void (*commit_trans)(int idx); 22 | }; 23 | 24 | /* for sche_thread_ops_register */ 25 | extern int disk_maping_register(); 26 | extern int etcd_ops_register(); 27 | 28 | int sche_thread_ops_register(struct sche_thread_ops *hook, int type, int size); 29 | struct sche_thread_ops *sche_thread_ops_get(int type); 30 | 31 | int schedule_thread_init(); 32 | int schedule_newthread(sche_thread_type_t type, const int hash, int trans, 33 | const char *name, int timeout, func_va_t exec, ...); 34 | 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /schedule/spdk.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPDK_H_ 2 | #define __SPDK_H_ 3 | 4 | #ifdef SPDK 5 | 6 | #include "sdfs_buffer.h" 7 | 8 | sem_t spdk_launch_sem; 9 | 10 | typedef struct sgl_element { 11 | void *sgl_base; 12 | size_t sgl_len; 13 | uint64_t phyaddr; 14 | size_t offset; 15 | }sgl_element_t; 16 | 17 | void *lookup_spdk_nvme_controller(int bus, int domain, int dev, int func); 18 | void spdk_nvme_disk_size(void *ctrlr, uint64_t *disk_size); 19 | int spdk_pwrite(void *ctrlr, sgl_element_t *sgl,off_t offset); 20 | int spdk_pread(void *ctrlr, sgl_element_t *sgl,off_t offset); 21 | int spdk_pwritev(void *ctrlr, sgl_element_t *sgl, int sgl_count, size_t size, off_t offset); 22 | int spdk_preadv(void *ctrlr, sgl_element_t *sgl, int sgl_count, size_t size, off_t offset); 23 | int spdk_aio_preadv(void *ctrlr, sgl_element_t *sgl, int sgl_count, size_t size, off_t offset); 24 | int spdk_aio_pwritev(void *ctrlr, sgl_element_t *sgl, int sgl_count, size_t size, off_t offset); 25 | void spdk_aio_polling(void); 26 | int spdk_init(void **arg, char *cpu_mask_str,void *work_fn(void *_arg)); 27 | 28 | #endif //SPDK 29 | 30 | #endif //__SPDK_H_ 31 | 32 | -------------------------------------------------------------------------------- /schedule/spdk_extra.h: -------------------------------------------------------------------------------- 1 | #ifndef SPDK_EXTRA_H 2 | #define SPDK_EXTRA_H 3 | 4 | #include "sdfs_buffer.h" 5 | #include "spdk.h" 6 | #include "schedule.h" 7 | 8 | #if PERFORMANCE_ANALYSIS 9 | struct spdk_performan_ayalysis_t { 10 | uint64_t incomplete_io_count; 11 | uint64_t io_max; 12 | uint64_t io_avg_time; 13 | 14 | uint64_t total_complete_write_io; 15 | uint64_t total_complete_read_io; 16 | uint64_t total_io_request; 17 | uint64_t total_io_time; 18 | uint64_t max_io_time; 19 | char disk_name[128]; 20 | int io_type; 21 | }; 22 | 23 | int get_spdk_io_count(struct spdk_performan_ayalysis_t *spa); 24 | #endif 25 | 26 | typedef enum { 27 | PREAD = 0x01, 28 | PWRITE, 29 | PREADV, 30 | PWRITEV, 31 | }io_type_t; 32 | 33 | struct non_aligned_io_handle_t { 34 | sem_t sem; 35 | sy_spinlock_t lock; 36 | struct list_head io_list; 37 | }; 38 | extern struct non_aligned_io_handle_t handle_io; 39 | 40 | struct non_aligned_io_t { 41 | struct list_head hook; 42 | io_type_t type; 43 | void *fd; 44 | size_t size; 45 | size_t offset; 46 | sgl_element_t *sgl; 47 | int sgl_count; 48 | task_t schedule_task; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /schedule/uss_aio.h: -------------------------------------------------------------------------------- 1 | #ifndef __LICH_AIO__ 2 | #define __LICH_AIO__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int aio_getevent(); 10 | void aio_submit(); 11 | int aio_commit(struct iocb *iocb, int prio); 12 | int aio_create(const char *name, int cpu, int *_eventfd); 13 | void aio_destroy(); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /schedule/variable.h: -------------------------------------------------------------------------------- 1 | #ifndef __VARIABLE_H__ 2 | #define __VARIABLE_H__ 3 | 4 | typedef enum { 5 | VARIABLE_MAPING, 6 | VARIABLE_MEMCACHE, 7 | VARIABLE_HUGEPAGE, 8 | VARIABLE_CORENET_TCP, 9 | VARIABLE_CORENET_RDMA, 10 | VARIABLE_CORERPC, 11 | VARIABLE_CORE, 12 | VARIABLE_SCHEDULE, 13 | VARIABLE_AIO, 14 | VARIABLE_CLOCK, 15 | VARIABLE_TIMER, 16 | VARIABLE_GETTIME, 17 | VARIABLE_REDIS, 18 | VARIABLE_ANALYSIS, 19 | VARIABLE_ATTR_QUEUE, 20 | VARIABLE_MAX, 21 | } variable_type_t; 22 | 23 | int variable_init(); 24 | void variable_exit(); 25 | 26 | void * IO_FUNC variable_get(variable_type_t type); 27 | void variable_set(variable_type_t type, void *variable); 28 | void variable_unset(variable_type_t type); 29 | 30 | int variable_newthread(); 31 | int variable_thread(); 32 | void * IO_FUNC variable_get_byctx(void *ctx, int type); 33 | void * IO_FUNC variable_get_ctx(); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /scripts/Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | ./install.sh -i 3 | 4 | uninstall: 5 | ./install.sh -e 6 | -------------------------------------------------------------------------------- /scripts/gen_sshkey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SSHKEY_FILE="/root/.ssh/id_dsa" 4 | 5 | if [ "`whoami`" = "root" ];then 6 | ssh-keygen -t dsa -P '' -f $SSHKEY_FILE 7 | echo "public ssh key generate in $SSHKEY_FILE.pub, now paste it in the tail of '/root/.ssh/authorized_keys" 8 | else 9 | echo "Error: Please run this programm as root" 10 | fi 11 | -------------------------------------------------------------------------------- /scripts/taillog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LOG_DIR="/var/log/uss" 4 | LINE=100 5 | 6 | if [ $# -lt 1 ] 7 | then 8 | echo "Usage: " 9 | echo " $0 -t tail log" 10 | echo " $0 -s scp log" 11 | fi 12 | 13 | while getopts :tsl options 14 | do 15 | case $options in 16 | t) 17 | for i in `awk '{print $1}' /sysy/yfs/etc/cluster.conf ` 18 | do 19 | echo $i 20 | ssh $i "/sysy/yfs/app/bin/taillog.sh -l" 21 | done 22 | ;; 23 | s) 24 | for i in `awk '{print $1}' /sysy/yfs/etc/cluster.conf ` 25 | do 26 | echo $i 27 | scp $i:/var/log/uss/linex100.log /var/log/uss/"$i"_linex100.log 28 | echo scp $i:/var/log/uss/linex100.log /var/log/uss/"$i"_linex100.log 29 | done 30 | ;; 31 | l) 32 | 33 | if [ -d "$LOG_DIR" ];then 34 | echo > /var/log/uss/linex100.log 35 | date >> /var/log/uss/linex100.log 36 | for log in `find "$LOG_DIR" -type f ` 37 | do 38 | echo =========== $log =========== >> /var/log/uss/linex100.log 39 | tail -n $LINE $log >> /var/log/uss/linex100.log 40 | done 41 | else 42 | echo "No such directory" 43 | fi 44 | ;; 45 | esac 46 | done 47 | -------------------------------------------------------------------------------- /sdfs/allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALLOCATOR__ 2 | #define __ALLOCATOR__ 3 | 4 | #include 5 | 6 | #include "ylib.h" 7 | #include "dbg.h" 8 | 9 | #define ENABLE_ALLOCATE_BALANCE 1 10 | 11 | int allocator_init(); 12 | int allocator_new(int repnum, int hardend, int tier, nid_t *disks); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /sdfs/attr_queue.h: -------------------------------------------------------------------------------- 1 | #ifndef __ATTR_QUEUE__ 2 | #define __ATTR_QUEUE__ 3 | 4 | #include 5 | 6 | #include "ylib.h" 7 | #include "yfs_md.h" 8 | #include "dbg.h" 9 | 10 | int attr_queue_init(); 11 | int attr_queue_destroy(); 12 | void attr_queue_run(void *var); 13 | int attr_queue_update(const volid_t *volid, const fileid_t *fileid, void *md); 14 | int attr_queue_extern(const volid_t *volid, const fileid_t *fileid, uint64_t size); 15 | int attr_queue_truncate(const volid_t *volid, const fileid_t *fileid, uint64_t size); 16 | int attr_queue_settime(const volid_t *volid, const fileid_t *fileid, const void *setattr); 17 | 18 | int attr_cache_update(const volid_t *volid, const chkid_t *chkid, const md_proto_t *md); 19 | int attr_cache_get(const volid_t *volid, const chkid_t *chkid, md_proto_t *md); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /sdfs/io_analysis.h: -------------------------------------------------------------------------------- 1 | #ifndef __IO_ANALYSIS_H__ 2 | #define __IO_ANALYSIS_H__ 3 | 4 | #include 5 | 6 | typedef enum { 7 | ANALYSIS_OP_READ = 1, 8 | ANALYSIS_OP_WRITE, 9 | ANALYSIS_IO_READ, 10 | ANALYSIS_IO_WRITE, 11 | } analysis_op_t; 12 | 13 | int io_analysis_init(const char *name, int seq); 14 | int io_analysis(analysis_op_t op, int count); 15 | int io_analysis_dump(const char *type); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /sdfs/sdfs_chunk.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDFS_CHUNK_H__ 2 | #define __SDFS_CHUNK_H__ 3 | 4 | #include 5 | 6 | #include "ylib.h" 7 | #include "chk_proto.h" 8 | #include "net_proto.h" 9 | #include "dbg.h" 10 | 11 | int sdfs_chunk_read(const chkid_t *chkid, buffer_t *buf, int count, 12 | int offset, const ec_t *ec); 13 | int sdfs_chunk_write(const fileinfo_t *md, const chkid_t *objid, 14 | const buffer_t *buf, int count, 15 | int offset, const ec_t *ec); 16 | int sdfs_chunk_check(const chkid_t *chkid); 17 | int sdfs_chunk_recovery(const chkid_t *chkid); 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /test/cluster.conf: -------------------------------------------------------------------------------- 1 | Gentoo redis[0,1] mond[0] cds[0,1,2,3,4,5,6] nfs[0] 2 | -------------------------------------------------------------------------------- /test/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([test],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | 5 | AC_PROG_CC 6 | AC_PROG_LIBTOOL 7 | AC_PROG_INSTALL 8 | AC_CONFIG_HEADERS([include/config.h]) 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -W -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -D_REENTRANT -I../../parser/include -I../../ynet/include -I../../ylib/include/ -I../../yfs/include/" 21 | 22 | subdirs=" \ 23 | src \ 24 | " 25 | 26 | AC_SUBST(subdirs) 27 | 28 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 29 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 30 | 31 | AC_CONFIG_FILES([ \ 32 | Makefile \ 33 | src/Makefile \ 34 | ]) 35 | 36 | AC_OUTPUT 37 | -------------------------------------------------------------------------------- /test/exports.conf: -------------------------------------------------------------------------------- 1 | ynfs { 2 | use_export off; 3 | export { 4 | /default 127.0.0.1 (rw); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/ftp.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "path": "/ftp01", 4 | "password": "mdsmds123", 5 | "user": "root", 6 | "permision": "ro" 7 | }, 8 | { 9 | "path": "/ftpec2a2", 10 | "password": "mdsmds", 11 | "user": "root", 12 | "permision": "rw" 13 | } 14 | ] -------------------------------------------------------------------------------- /test/include/keep: -------------------------------------------------------------------------------- 1 | just keep this dir 2 | -------------------------------------------------------------------------------- /test/locks/locktests: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/test/locks/locktests -------------------------------------------------------------------------------- /test/make_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LOG_FILE="./make_test.log" 4 | for((i=0; i<20; i++)); do 5 | echo "***********************begin $i times test... ******************************" >> ${LOG_FILE} 6 | python test.py >> ${LOG_FILE} 2>&1 7 | ret=`echo $?` 8 | if [ ${ret} -ne 0 ] ; then 9 | echo "*********************** $i times test fail ******************************" >> ${LOG_FILE} 10 | exit 1 11 | fi 12 | echo "*********************** $i times test ok ******************************" >> ${LOG_FILE} 13 | done 14 | -------------------------------------------------------------------------------- /test/nfs_conf/common.conf: -------------------------------------------------------------------------------- 1 | NFSV4 { 2 | Allow_Numeric_Owners = true; 3 | Only_Numeric_Owners = true; 4 | } 5 | 6 | LOG 7 | { 8 | Default_log_level = FATAL; 9 | Components { 10 | MEMLEAKS = FATAL; 11 | FSAL = DEBUG; 12 | NFSPROTO = FATAL; 13 | NFS_V4 = FATAL; 14 | EXPORT = FATAL; 15 | FILEHANDLE = FATAL; 16 | DISPATCH = FATAL; 17 | CACHE_INODE = FATAL; 18 | CACHE_INODE_LRU = FATAL; 19 | HASHTABLE = FATAL; 20 | HASHTABLE_CACHE = FATAL; 21 | DUPREQ = FATAL; 22 | INIT = DEBUG; 23 | MAIN = DEBUG; 24 | IDMAPPER = FATAL; 25 | NFS_READDIR = FATAL; 26 | NFS_V4_LOCK = FATAL; 27 | CONFIG = FATAL; 28 | CLIENTID = FATAL; 29 | SESSIONS = FATAL; 30 | PNFS = FATAL; 31 | RW_LOCK = FATAL; 32 | NLM = FATAL; 33 | RPC = FATAL; 34 | NFS_CB = FATAL; 35 | THREAD = FATAL; 36 | NFS_V4_ACL = FATAL; 37 | STATE = FATAL; 38 | FSAL_UP = FATAL; 39 | DBUS = FATAL; 40 | } 41 | 42 | FORMAT { 43 | FILE_NAME = true; 44 | LINE_NUM = true; 45 | FUNCTION_NAME = true; 46 | LEVEL = true; 47 | COMPONENT = true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/nfs_conf/ganesha.conf: -------------------------------------------------------------------------------- 1 | %include "/etc/ganesha/common.conf" 2 | EXPORT 3 | { 4 | Export_Id = 2; 5 | Path = /nfs-ganesha; 6 | Pseudo = /nfs-ganesha; 7 | Access_Type = RO; 8 | Squash = No_Root_Squash; 9 | Disable_ACL = TRUE; 10 | SecType = sys; 11 | 12 | FSAL { 13 | name = USS; 14 | volpath = /nfs-ganesha; 15 | } 16 | CLIENT { 17 | Clients = 127.0.0.1; 18 | Access_Type = "RW"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/nfs_conf/nfs-ganesha: -------------------------------------------------------------------------------- 1 | OPTIONS="-L /opt/fusionnas/log/nfs-ganesha.log -f /etc/ganesha/ganesha.conf" 2 | EPOCH_EXEC="/bin/true" 3 | -------------------------------------------------------------------------------- /test/nfs_conf/nfs-ganesha-config.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Process NFS-Ganesha configuration 3 | DefaultDependencies=no 4 | 5 | [Service] 6 | Type=oneshot 7 | ExecStart=/usr/libexec/ganesha/nfs-ganesha-config.sh 8 | -------------------------------------------------------------------------------- /test/nfs_conf/nfs-ganesha-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Extract configuration from /etc/sysconfig/ganesha and 5 | # copy or generate new environment variables to 6 | # /run/sysconfig/ganesha to be used by nfs-ganesha service 7 | # 8 | 9 | CONFIGFILE=/etc/sysconfig/nfs-ganesha 10 | RUNCONFIG=/run/sysconfig/nfs-ganesha 11 | if [ ! -e $(command dirname ${CONFIGFILE} 2>/dev/null) ]; then 12 | # Debian/Ubuntu 13 | CONFIGFILE=/etc/ganesha/nfs-ganesha 14 | RUNCONFIG=/etc/default/nfs-ganesha 15 | fi 16 | 17 | if [ -r ${CONFIGFILE} ]; then 18 | . ${CONFIGFILE} 19 | [ -x ${EPOCH_EXEC} ] && EPOCHVALUE=`${EPOCH_EXEC}` 20 | 21 | mkdir -p $(command dirname ${RUNCONFIG} 2>/dev/null) 22 | { 23 | cat ${CONFIGFILE} 24 | [ -n "${EPOCHVALUE}" ] && echo EPOCH=\"-E $EPOCHVALUE\" 25 | 26 | # Set NUMA options if numactl is present 27 | NUMACTL=$(command -v numactl 2>/dev/null) 28 | if [ -n "${NUMACTL}" ]; then 29 | echo NUMACTL=${NUMACTL} 30 | echo NUMAOPTS=--interleave=all 31 | fi 32 | } > ${RUNCONFIG} 33 | fi 34 | -------------------------------------------------------------------------------- /test/nfs_conf/nfs-ganesha-lock.service: -------------------------------------------------------------------------------- 1 | # This file is part of nfs-ganesha. 2 | # 3 | # rpc.statd is started by the nfs-lock.service, but that also loads the 'lockd' 4 | # kernel module in 'ExecStartPre'. The 'lockd' kernel module will register 5 | # itself as 'nlockmgr' which conflicts with the nfs-ganesha locking 6 | # implementation. 7 | # 8 | # This unit includes all the nfs-lock.service settings and details, but 9 | # overrides the 'ExecStartPre' and 'ExecStartPost' options. 10 | # 11 | # When this unit is started, the original nfs-lock.service is stopped (due to 12 | # the 'Conflicts' directive). With stopping the nfs-lock.service, 'lockd' gets 13 | # instructed to unregister 'nlockmgr' from the portmapper. 14 | # 15 | # The nfs-ganesha.service depends on this unit. 16 | # 17 | 18 | .include /usr/lib/systemd/system/rpc-statd.service 19 | 20 | [Unit] 21 | Before=nfs-ganesha.service 22 | Conflicts=nfs-lock.service rpc-statd.service 23 | 24 | [Service] 25 | ExecStartPre= 26 | ExecStopPost= 27 | 28 | -------------------------------------------------------------------------------- /test/redis.conf.tpl: -------------------------------------------------------------------------------- 1 | daemonize yes 2 | tcp-backlog 511 3 | unixsocketperm 700 4 | timeout 0 5 | tcp-keepalive 0 6 | loglevel notice 7 | databases 16 8 | save 900 1 9 | save 300 10 10 | save 60 10000 11 | stop-writes-on-bgsave-error yes 12 | rdbcompression yes 13 | rdbchecksum yes 14 | dbfilename dump.rdb 15 | slave-serve-stale-data yes 16 | slave-read-only yes 17 | repl-diskless-sync no 18 | repl-diskless-sync-delay 5 19 | repl-disable-tcp-nodelay no 20 | slave-priority 100 21 | appendonly yes 22 | appendfilename "appendonly.aof" 23 | appendfsync always 24 | no-appendfsync-on-rewrite no 25 | auto-aof-rewrite-percentage 150 26 | auto-aof-rewrite-min-size 64mb 27 | aof-load-truncated yes 28 | lua-time-limit 5000 29 | slowlog-log-slower-than 10000 30 | slowlog-max-len 128 31 | latency-monitor-threshold 0 32 | notify-keyspace-events "" 33 | hash-max-ziplist-entries 512 34 | hash-max-ziplist-value 64 35 | list-max-ziplist-entries 512 36 | list-max-ziplist-value 64 37 | set-max-intset-entries 512 38 | zset-max-ziplist-entries 128 39 | zset-max-ziplist-value 64 40 | hll-sparse-max-bytes 3000 41 | activerehashing yes 42 | client-output-buffer-limit normal 0 0 0 43 | client-output-buffer-limit slave 256mb 64mb 60 44 | client-output-buffer-limit pubsub 32mb 8mb 60 45 | hz 10 46 | aof-rewrite-incremental-fsync yes 47 | -------------------------------------------------------------------------------- /test/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NUM=$1 4 | 5 | for i in $(seq $NUM) 6 | do 7 | DATE=$(date +"%Y-%m-%d %T") 8 | pkill -9 python 9 | mkdir -p /tmp/sdfs_test 10 | echo "$DATE begin test $i/$NUM, log is in /tmp/sdfs_test" 11 | time python2 test.py $2 > /tmp/sdfs_test/test.log 2>&1 12 | RET=$? 13 | if [ "$RET" -ne 0 ]; then 14 | DATE=$(date +"%Y-%m-%d %T") 15 | echo "$DATE ret $RET" 16 | exit $RET 17 | fi 18 | DATE=$(date +"%Y-%m-%d %T") 19 | echo "$DATE end $i" 20 | 21 | # check valgrind result 22 | grep 'llegal\|inappropriate\|inadequate\|verlapping\|emory leak\|overlap\|Invalid read\|Invalid write\|definitely' /tmp/sdfs_test/*.log | grep -v 'definitely lost: 0 bytes' 23 | if [ $? == 0 ]; then 24 | echo "==========valgrind check fail===========" 25 | exit 1 26 | fi 27 | 28 | done 29 | -------------------------------------------------------------------------------- /test/shell/iops.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | while [ 1 ] 3 | do 4 | find "$1" -type f|while read file 5 | do 6 | if ! [ -L "$file" ];then 7 | 8 | echo "http://192.168.1.124/mds/data/$file" 9 | fi 10 | done >> /dev/null 11 | done 12 | -------------------------------------------------------------------------------- /test/shell/mirror_R.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TARGET="/home/gj/linux" 4 | MYUSER="mds" 5 | MYPASSWD="mds" 6 | 7 | do_it() 8 | { 9 | SERVERPATH=`date +%s` 10 | 11 | lftp $MYUSER:$MYPASSWD@192.168.1.119:21 << EEEEOF 12 | mkdir "$SERVERPATH" 13 | cd "$SERVERPATH" 14 | lcd "$TARGET" 15 | lcd "../" 16 | mirror -R $TARGET 17 | bye 18 | EEEEOF 19 | 20 | sleep 2 21 | 22 | if [ $? != 0 ] 23 | then 24 | echo "+Mirror $TARGET to $SERVERPATH@192.168.1.10 faile +`date +%D-%T`" >> mirror.log 25 | continue 26 | fi 27 | } 28 | 29 | 30 | 31 | while [ 1 != 0 ] 32 | do 33 | do_it 34 | done 35 | -------------------------------------------------------------------------------- /test/shell/webdownload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function download 4 | { 5 | count=0 6 | while [ $count -lt $1 ] ; do 7 | # wget --timeout=8 http://192.168.1.200/zzn/mk2list.sh -O /dev/null 8 | # wget --timeout=8 http://192.168.1.200/zzn/gcc-2.95.3.tar.gz -O /dev/null 9 | time wget --timeout=8 http://192.168.1.200/zzn/RFC-all.tar.gz -O /dev/null 10 | let "count+=1" 11 | done 12 | echo $1 13 | } 14 | 15 | time download 2 16 | -------------------------------------------------------------------------------- /test/src/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS=\ 2 | test_skiplist \ 3 | test_bitmap \ 4 | ynfs_iotest \ 5 | testlock \ 6 | io_test 7 | 8 | io_test_SOURCES = io_test.c 9 | 10 | #bigfile_4g+_SOURCES = \ 11 | # bigfile_4g+.c 12 | 13 | #testyfscli_SOURCES = \ 14 | # yfsclitest.c 15 | 16 | # testftp_SOURCES = \ 17 | # yftptest.c 18 | 19 | # test_fuse_SOURCES = \ 20 | # test_fuse.c 21 | 22 | # aio_test_SOURCES= \ 23 | # aio_test.c 24 | 25 | # pread_test_SOURCES= \ 26 | # pread_test.c 27 | 28 | # test_seek_SOURCES= test_seek.c 29 | 30 | test_skiplist_SOURCES=test_skiplist.c 31 | test_bitmap_SOURCES=test_bitmap.c 32 | testlock_SOURCES=testlock.c 33 | #ynfs_functest_SOURCES=md5.c main.c functest.c 34 | ynfs_iotest_SOURCES=md5.c ynfs_iotest.c 35 | 36 | AM_LDFLAGS = @LDFLAGS@ \ 37 | -L../../parser/lib -lparser\ 38 | -L../../yfs/build -lyfs \ 39 | -L../../ynet/build -lynet \ 40 | -L../../ylib/lib -lylib\ 41 | -lpthread -lcrypto -laio -lssl 42 | -------------------------------------------------------------------------------- /test/src/pread_test.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | #define DBG_SUBSYS S_YFSLIB 19 | 20 | #include "sdfs_lib.h" 21 | #include "dbg.h" 22 | #include "ylib.h" 23 | 24 | int fd, fd_out; 25 | void *ptr; 26 | off_t size = 3114787; 27 | 28 | 29 | int main () 30 | { 31 | int ret; 32 | char buf[512]; 33 | 34 | ly_init(LY_IO); 35 | 36 | sleep(1); 37 | 38 | fd = ly_open("/gray/Painted.Skin.2008.CN.DVDRip.XviD-PMCG-cd2.idx"); 39 | 40 | ret = ly_pread(fd, buf, 512, 0); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/src/python/merge_chunk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | 5 | def is_x86_64(): 6 | return '86_64' in os.popen('uname -a').read() 7 | 8 | def merge_chk(from_chk, to_fd): 9 | try: 10 | fr = open(from_chk, 'r') 11 | fr.seek(4160) 12 | except: 13 | raise 14 | 15 | while True: 16 | buf = fr.read(524288) 17 | if buf: 18 | to_fd.write(buf) 19 | else: 20 | break 21 | 22 | fr.close() 23 | 24 | def main(): 25 | if not is_x86_64(): 26 | print 'System is i386, exit' 27 | exit(0) 28 | 29 | to_fd = open(sys.argv[-1], 'w') 30 | for i in sys.argv[1:-1]: 31 | print 'merge chk %s' % i 32 | merge_chk(i, to_fd) 33 | 34 | to_fd.close() 35 | 36 | if __name__ == '__main__': 37 | main() 38 | -------------------------------------------------------------------------------- /test/src/python/yfs_clear.sh: -------------------------------------------------------------------------------- 1 | YFS=/sysy/yfs 2 | 3 | cd $YFS/app/sbin 4 | 5 | python yfs-daemon.py -k all 6 | 7 | rm -rf $YFS/cds/1/* 8 | rm -rf $YFS/cds/2/* 9 | rm -rf $YFS/cds/3/* 10 | rm -rf $YFS/mds/* 11 | 12 | rm -rf /var/log/yfs*.log 13 | rm -rf /var/log/ynfs.log 14 | 15 | python yfs-daemon.py -s mds 16 | python yfs-daemon.py -s ynfs 17 | # python yfs-daemon.py -s cds 18 | 19 | sleep 1 20 | -------------------------------------------------------------------------------- /test/src/python/yfs_mount.sh: -------------------------------------------------------------------------------- 1 | cd /root 2 | umount -f nfs 3 | mount -o proto=tcp,noacl,wsize=524288,rsize=524288,timeo=30,retrans=1 localhost:/ nfs 4 | 5 | -------------------------------------------------------------------------------- /test/src/test_bitmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "bmap.h" 5 | 6 | #define N 10 7 | 8 | int main() 9 | { 10 | int i; 11 | bmap_t *bmap; 12 | 13 | assert((1<<2) == 4); 14 | assert((1<<3) == 8); 15 | 16 | bmap_create(bmap, N); 17 | 18 | for (i = 0; i < N; i+=2) { 19 | bmap_set(bmap, i); 20 | } 21 | 22 | for (i = 0; i < N; ++i) { 23 | if (i % 2 == 0) 24 | assert(bmap_get(bmap, i)); 25 | else 26 | assert(!bmap_get(bmap, i)); 27 | } 28 | 29 | for (i = 0; i < N; ++i) 30 | bmap_del(bmap, i); 31 | 32 | for (i = 0; i < N; i++) { 33 | assert(!bmap_get(bmap, i)); 34 | } 35 | 36 | bmap_destroy(bmap); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/src/testlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "dbg.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int ret, fd; 9 | char *key; 10 | 11 | key = argv[argc - 1]; 12 | 13 | fd = open(key, O_CREAT | O_RDONLY, 0640); 14 | if (fd == -1) { 15 | ret = errno; 16 | GOTO(err_ret, ret); 17 | } 18 | 19 | //DINFO("fd %d\n", fd); 20 | 21 | ret = flock(fd, LOCK_EX | LOCK_NB); 22 | if (ret == -1) { 23 | ret = errno; 24 | if (ret == EWOULDBLOCK) { 25 | DINFO("lock %s fail\n", key); 26 | goto err_fd; 27 | } else 28 | GOTO(err_ret, ret); 29 | } 30 | 31 | DINFO("lock %s success\n", key); 32 | 33 | close(fd); 34 | 35 | return 0; 36 | err_fd: 37 | close(fd); 38 | err_ret: 39 | return ret; 40 | } 41 | -------------------------------------------------------------------------------- /tools/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## http://www.amath.washington.edu/~lf/tutorials/autoconf/toolsmanual.html 4 | 5 | aclocal --version | exit 6 | autoheader --version | exit 7 | autoconf --version | exit 8 | automake --version | exit 9 | libtool --version | exit 10 | libtoolize --version | exit 11 | 12 | rm -f ltconfig ltmain.sh config.cache aclocal.m4 13 | 14 | # remove the autoconf cache 15 | rm -rf autom4te*.cache 16 | 17 | touch NEWS README AUTHORS ChangeLog 18 | 19 | set -e 20 | 21 | echo "aclocal... " 22 | ${ACLOCAL:-aclocal} -I . 23 | echo "autoheader... " 24 | ${AUTOHEADER:-autoheader} 25 | 26 | echo "libtoolize... " 27 | ${LIBTOOLIZE:-libtoolize} --automake -c -f 28 | 29 | echo "autoconf... " 30 | ${AUTOCONF:-autoconf} 31 | echo "automake... " 32 | ${AUTOMAKE:-automake} -a -c 33 | 34 | # remove the autoconf cache 35 | rm -rf autom4te*.cache 36 | 37 | echo "Now type './configure ...' and 'make' to compile." 38 | -------------------------------------------------------------------------------- /tools/conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #set -xv 4 | 5 | PLATFORM=`uname -m` 6 | 7 | if [ $PLATFORM = 'x86_64' ];then 8 | CONF_ARGS='--with-pic' 9 | else 10 | CFLAGS='-D_FILE_OFFSET_BITS=64' 11 | fi 12 | 13 | PREFIX='/sysy/yfs/app' 14 | 15 | if [ -x ccache ]; then 16 | CC="ccache gcc $1" CFLAGS="$CFLAGS" ./configure $CONF_ARGS --prefix=$PREFIX 17 | else 18 | CC="gcc $1" CFLAGS="$CFLAGS" ./configure $CONF_ARGS --prefix=$PREFIX 19 | fi 20 | -------------------------------------------------------------------------------- /tools/delsvn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for f in `find -name .svn -type d `;do rm -rf $f;done 4 | -------------------------------------------------------------------------------- /tools/get_version.base: -------------------------------------------------------------------------------- 1 | #ifndef __GET_VERSION_H__ 2 | #define __GET_VERSION_H__ 3 | 4 | #include 5 | 6 | #define get_version() \ 7 | do { \ 8 | fprintf(stdout, "%s\n", YVERSION); \ 9 | } while (0) 10 | 11 | #endif /* __GET_VERSION_H__ */ 12 | -------------------------------------------------------------------------------- /tools/get_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FUNC_FILE=$1/include/get_version.h 4 | FUNC_BASE=$1/tools/get_version.base 5 | 6 | rm -f $FUNC_FILE 7 | cat $FUNC_BASE | sed -n '1,5p' >> $FUNC_FILE 8 | 9 | echo "#define YVERSION \\" >> $FUNC_FILE 10 | 11 | 12 | #echo "\"Version: `cat ../v_num|cut -d '_' -f 1` \\">> $FUNC_FILE 13 | #echo "\nInternalID: `cat ../v_num|cut -d '_' -f 2` \\">> $FUNC_FILE 14 | #echo $FUNC_FILE 15 | echo "\"BuildId: `git show |grep -i ^commit |awk '{print $2}'` \\" >> $FUNC_FILE 16 | echo "\nDate: `git show |grep ^Date:|cut -c 9-` \\" >> $FUNC_FILE 17 | echo "\nBranch: SDFS/`git branch |grep '^\*' |awk '{print $2}'` \\" >> $FUNC_FILE 18 | echo "\nSystem: `lsb_release -i | awk '{print $3}'` `uname -ir` \\" >> $FUNC_FILE 19 | echo "\nGlibc: `/lib64/libc.so.6 | head -n 1` \"" >> $FUNC_FILE 20 | 21 | 22 | echo >> $FUNC_FILE 23 | cat $FUNC_BASE | sed -n '6,12p'>> $FUNC_FILE 24 | 25 | -------------------------------------------------------------------------------- /tools/getlines.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . -name "*.[cch]" | xargs wc -l 4 | -------------------------------------------------------------------------------- /tools/mktags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -f tags 4 | rm -f cscope* 5 | rm -f filenametags 6 | 7 | echo -e "!_TAG_FILE_SORTED\t2\t/2=foldcase/" > filenametags 8 | # find . -not -regex '.*\.\(Plo\|lo\|o\|png\|gif\)' -type f -printf "%f\t%p\t1\n" | sort -f >> filenametags 9 | find $(pwd) -name '*.[ch]' -type f -printf "%f\t%p\t1\n" | sort -f >> filenametags 10 | 11 | ctags -R --fields=+lS . 12 | 13 | find $(pwd) -name "*.[ch]" > cscope.files 14 | cscope -bq 15 | -------------------------------------------------------------------------------- /tools/ocat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | from optparse import OptionParser 7 | 8 | def main(file, offset, length): 9 | 10 | f = open('%s' % file) 11 | f.seek(offset) 12 | content = f.read(length) 13 | sys.stdout.write ("%s" % content) 14 | f.seek(0) 15 | f.close() 16 | 17 | 18 | 19 | if __name__ == "__main__": 20 | parser = OptionParser() 21 | parser.add_option("-f", "--file", dest="file", type='string', help="file to open") 22 | parser.add_option("-o", "--offset", dest="offset", type='int', help="offset position", default="0") 23 | parser.add_option("-l", "--length", action="store", dest="length", type='int', help="read length", ) 24 | (options, args) = parser.parse_args() 25 | try: 26 | main(options.file, options.offset, options.length) 27 | except: 28 | print "Usage: ocat.py -f file -o offset -l length" 29 | -------------------------------------------------------------------------------- /tools/replice.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ################### 4 | # Usage: ./replace.sh dirname s_syscall d_syscall 5 | ################### 6 | 7 | for file in `find "$1" -name '*.[c,h]'` 8 | do 9 | eval sed -i 's/"$2"/"$3"/g' "$file" 10 | done 11 | 12 | 13 | for file in `find "$1" -name '*.py'` 14 | do 15 | eval sed -i 's/"$2"/"$3"/g' "$file" 16 | done 17 | 18 | for file in `find "$1" -name '*.sh'` 19 | do 20 | eval sed -i 's/"$2"/"$3"/g' "$file" 21 | done 22 | 23 | for file in `find "$1" -name '*.rst'` 24 | do 25 | eval sed -i 's/"$2"/"$3"/g' "$file" 26 | done 27 | 28 | for file in `find "$1" -name '*.conf'` 29 | do 30 | eval sed -i 's/"$2"/"$3"/g' "$file" 31 | done 32 | 33 | -------------------------------------------------------------------------------- /tools/tagit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #find . -name "*.[cch]" | xargs ctags 4 | ctags -R 5 | 6 | -------------------------------------------------------------------------------- /tools/trunk_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PREFIX=/sysy/yfs/app 4 | cd ../ # yfs/trunk 5 | echo `svn info |sed -n '2p' |awk -F/ '{print $NF}'` `svn info |sed -n '5p' |awk '{print " r"$2}'` > $PREFIX"/VERSION" 6 | 7 | -------------------------------------------------------------------------------- /tools/whereis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . -name "*.[cch]" | xargs grep $1 4 | -------------------------------------------------------------------------------- /yfs/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /yfs/cds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | ) 7 | link_directories(${PROJECT_BINARY_DIR}/lib) 8 | 9 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/sbin) 10 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 11 | 12 | set(MOD_EXTRA_LIBS pthread aio crypt uuid ssl parser ylib ynet yfs) 13 | 14 | set(MOD_SRCS 15 | main.c 16 | cds.c 17 | cds_cache.c 18 | chk_jnl.c 19 | cds_robot.c 20 | cds_volume.c 21 | cds_proto.c 22 | cds_hb.c 23 | cds_lib.c 24 | cds_events.c 25 | cds_state_machine.c 26 | rangelock.c 27 | cds_jnl.c 28 | disk.c 29 | watchdog.c 30 | cds_sync.c 31 | cds_leveldb.c 32 | ) 33 | 34 | # cds_hotsum.c 35 | 36 | add_executable(yfs_cds ${MOD_SRCS}) 37 | target_link_libraries(yfs_cds ${MOD_EXTRA_LIBS}) 38 | 39 | install(TARGETS yfs_cds 40 | RUNTIME DESTINATION app/sbin) 41 | 42 | -------------------------------------------------------------------------------- /yfs/cds/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS=yfs_cds 2 | 3 | yfs_cds_SOURCES = \ 4 | main.c \ 5 | cds.c \ 6 | chunk.c \ 7 | cds_robot.c \ 8 | cds_volume.c \ 9 | cds_proto.c \ 10 | cds_hb.c \ 11 | cds_lib.c \ 12 | cds_events.c \ 13 | cds_state_machine.c \ 14 | cds_leveldb.c\ 15 | objs_stm.c \ 16 | objs.c \ 17 | objs_event.c \ 18 | inode_stm.c \ 19 | inodes_event.c \ 20 | inodes.c \ 21 | disk.c \ 22 | watchdog.c \ 23 | rangelock.c \ 24 | chkinfo.c \ 25 | dpool.c 26 | 27 | AM_LDFLAGS = @LDFLAGS@ \ 28 | -L../../ylib/lib -lylib \ 29 | -L../../parser/lib -lparser \ 30 | -L../../ynet/build -lynet \ 31 | -L../build -lyfs \ 32 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl -lattr 33 | -------------------------------------------------------------------------------- /yfs/cds/cds_hb.h: -------------------------------------------------------------------------------- 1 | #ifndef __CDS_HB_H__ 2 | #define __CDS_HB_H__ 3 | 4 | #include "file_proto.h" 5 | #include "chk_proto.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /yfs/cds/cds_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __CDS_LIB_H__ 2 | #define __CDS_LIB_H__ 3 | 4 | #include 5 | 6 | #include "file_proto.h" 7 | #include "cd_proto.h" 8 | #include "chk_meta.h" 9 | #include "cds.h" 10 | 11 | /* cds_lib.c */ 12 | int cds_getinfo(const chkid_t *chkid, chkmeta2_t *md, uint64_t *unlost_version, 13 | uint64_t *max_version); 14 | 15 | /* cds_hb.c */ 16 | extern int hb_service_init(hb_service_t *, int servicenum); 17 | extern void *cds_hb(void *); 18 | int hb_service_destroy(); 19 | 20 | /* cds_robot.c */ 21 | extern int robot_service_init(robot_service_t *); 22 | extern int robot_service_destroy(robot_service_t *); 23 | extern void *cds_robot(void *); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /yfs/cds/cds_volume.h: -------------------------------------------------------------------------------- 1 | #ifndef __CDS_VOLUME_H__ 2 | #define __CDS_VOLUME_H__ 3 | 4 | #include "md_proto.h" 5 | 6 | 7 | int cds_volume_init(); 8 | int cds_volume_update(uint32_t volid, int size); 9 | int cds_volume_get(volinfo_t **_info); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /yfs/cds/chkinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef __CHKINFO_H__ 2 | #define __CHKINFO_H__ 3 | 4 | #include 5 | 6 | #include "chk_meta.h" 7 | #include "yfscds_conf.h" 8 | #include "cache.h" 9 | #include "sdfs_buffer.h" 10 | 11 | typedef struct { 12 | chkid_t id; 13 | uint32_t size; 14 | int hit; 15 | } chklist_t; 16 | 17 | int chkinfo_dump(chklist_t **_chklist, int *_count); 18 | int chkinfo_init(); 19 | int chkinfo_add(const chkid_t *chkid, int size); 20 | int chkinfo_del(const chkid_t *chkid, int size); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /yfs/cds/disk.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISK_H__ 2 | #define __DISK_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "chk_meta.h" 8 | #include "file_proto.h" 9 | #include "cd_proto.h" 10 | #include "ynet_rpc.h" 11 | #include "sdfs_conf.h" 12 | #include "sdfs_buffer.h" 13 | 14 | #define MAX_SUBMIT 256 15 | 16 | int disk_join(const diskid_t *diskid, struct statvfs *fsbuf); 17 | int disk_init(const char *home, uint64_t _max_object); 18 | int disk_statvfs(struct statvfs *_stbuf); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /yfs/cds/dpool.h: -------------------------------------------------------------------------------- 1 | #ifndef __DPOOL_H__ 2 | #define __DPOOL_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_conf.h" 8 | 9 | typedef struct { 10 | char home[MAX_PATH_LEN]; 11 | sy_spinlock_t lock; 12 | struct list_head list; 13 | int len; 14 | } dpool_level_t; 15 | 16 | typedef struct { 17 | int inited; 18 | int max; 19 | int level_count; 20 | size_t size; 21 | dpool_level_t array[0]; 22 | } dpool_t; 23 | 24 | int dpool_init(dpool_t **dpool, size_t size, int max, int level_count); 25 | int dpool_get(dpool_t *dpool, char *path, int level); 26 | int dpool_put(dpool_t *dpool, const char *path, int level); 27 | uint64_t dpool_size(dpool_t *dpool, int levelid); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /yfs/cds/hb.h: -------------------------------------------------------------------------------- 1 | #ifndef __HB_H__ 2 | #define __HB_H__ 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /yfs/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([yfs],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -W -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../ynet/include -I../../ylib/include -I../../parser/include" 21 | 22 | subdirs=" \ 23 | include \ 24 | build \ 25 | cds \ 26 | tests \ 27 | utils \ 28 | " 29 | 30 | AC_SUBST(subdirs) 31 | 32 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 33 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 34 | 35 | LIBS=-lpthread 36 | 37 | AC_CHECK_FUNCS([pthread_rwlock_init]) 38 | 39 | AC_CONFIG_FILES([ \ 40 | Makefile \ 41 | include/Makefile \ 42 | cds/Makefile \ 43 | build/Makefile \ 44 | tests/Makefile \ 45 | utils/Makefile \ 46 | ]) 47 | 48 | AC_OUTPUT 49 | -------------------------------------------------------------------------------- /yfs/include/Makefile.am: -------------------------------------------------------------------------------- 1 | include_HEADERS = \ 2 | yfs_lib.h 3 | -------------------------------------------------------------------------------- /yfs/include/chk_meta.h: -------------------------------------------------------------------------------- 1 | #ifndef __CHK_META_H__ 2 | #define __CHK_META_H__ 3 | 4 | #include 5 | 6 | #include "chk_proto.h" 7 | #include "file_proto.h" 8 | 9 | #define YFS_CDS_MET_OFF (sizeof(uint32_t)) 10 | 11 | #pragma pack(8) 12 | 13 | typedef struct { 14 | crc_t crc; 15 | chkid_t chkid; 16 | uint64_t __pad0__; 17 | uint64_t chk_version; 18 | uint32_t chklen; 19 | uint32_t chkoff; 20 | uint32_t chkmax; 21 | uint32_t __pad1__; 22 | uint32_t status; 23 | uint64_t seq; 24 | uint32_t __pad__2; 25 | uint64_t __pad__3;/*lost version*/ 26 | } chkmeta2_t_old; 27 | 28 | typedef struct { 29 | crc_t crc; 30 | uint64_t chk_version; 31 | chkid_t chkid; 32 | uint64_t __pad__1[2]; 33 | } chkmeta2_t; 34 | 35 | #pragma pack() 36 | 37 | //#define YFS_CDS_CHK_OFF (sizeof(chkmeta2_t) + YFS_CDS_CRC_LEN) 38 | #define YFS_CDS_CHK_OFF (PAGE_SIZE * 3) 39 | 40 | #define CHUNK_OFFSET (PAGE_SIZE * 2) 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /yfs/include/chunk_journal.h: -------------------------------------------------------------------------------- 1 | #ifndef __CHK_JNL_H 2 | #define __CHK_JNL_H 3 | 4 | #include "chk_proto.h" 5 | 6 | int chkjnl_init(); 7 | int chkjnl_get(const chkid_t *id, uint64_t verison, chkop_t *op); 8 | int chkjnl_prep(const chkid_t *id); 9 | int chkjnl_add(const chkid_t *id, uint64_t verison, const chkop_t *op); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /yfs/include/directory_quota_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef _D_QUOTA_CACHE_H_ 2 | #define _D_QUOTA_CACHE_H_ 3 | 4 | #include "sdfs_quota.h" 5 | 6 | typedef struct { 7 | uint64_t quotaid; 8 | quota_t quota; 9 | }dir_quota_entry_t; 10 | 11 | extern int dir_quota_cache_init(); 12 | extern int dir_quota_cache_get(const uint64_t quotaid, cache_entry_t **_cent); 13 | extern int dir_quota_cache_update(cache_entry_t *cent, const quota_t *quota); 14 | extern int dir_quota_cache_create(const uint64_t quotaid, quota_t *quota); 15 | extern int dir_quota_cache_drop(const uint64_t quotaid); 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /yfs/include/file_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILE_PROTO_H__ 2 | #define __FILE_PROTO_H__ 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /yfs/include/file_table.h: -------------------------------------------------------------------------------- 1 | #ifndef __FILE_TABLE_H__ 2 | #define __FILE_TABLE_H__ 3 | 4 | #include "array_table.h" 5 | 6 | int get_empty_filetable(atable_t ftable, void *ptr); 7 | void *get_file(atable_t ftable, int fd); 8 | int put_file(atable_t ftable, int fd); 9 | int files_init(atable_t *ftable, uint32_t size); 10 | int files_destroy(atable_t ftable); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /yfs/include/flock.h: -------------------------------------------------------------------------------- 1 | /* 2 | *Date : 2017.09.13 3 | *Author : JinagYang 4 | */ 5 | #ifndef __FLOCK_H__ 6 | #define __FLOCK_H__ 7 | 8 | typedef struct { 9 | uint8_t type; // shared(readlock), exclusive(writelock), remove(unlock) 10 | uint64_t sid; // which server (nfs, samba...) requests/holds the lock 11 | uint64_t owner; // who requests/holds the lock 12 | uint64_t start; // initial location to lock 13 | uint64_t length; // num bytes to lock from start 14 | }uss_flock_t; 15 | 16 | typedef enum { 17 | USS_RDLOCK, 18 | USS_WRLOCK, 19 | USS_UNLOCK, 20 | }uss_flock_type_t; 21 | 22 | typedef enum { 23 | USS_SETFLOCK, 24 | USS_GETFLOCK, 25 | }uss_flock_op_t; 26 | 27 | //remove locks info with server id which disconnect from mds 28 | extern void flock_remove_sid_locks(IN const uint64_t sid); 29 | extern int flock_mds_init(void); 30 | extern int flock_mds_op(IN const fileid_t *fileid, 31 | IN uss_flock_op_t flock_op, 32 | INOUT uss_flock_t *plock); 33 | extern void ussflock_to_flock(IN const uss_flock_t *uss_flock, 34 | INOUT struct flock *flock); 35 | extern void flock_to_ussflock(IN const struct flock *flock, 36 | INOUT uss_flock_t *uss_flock); 37 | #endif -------------------------------------------------------------------------------- /yfs/include/group.h: -------------------------------------------------------------------------------- 1 | /* 2 | *Date : 2017.07.29 3 | *Author : jinxx 4 | */ 5 | 6 | #ifndef __GROUP_H__ 7 | #define __GROUP_H__ 8 | 9 | #define GROUP_PREFIX 1 10 | #define MAX_GROUP_KEY_LEN 512 11 | 12 | typedef struct { 13 | char gname[MAX_NAME_LEN]; 14 | gid_t gid; 15 | } group_t; 16 | 17 | typedef enum { 18 | GROUP_SET = 0, 19 | GROUP_GET, 20 | GROUP_REMOVE, 21 | GROUP_LIST, 22 | GROUP_INVALID_OP, 23 | } group_op_type_t; 24 | 25 | extern int group_set(const group_t *group); 26 | extern int group_get(const char *name, group_t *group); 27 | extern int group_remove(const char *name); 28 | extern int group_list(group_t **group, int *len); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /yfs/include/group_quota_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef _G_QUOTA_CACHE_H_ 2 | #define _G_QUOTA_CACHE_H_ 3 | 4 | #include 5 | #include "sdfs_quota.h" 6 | 7 | typedef struct { 8 | uint64_t volid; 9 | gid_t gid; 10 | }entry_group_key_t; 11 | 12 | typedef struct { 13 | entry_group_key_t key; 14 | quota_t quota; 15 | }group_quota_entry_t; 16 | 17 | extern int group_quota_cache_init(); 18 | extern int group_quota_cache_get(const gid_t gid, const uint64_t volid, cache_entry_t **_cent); 19 | extern int group_quota_cache_update(cache_entry_t *cent, const quota_t *quota); 20 | extern int group_quota_cache_create(const gid_t gid, const uint64_t volid, const quota_t *quota); 21 | extern int group_quota_cache_drop(const gid_t gid, const uint64_t volid); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /yfs/include/md_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD_PROTO_H__ 2 | #define __MD_PROTO_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "adt.h" 8 | #include "chk_proto.h" 9 | #include "disk_proto.h" 10 | #include "file_proto.h" 11 | #include "node_proto.h" 12 | #include "net_proto.h" 13 | #include "yfs_md.h" 14 | #include "sdfs_lib.h" 15 | #include "dbg.h" 16 | #include "sdfs_share.h" 17 | #include "user.h" 18 | #include "group.h" 19 | #include "flock.h" 20 | #include "sdfs_worm.h" 21 | 22 | typedef struct { 23 | uint64_t size; 24 | uint32_t volid; 25 | uint32_t __pad__; 26 | } volrept_t; 27 | 28 | typedef struct { 29 | uint32_t volreptnum; 30 | uint32_t __pad__; 31 | volrept_t volrept[0];/*chkjnl_t already aligned*/ 32 | } volinfo_t; 33 | 34 | #define NEWREP_NORMAL 0 35 | #define NEWREP_UNREG 1 36 | #define NEWREP_FORCE 2 37 | #endif 38 | -------------------------------------------------------------------------------- /yfs/include/node_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODE_PROTO_H__ 2 | #define __NODE_PROTO_H__ 3 | 4 | #if 0 5 | typedef struct { 6 | uint32_t id; 7 | uint32_t version; 8 | } nodeid_t; 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /yfs/include/option.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Nippon Telegraph and Telephone Corporation. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License version 6 | * 2 as published by the Free Software Foundation. 7 | * 8 | * You should have received a copy of the GNU General Public License 9 | * along with this program. If not, see . 10 | */ 11 | #ifndef __SD_OPTION_H__ 12 | #define __SD_OPTION_H__ 13 | 14 | #include 15 | #include 16 | 17 | struct sd_option { 18 | int ch; 19 | const char *name; 20 | bool has_arg; 21 | const char *desc; 22 | const char *help; 23 | }; 24 | 25 | struct option_parser { 26 | const char *option; 27 | int (*parser)(const char *); 28 | }; 29 | 30 | char *build_short_options(const struct sd_option *opts); 31 | struct option *build_long_options(const struct sd_option *opts); 32 | const char *option_get_help(const struct sd_option *, int); 33 | int option_parse(char *arg, const char *delim, struct option_parser *parsers); 34 | int option_parse_size(const char *value, uint64_t *ret); 35 | 36 | #define sd_for_each_option(opt, opts) \ 37 | for (opt = (opts); opt->name; opt++) 38 | 39 | #endif /* __SD_OPTION_H__ */ 40 | -------------------------------------------------------------------------------- /yfs/include/rep_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __REP_PROTO_H__ 2 | #define __REP_PROTO_H__ 3 | 4 | #define YFS_MIN_REP 2 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /yfs/include/user.h: -------------------------------------------------------------------------------- 1 | /* 2 | *Date : 2017.07.29 3 | *Author : jinxx 4 | */ 5 | #ifndef __USER_H__ 6 | #define __USER_H__ 7 | 8 | #define USER_PREFIX 0 9 | #define MAX_USER_KEY_LEN 4096 10 | 11 | typedef struct { 12 | char name[MAX_NAME_LEN]; 13 | char password[MAX_NAME_LEN]; 14 | uid_t uid; 15 | gid_t gid; 16 | } user_t; 17 | 18 | typedef enum { 19 | USER_SET = 0, 20 | USER_GET, 21 | USER_REMOVE, 22 | USER_LIST, 23 | USER_INVALID_OP, 24 | } user_op_type_t; 25 | 26 | typedef struct { 27 | user_t user; 28 | user_op_type_t opt; 29 | } user_op_t; 30 | 31 | extern int user_set(const user_t *user); 32 | extern int user_remove(const char *name); 33 | extern int user_get(const char *name, user_t *user); 34 | extern int user_list(user_t **user, int *count); 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /yfs/include/user_quota_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef _U_QUOTA_CACHE_H_ 2 | #define _U_QUOTA_CACHE_H_ 3 | 4 | #include 5 | #include "sdfs_quota.h" 6 | 7 | typedef struct { 8 | uint64_t volid; 9 | uid_t uid; 10 | }entry_user_key_t; 11 | 12 | typedef struct { 13 | entry_user_key_t key; 14 | quota_t quota; 15 | }user_quota_entry_t; 16 | 17 | extern int user_quota_cache_init(); 18 | extern int user_quota_cache_get(const uid_t uid, const uint64_t volid, cache_entry_t **_cent); 19 | extern int user_quota_cache_update(cache_entry_t *cent, const quota_t *quota); 20 | extern int user_quota_cache_create(const uid_t uid, const uint64_t volid, const quota_t *quota); 21 | extern int user_quota_cache_drop(const uid_t uid, const uint64_t volid); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /yfs/include/uss_sysstat.h: -------------------------------------------------------------------------------- 1 | #ifndef __USS_SYSSTAT_H__ 2 | #define __USS_SYSSTAT_H__ 3 | 4 | #include 5 | 6 | int uss_globestat(); 7 | int uss_mdsstat(); 8 | int uss_cdsstat(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /yfs/include/worm_cli_lib.h: -------------------------------------------------------------------------------- 1 | #ifndef __WORM_CLI_LIB_H__ 2 | #define __WORM_CLI_LIB_H__ 3 | 4 | #include "sdfs_worm.h" 5 | 6 | #if ENABLE_WORM 7 | extern int worm_init_wormclock_dir(fileid_t *_fileid); 8 | extern int worm_set_clock_time(const fileid_t *fileid, const time_t wormclock_timestamp); 9 | extern int worm_get_clock_time(const fileid_t *fileid, time_t *wormclock_timestamp); 10 | extern int worm_update_clock_time(void); 11 | extern int worm_set_file_attr(const fileid_t *fileid, worm_file_t *_worm_file); 12 | extern int worm_get_file_attr(const fileid_t *fileid, worm_file_t *_worm_file); 13 | extern int worm_remove_file_attr(const fileid_t *fileid); 14 | extern int worm_get_attr(const fileid_t *fileid, worm_t *_worm); 15 | extern int worm_set_attr(const fileid_t *fileid, worm_t *_worm); 16 | extern int worm_remove_attr(const fileid_t *fileid); 17 | extern worm_status_t worm_get_status(const fileid_t *fileid); 18 | extern worm_status_t convert_string_to_worm_status(const char *string); 19 | extern int worm_list_root_directory(void (*print_worm_root)(const worm_t *)); 20 | extern int get_wormfileid_by_fid_cli(const uint64_t fid, const fileid_t *subfileid, fileid_t *fileid); 21 | extern int worm_auth_valid(const char *username, const char *password); 22 | #endif 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /yfs/include/write_crc.h: -------------------------------------------------------------------------------- 1 | #ifndef __WRITE_CRC_H__ 2 | #define __WRITE_CRC_H__ 3 | 4 | #include "yfs_conf.h" 5 | #include "sdfs_buffer.h" 6 | 7 | int wcrc_drop(uint32_t _off, uint32_t _size, uint32_t *crc, int count); 8 | int wcrc_verify(uint32_t _off, uint32_t _size, const buffer_t *buf, 9 | const uint32_t *crc, int count); 10 | int wcrc_sum(uint32_t _off, uint32_t _size, const buffer_t *buf, 11 | uint32_t *crc, uint32_t *_count); 12 | int wcrc_extern(uint32_t _off, uint32_t _size, uint32_t *crc, int count, 13 | int (disk_read)(int, char *, int, int), int fd); 14 | int wcrc_count(uint32_t _off, uint32_t _size); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /yfs/include/xattr.h: -------------------------------------------------------------------------------- 1 | #ifndef __XATTR_H__ 2 | #define __XATTR_H__ 3 | 4 | //set xattr flag 5 | #define USS_XATTR_DEFAULT (0) 6 | #define USS_XATTR_CREATE (1 << 0) /* set value, fail if attr already exists */ 7 | #define USS_XATTR_REPLACE (1 << 1) /* set value, fail if attr does not exist */ 8 | #define USS_XATTR_INVALID (1 << 31) 9 | 10 | typedef struct { 11 | int (*set)(const fileid_t *fileid, const char *key, const void *value, 12 | size_t size, int flags); 13 | int (*get)(const fileid_t *fileid, const char *key, void *value, size_t *size); 14 | int (*remove)(const fileid_t *fileid, const char *key); 15 | int (*list)(const fileid_t *fileid, void *list, size_t *size); 16 | } xattr_op_t; 17 | 18 | typedef struct { 19 | int (*init)(void); 20 | int (*set)(const fileid_t *fileid, const char *key, const void *value, 21 | size_t size, int flags); 22 | int (*get)(const fileid_t *fileid, const char *key, void *value, size_t *size); 23 | int (*remove)(const fileid_t *fileid, const char *key); 24 | } xattr_queue_op_t; 25 | 26 | extern void xattr_removeall(IN const fileid_t *fileid); 27 | extern int xattr_queue_removeall(IN const fileid_t *fileid); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /yfs/include/yfs_chunk.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFS_CHUNK_H__ 2 | #define __YFS_CHUNK_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "chk_proto.h" 8 | #include "cd_proto.h" 9 | #include "ynet_rpc.h" 10 | #include "job.h" 11 | 12 | struct yfs_chunk { 13 | /* filled by mdc */ 14 | chkid_t chkid; 15 | uint64_t version; 16 | //uint32_t no; 17 | uint32_t rep; /* rep number */ 18 | uint32_t validrep; 19 | net_handle_t *nid; /* rep*nid */ 20 | time_t ltime; 21 | 22 | /* filled by ly */ 23 | int loaded; 24 | }; 25 | 26 | extern void yfs_chunk_dump(struct yfs_chunk *chk); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /yfs/include/yfs_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFS_CONF_H__ 2 | #define __YFS_CONF_H__ 3 | 4 | #include "sdfs_conf.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /yfs/include/yfs_dir.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFS_DIR_H__ 2 | #define __YFS_DIR_H__ 3 | 4 | #include "dir.h" 5 | 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /yfs/include/yfs_file.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFS_FILE_H__ 2 | #define __YFS_FILE_H__ 3 | 4 | #include 5 | 6 | #include "yfs_chunk.h" 7 | 8 | #endif /* __YFS_FILE_H__ */ 9 | -------------------------------------------------------------------------------- /yfs/include/yfs_limit.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFS_LIMIT_H__ 2 | #define __YFS_LIMIT_H__ 3 | 4 | #include "yfs_md.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /yfs/include/yfscli_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFSCLI_CONF_H__ 2 | #define __YFSCLI_CONF_H__ 3 | 4 | #include "yfs_conf.h" 5 | 6 | #define YFS_CDC_DIR_MEM_PRE "/dev/shm/sdfs/yfs/cdc" 7 | 8 | #define CDC_QLEN 256 9 | 10 | #define YFS_XATTR_REPLICA "replica" 11 | #define YFS_XATTR_CHKLEN "chklen" 12 | 13 | #define NR_FILETABLE 8192 * 4 14 | 15 | #define CACHE_LIST_LEN 32 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /yfs/libyfs/file_table.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | #define DBG_SUBSYS S_YFSLIB 7 | 8 | #include "yfscli_conf.h" 9 | #include "yfs_file.h" 10 | #include "ylib.h" 11 | #include "dbg.h" 12 | 13 | int get_empty_filetable(atable_t ftable, void *ptr) 14 | { 15 | int fd; 16 | 17 | fd = array_table_insert_empty(ftable, ptr); 18 | if (fd == 0) { 19 | array_table_remove(ftable, fd, (void *)&fd, NULL); 20 | fd = array_table_insert_empty(ftable, ptr); 21 | YASSERT(fd != 0); 22 | } 23 | 24 | return fd; 25 | } 26 | 27 | void *get_file(atable_t ftable, int fd) 28 | { 29 | return array_table_find(ftable, fd, (void *)&fd); 30 | } 31 | 32 | int put_file(atable_t ftable, int fd) 33 | { 34 | (void) array_table_remove(ftable, fd, (void *)&fd, NULL); 35 | 36 | return 0; 37 | } 38 | 39 | int files_init(atable_t *ftable, uint32_t size) 40 | { 41 | *ftable = array_create_table(NULL, size); 42 | if (*ftable) 43 | return 0; 44 | else 45 | return ENOMEM; 46 | } 47 | 48 | int files_destroy(atable_t ftable) 49 | { 50 | array_table_destroy(ftable); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /yfs/libyfs/group.c: -------------------------------------------------------------------------------- 1 | #define DBG_SUBSYS S_YFSLIB 2 | 3 | #include "md_lib.h" 4 | #include "dbg.h" 5 | #include "group.h" 6 | 7 | int group_set(const group_t *group) 8 | { 9 | int ret; 10 | 11 | ret = md_set_groupinfo(group); 12 | if (ret) 13 | GOTO(err_ret, ret); 14 | 15 | return 0; 16 | err_ret: 17 | return ret; 18 | } 19 | 20 | int group_get(const char *group_name, group_t *group) 21 | { 22 | int ret; 23 | 24 | ret = md_get_groupinfo(group_name, group); 25 | if (ret) 26 | GOTO(err_ret, ret); 27 | 28 | return 0; 29 | err_ret: 30 | return ret; 31 | } 32 | 33 | int group_remove(const char *group_name) 34 | { 35 | int ret; 36 | 37 | ret = md_remove_groupinfo(group_name); 38 | if (ret) 39 | GOTO(err_ret, ret); 40 | 41 | return 0; 42 | err_ret: 43 | return ret; 44 | } 45 | 46 | int group_list(group_t **group, int *len) 47 | { 48 | int ret; 49 | 50 | ret = md_list_groupinfo(group, len); 51 | if (ret) 52 | GOTO(err_ret, ret); 53 | 54 | return 0; 55 | err_ret: 56 | return ret; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /yfs/libyfs/posix_acl.h: -------------------------------------------------------------------------------- 1 | #ifndef CEPH_POSIX_ACL 2 | #define CEPH_POSIX_ACL 3 | 4 | #define ACL_EA_VERSION 0x0002 5 | 6 | #define ACL_USER_OBJ 0x01 7 | #define ACL_USER 0x02 8 | #define ACL_GROUP_OBJ 0x04 9 | #define ACL_GROUP 0x08 10 | #define ACL_MASK 0x10 11 | #define ACL_OTHER 0x20 12 | 13 | #define ACL_DEFAULT_EA_ENTRY_COUNT 6 14 | 15 | #define ACL_EA_ACCESS "system.posix_acl_access" 16 | #define ACL_EA_DEFAULT "system.posix_acl_default" 17 | 18 | typedef struct { 19 | uint16_t e_tag; 20 | uint16_t e_perm; 21 | uint32_t e_id; 22 | }acl_ea_entry; 23 | 24 | typedef struct { 25 | uint32_t a_version; 26 | acl_ea_entry a_entries[0]; 27 | } acl_ea_header; 28 | 29 | extern int posix_acl_check(const void *xattr, size_t size); 30 | extern int posix_acl_equiv_mode(const void *xattr, size_t size, mode_t *mode_p); 31 | extern int posix_acl_default_get(void *acl_buf, size_t acl_buf_size, mode_t mode); 32 | extern size_t posix_acl_ea_size(int count); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /yfs/libyfs/super.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DBG_SUBSYS S_YFSLIB 9 | 10 | #include "md_lib.h" 11 | #include "network.h" 12 | #include "sdfs_lib.h" 13 | #include "dbg.h" 14 | 15 | #if 1 16 | int ly_statvfs(const char *path, struct statvfs *svbuf) 17 | { 18 | int ret; 19 | fileid_t parent, fileid; 20 | char name[MAX_PATH_LEN]; 21 | 22 | ret = sdfs_splitpath(path, &parent, name); 23 | if (ret) 24 | GOTO(err_ret, ret); 25 | 26 | ret = sdfs_lookup(NULL, &parent, name, &fileid); 27 | if (ret) 28 | GOTO(err_ret, ret); 29 | 30 | ret = sdfs_statvfs(NULL, &fileid, svbuf); 31 | if (ret) 32 | GOTO(err_ret, ret); 33 | 34 | return 0; 35 | err_ret: 36 | return ret; 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /yfs/python/cds_robot/conf.py: -------------------------------------------------------------------------------- 1 | debug = True 2 | 3 | CDSDIR = '/sysy/yfs/cds' 4 | -------------------------------------------------------------------------------- /yfs/python/libyfs/Makefile: -------------------------------------------------------------------------------- 1 | PYLIB = `python-config --libs` 2 | PYINC = `python-config --includes` 3 | CFLAGS = -g -Werror -D_FILE_OFFSET_BITS=64 -D_REENTRANT -I../../../ylib/include -I ../../../ynet/include -I../../../yfs/include -I../../mdc 4 | CLIBS = -L/sysy/yfs/app/lib/ -lyfs -lynet -lylib -lcrypt -lrt 5 | 6 | all: yfs.so 7 | 8 | yfs.so: yfs.o 9 | gcc -shared -o $@ $^ $(PYLIB) $(CLIBS) 10 | 11 | yfs.o: yfs.c 12 | gcc -fpic -c $(CFLAGS) $(PYINC) $< 13 | 14 | clean: 15 | rm -f yfs.so yfs.o 16 | 17 | install: 18 | cp yfs.so /var/lib/python-support/python2.6 19 | -------------------------------------------------------------------------------- /yfs/python/test/test_yfs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | sys.path.append('../libyfs') 5 | import yfs 6 | 7 | def test_node(): 8 | yfs.mkdir('test', 777) 9 | print 'mkdir test' 10 | 11 | yfs.rmdir('test') 12 | print 'rmdir test' 13 | 14 | def main(): 15 | ret = yfs.init() 16 | print ret 17 | if ret != 0: 18 | print 'init failed' 19 | EXIT(1) 20 | 21 | print 'yfs init' 22 | test_node() 23 | yfs.destroy() 24 | print 'yfs_destroy' 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /yfs/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | #noinst_PROGRAMS = yfs_sanity 2 | 3 | #yfs_sanity_SOURCES = yfs_sanity.c 4 | 5 | AM_LDFLAGS = @LDFLAGS@ \ 6 | -L../../ylib/lib -lylib \ 7 | -L../../parser/lib -lparser \ 8 | -L../../ynet/build -lynet \ 9 | -L../build -lyfs \ 10 | -lpthread -lcrypt -luuid -laio -lssl 11 | -------------------------------------------------------------------------------- /yfs/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | ) 7 | link_directories(${PROJECT_BINARY_DIR}/lib) 8 | 9 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 10 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 11 | 12 | set(MOD_EXTRA_LIBS pthread aio crypt uuid ssl parser ylib ynet yfs) 13 | set(UTILS 14 | ychkstat 15 | ychmod 16 | ylogin 17 | yls 18 | ymkdir 19 | yping 20 | ypasswd 21 | yrep 22 | yrm 23 | yrmdir 24 | ystat 25 | ystatvfs 26 | yshutdown 27 | jnlfind 28 | yrecycle 29 | ylvm 30 | ychunk_merge 31 | ysetopt 32 | ychunk_check 33 | repcheck 34 | rebuild_cdsjnl 35 | cmd 36 | ytruncate 37 | cdsop_read) 38 | 39 | # ffc 40 | 41 | foreach(x ${UTILS}) 42 | message(STATUS "Util " ${x}) 43 | add_executable(${x} ${x}.c) 44 | target_link_libraries(${x} ${MOD_EXTRA_LIBS}) 45 | endforeach() 46 | 47 | install(TARGETS ${UTILS} 48 | RUNTIME DESTINATION app/bin) 49 | -------------------------------------------------------------------------------- /yfs/utils/newrep.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "configure.h" 9 | #include "sdfs_lib.h" 10 | #include "../libyfs/chunk.h" 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | int ret; 15 | uint32_t newrep; 16 | chkid_t chkid; 17 | 18 | if ((argc != 4)) { 19 | fprintf(stderr, "Usage: %s id> version> \n", argv[0]); 20 | exit(1); 21 | } 22 | 23 | chkid.id = atoi(argv[1]); 24 | chkid.version = atoi(argv[2]); 25 | newrep = atoi(argv[3]); 26 | 27 | ret = conf_init(YFS_CONFIGURE_FILE); 28 | if (ret) 29 | exit(1); 30 | 31 | ret = ly_init_simple("newrep"); 32 | if (ret) { 33 | fprintf(stderr, "ly_init() %s\n", strerror(ret)); 34 | exit(1); 35 | } 36 | 37 | ret = ly_newrep(&chkid, newrep); 38 | if (ret) { 39 | fprintf(stderr, "ly_newrep() %s\n", strerror(ret)); 40 | exit(1); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /yfs/utils/uss.cdstat.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "configure.h" 9 | #include "uss_sysstat.h" 10 | #include "sdfs_lib.h" 11 | #include "dbg.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | int ret; 16 | 17 | (void) argc; 18 | (void) argv; 19 | 20 | dbg_info(0); 21 | 22 | ret = conf_init(YFS_CONFIGURE_FILE); 23 | if (ret) 24 | GOTO(err_ret, ret); 25 | 26 | ret = ly_init_simple("uss.cdstat"); 27 | if (ret) 28 | GOTO(err_ret, ret); 29 | 30 | ret = uss_globestat(); 31 | if (ret) 32 | GOTO(err_ret, ret); 33 | 34 | ret = uss_cdsstat(); 35 | if (ret) 36 | GOTO(err_ret, ret); 37 | 38 | return 0; 39 | err_ret: 40 | return ret; 41 | } 42 | -------------------------------------------------------------------------------- /yfs/utils/uss.mdstat.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "configure.h" 9 | #include "uss_sysstat.h" 10 | #include "sdfs_lib.h" 11 | #include "dbg.h" 12 | 13 | void print_clusterid(const char *clusterid) 14 | { 15 | printf("cluster id : %s\n", clusterid); 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | int ret; 21 | 22 | (void) argc; 23 | (void) argv; 24 | 25 | dbg_info(0); 26 | 27 | ret = conf_init(YFS_CONFIGURE_FILE); 28 | if (ret) 29 | GOTO(err_ret, ret); 30 | 31 | ret = ly_init_simple("uss.mdstat"); 32 | if (ret) 33 | GOTO(err_ret, ret); 34 | 35 | ret = uss_globestat(); 36 | if (ret) 37 | GOTO(err_ret, ret); 38 | 39 | UNIMPLEMENTED(__WARN__); 40 | #if 0 41 | ret = uss_mdsstat(); 42 | if (ret) 43 | GOTO(err_ret, ret); 44 | #endif 45 | 46 | return 0; 47 | err_ret: 48 | return ret; 49 | } 50 | -------------------------------------------------------------------------------- /yfs/utils/ystatchk.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "configure.h" 8 | #include "chk_proto.h" 9 | #include "sdfs_lib.h" 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | int ret; 14 | unsigned long long chkid; 15 | unsigned long version; 16 | 17 | if(argc < 3) 18 | { 19 | printf("usage:%s id version\n", argv[0]); 20 | } 21 | 22 | chkid = strtoull(argv[1], NULL, 10); 23 | version = strtoul(argv[2], NULL, 10); 24 | 25 | ret = conf_init(YFS_CONFIGURE_FILE); 26 | if (ret) 27 | exit(1); 28 | 29 | ret = ly_init_simple("ystatchk"); 30 | if(ret) { 31 | fprintf(stderr, "ly_init() %s\n", strerror(ret)); 32 | } 33 | 34 | ret = ly_statchk(chkid, version); 35 | if(ret) { 36 | fprintf(stderr, "ly_printchk() %s\n", strerror(ret)); 37 | } 38 | 39 | ret = ly_destroy(); 40 | if (ret) { 41 | fprintf(stderr, "ly_destroy() %s\n", strerror(ret)); 42 | exit(1); 43 | } 44 | 45 | return 0; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /yftp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /yftp/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /yftp/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([yftp],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -Werror -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../ynet/include -I../../ylib/include/ -I../../yfs/include/" 21 | 22 | LIBS=-lpthread 23 | 24 | AC_CHECK_FUNCS([pthread_rwlock_init]) 25 | 26 | subdirs=" \ 27 | include \ 28 | src \ 29 | " 30 | 31 | AC_SUBST(subdirs) 32 | 33 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 34 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 35 | 36 | AC_CONFIG_FILES([ \ 37 | Makefile \ 38 | include/Makefile \ 39 | src/Makefile \ 40 | ]) 41 | 42 | AC_OUTPUT 43 | -------------------------------------------------------------------------------- /yftp/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yftp/include/Makefile.am -------------------------------------------------------------------------------- /yftp/include/yftp_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YFTP_CONF_H__ 2 | #define __YFTP_CONF_H__ 3 | 4 | #define YFTP_SERVICE_DEF "21" 5 | #define YFTP_QLEN_DEF 256 6 | 7 | #define YFTP_LOCKFILE "/dev/shm/uss/yftp/lock/yftp" 8 | #define YFTP_PIDFILE "/dev/shm/uss/yftp/lock/yftp.pid" 9 | 10 | #define YFTP_LOGFILE "/var/log/yftp.log" 11 | 12 | #define YFTP_EPOLL_SIZE 32 13 | 14 | #define YFTP_THR_MAX 1024 15 | 16 | #define YFTP_MAX_CMD_LINE 4096 17 | #define YFTP_MAX_PATH_LINE 4096 18 | #define YFTP_MAX_DIR_BUFSIZE 16384 19 | 20 | #define YFTP_IDLE_SESSION_TIMEOUT (1000 * 1000) 21 | 22 | #define YFTP_CHROOT "/" 23 | 24 | /* "\012" "\n" */ 25 | 26 | #define FTP_CMD_END '\012' 27 | 28 | #define YFTP_PASV_SERVICE_BASE "2021" 29 | #define YFTP_PASV_SERVICE_RANG YFTP_THR_MAX 30 | 31 | /* XXX max upload rate -gj */ 32 | #define YFTP_MAX_RATE 0 33 | 34 | #define SERVER_SOFTWARE "yftpd/0.01 09oct2006" 35 | #define SERVER_URL "http://www.joybeta.com/" 36 | 37 | #define YFTP_ACCESS_LOG 0 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /yftp/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ${PROJECT_SOURCE_DIR}/ynet/include 5 | ${PROJECT_SOURCE_DIR}/yfs/include 6 | ${PROJECT_SOURCE_DIR}/yftp/include 7 | ) 8 | link_directories(${PROJECT_BINARY_DIR}/lib) 9 | 10 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/sbin) 11 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 12 | 13 | set(MOD_EXTRA_LIBS pthread aio crypt uuid ssl parser ylib ynet yfs) 14 | 15 | set(MOD_SRCS 16 | main.c 17 | ftpfeatures.c 18 | prelogin.c 19 | postlogin.c 20 | cmdio.c 21 | dataio.c 22 | session.c) 23 | 24 | add_executable(yftp_server ${MOD_SRCS}) 25 | target_link_libraries(yftp_server ${MOD_EXTRA_LIBS}) 26 | 27 | install(TARGETS yftp_server 28 | RUNTIME DESTINATION app/sbin) 29 | -------------------------------------------------------------------------------- /yftp/src/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS=yftp_server 2 | 3 | yftp_server_SOURCES = \ 4 | main.c \ 5 | ftpfeatures.c \ 6 | prelogin.c \ 7 | postlogin.c \ 8 | cmdio.c \ 9 | dataio.c \ 10 | session.c 11 | 12 | AM_LDFLAGS = @LDFLAGS@ \ 13 | -L../../parser/lib -lparser \ 14 | -L../../yfs/build -lyfs \ 15 | -L../../ynet/build -lynet \ 16 | -L../../ylib/lib -lylib \ 17 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl 18 | -------------------------------------------------------------------------------- /yftp/src/cmdio.h: -------------------------------------------------------------------------------- 1 | #ifndef __CMDIO_H__ 2 | #define __CMDIO_H__ 3 | 4 | #include "session.h" 5 | #include "dbg.h" 6 | 7 | extern int cmdio_write(struct yftp_session *, int status, const char *msg); 8 | 9 | extern int cmdio_get_cmd_and_arg(struct yftp_session *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /yftp/src/dataio.h: -------------------------------------------------------------------------------- 1 | #ifndef __DATAIO_H__ 2 | #define __DATAIO_H__ 3 | 4 | #include "session.h" 5 | 6 | extern int dataio_get_pasv_fd(struct yftp_session *ys, int *pfd); 7 | 8 | extern int dataio_transfer_dir(struct yftp_session *ys, int rfd, char *path, 9 | char *opt, char *filter, int full_details); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /yftp/src/ftpfeatures.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define DBG_SUBSYS S_YFTP 4 | 5 | #include "cmdio.h" 6 | #include "features.h" 7 | #include "ftpcodes.h" 8 | #include "session.h" 9 | #include "dbg.h" 10 | 11 | int handle_feat(struct yftp_session *ys) 12 | { 13 | int ret; 14 | 15 | ret = cmdio_write(ys, 0, "211-Features:"); 16 | ret = cmdio_write(ys, 0, " EPSV\r\n"); 17 | ret = cmdio_write(ys, 0, " MDTM\r\n"); 18 | ret = cmdio_write(ys, 0, " PASV\r\n"); 19 | ret = cmdio_write(ys, 0, " REST\r\n"); 20 | ret = cmdio_write(ys, 0, " STREAM\r\n"); 21 | ret = cmdio_write(ys, 0, " SIZE\r\n"); 22 | ret = cmdio_write(ys, 0, " TVFS\r\n"); 23 | ret = cmdio_write(ys, 0, " UTF8\r\n"); 24 | ret = cmdio_write(ys, FTP_FEAT, "End"); 25 | if (ret) 26 | GOTO(err_ret, ret); 27 | 28 | return 0; 29 | err_ret: 30 | return ret; 31 | } 32 | -------------------------------------------------------------------------------- /yftp/src/ftpfeatures.h: -------------------------------------------------------------------------------- 1 | #ifndef __FEATURES_H__ 2 | #define __FEATURES_H__ 3 | 4 | #include "session.h" 5 | 6 | extern int handle_feat(struct yftp_session *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /yftp/src/postlogin.h: -------------------------------------------------------------------------------- 1 | #ifndef __POSTLOGIN_H__ 2 | #define __POSTLOGIN_H__ 3 | 4 | #include "session.h" 5 | 6 | extern int postlogin_process(struct yftp_session *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /yftp/src/prelogin.h: -------------------------------------------------------------------------------- 1 | #ifndef __PRELOGIN_H__ 2 | #define __PRELOGIN_H__ 3 | 4 | #include "session.h" 5 | 6 | extern int emit_greeting(struct yftp_session *); 7 | extern int ftp_handle(struct yftp_session *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /yftp/src/session.h: -------------------------------------------------------------------------------- 1 | #ifndef __SESSION_H__ 2 | #define __SESSION_H__ 3 | 4 | #include 5 | 6 | #include "sdfs_conf.h" 7 | #include "yftp_conf.h" 8 | #define SESSION_READONLY 0 9 | #define SESSION_READWRITE 0xFF 10 | 11 | struct yftp_session { 12 | int epoll_fd; 13 | int ctrl_fd; 14 | int pasv_sd; 15 | 16 | char ctrl_line[YFTP_MAX_CMD_LINE + 1]; 17 | char *cmd; 18 | char *arg; 19 | 20 | char user[YFTP_MAX_CMD_LINE + 1]; 21 | uint32_t uid; 22 | uint32_t mode; 23 | char *fakedir; 24 | 25 | char pwd[MAX_PATH_LEN + 1]; 26 | 27 | char rnfr_filename[MAX_PATH_LEN + 1]; 28 | 29 | int is_ascii; 30 | 31 | uint64_t offset; 32 | }; 33 | 34 | extern long yftp_session_running; 35 | 36 | extern int session_init(struct yftp_session *, int ctrl_fd); 37 | extern int session_destroy(struct yftp_session *); 38 | extern int session_clearpasv(struct yftp_session *); 39 | extern int session_pasvactive(struct yftp_session *); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /yfuse/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /yfuse/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([fuse],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | AC_CHECK_FUNCS(xdr_u_long xdr_uint32) 11 | 12 | case $target_os in 13 | *linux*) arch=linux;; 14 | *bsd*) arch=bsd;; 15 | *) arch=unknown;; 16 | esac 17 | 18 | if test "$ac_env_CFLAGS_set" != set; then 19 | CFLAGS="-Wall -Werror -g" 20 | fi 21 | 22 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../ynet/include -I../../ylib/include/ -I../../yfs/include/" 23 | 24 | subdirs=" \ 25 | include \ 26 | src \ 27 | " 28 | 29 | AC_SUBST(subdirs) 30 | 31 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 32 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 33 | 34 | LIBS=-lpthread 35 | 36 | AC_CHECK_FUNCS([pthread_rwlock_init]) 37 | 38 | AC_CONFIG_FILES([ \ 39 | Makefile \ 40 | include/Makefile \ 41 | src/Makefile \ 42 | ]) 43 | 44 | AC_OUTPUT 45 | -------------------------------------------------------------------------------- /yfuse/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yfuse/include/Makefile.am -------------------------------------------------------------------------------- /yfuse/readme: -------------------------------------------------------------------------------- 1 | 这个链接里面列出了各个函数说明 2 | https://fossies.org/dox/fuse-2.9.7/structfuse__operations.html#a4dd366b9f74ead6927fb75afb91863bc 3 | -------------------------------------------------------------------------------- /yfuse/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS=yfuse 2 | 3 | yfuse_SOURCES = \ 4 | main.c 5 | 6 | AM_LDFLAGS = @LDFLAGS@ \ 7 | -L../../parser/lib -lparser \ 8 | -L../../yfs/build -lyfs \ 9 | -L../../ynet/build -lynet \ 10 | -L../../ylib/lib -lylib \ 11 | -L/usr/local/lib -lfuse3 \ 12 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl 13 | -------------------------------------------------------------------------------- /yfuse3/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /yfuse3/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([fuse3],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | AC_CHECK_FUNCS(xdr_u_long xdr_uint32) 11 | 12 | case $target_os in 13 | *linux*) arch=linux;; 14 | *bsd*) arch=bsd;; 15 | *) arch=unknown;; 16 | esac 17 | 18 | if test "$ac_env_CFLAGS_set" != set; then 19 | CFLAGS="-Wall -Werror -g" 20 | fi 21 | 22 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../ynet/include -I../../ylib/include/ -I../../yfs/include/" 23 | 24 | subdirs=" \ 25 | include \ 26 | src \ 27 | " 28 | 29 | AC_SUBST(subdirs) 30 | 31 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 32 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 33 | 34 | LIBS=-lpthread 35 | 36 | AC_CHECK_FUNCS([pthread_rwlock_init]) 37 | 38 | AC_CONFIG_FILES([ \ 39 | Makefile \ 40 | include/Makefile \ 41 | src/Makefile \ 42 | ]) 43 | 44 | AC_OUTPUT 45 | -------------------------------------------------------------------------------- /yfuse3/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yfuse3/include/Makefile.am -------------------------------------------------------------------------------- /yfuse3/readme: -------------------------------------------------------------------------------- 1 | 这个链接里面列出了各个函数说明 2 | https://fossies.org/dox/fuse-2.9.7/structfuse__operations.html#a4dd366b9f74ead6927fb75afb91863bc 3 | -------------------------------------------------------------------------------- /yfuse3/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS=yfuse 2 | 3 | yfuse_SOURCES = \ 4 | main.c 5 | 6 | AM_LDFLAGS = @LDFLAGS@ \ 7 | -L../../parser/lib -lparser \ 8 | -L../../yfs/build -lyfs \ 9 | -L../../ynet/build -lynet \ 10 | -L../../ylib/lib -lylib \ 11 | -L/usr/local/lib -lfuse3 \ 12 | -lpthread -lcrypt -lcrypto -luuid -laio -lssl 13 | -------------------------------------------------------------------------------- /ylib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(lib) 2 | 3 | -------------------------------------------------------------------------------- /ylib/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | 6 | 7 | test: 8 | ./tests/array_test -------------------------------------------------------------------------------- /ylib/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([ylib],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | AM_MAINTAINER_MODE([enable]) 11 | 12 | case $target_os in 13 | *linux*) arch=linux;; 14 | *bsd*) arch=bsd;; 15 | *) arch=unknown;; 16 | esac 17 | 18 | if test "$ac_env_CFLAGS_set" != set; then 19 | CFLAGS="-Wall -W -g" 20 | fi 21 | 22 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include" 23 | 24 | LIBS="-lpthread" 25 | 26 | AC_CHECK_FUNCS([pthread_rwlock_init]) 27 | 28 | subdirs=" \ 29 | include \ 30 | lib \ 31 | tests \ 32 | " 33 | 34 | AC_SUBST(subdirs) 35 | 36 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 37 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 38 | 39 | AC_CONFIG_FILES([ \ 40 | Makefile \ 41 | include/Makefile \ 42 | lib/Makefile \ 43 | tests/Makefile \ 44 | ]) 45 | 46 | AC_OUTPUT 47 | -------------------------------------------------------------------------------- /ylib/include/Makefile.am: -------------------------------------------------------------------------------- 1 | include_HEADERS = \ 2 | dbg.h \ 3 | ylog.h 4 | -------------------------------------------------------------------------------- /ylib/include/analysis.h: -------------------------------------------------------------------------------- 1 | #ifndef __ANALYSIS_H__ 2 | #define __ANALYSIS_H__ 3 | 4 | #include "hash_table.h" 5 | #include "job.h" 6 | #include "ylock.h" 7 | 8 | #define ANALYSIS_QUEUE_MAX (8192 * 100) 9 | 10 | typedef struct { 11 | int count; 12 | struct { 13 | char name[MAX_NAME_LEN]; 14 | uint64_t time; 15 | } array[ANALYSIS_QUEUE_MAX]; 16 | } analysis_queue_t; 17 | 18 | typedef struct { 19 | struct list_head hook; 20 | char name[MAX_NAME_LEN]; 21 | int private; 22 | hashtable_t tab; 23 | analysis_queue_t *queue; 24 | analysis_queue_t *new_queue; 25 | sy_spinlock_t queue_lock; 26 | sy_spinlock_t tab_lock; 27 | } analysis_t; 28 | 29 | typedef struct { 30 | char name[MAX_NAME_LEN]; 31 | } analysis_entry_t; 32 | 33 | extern analysis_t *default_analysis; 34 | 35 | int analysis_create(analysis_t **_ana, const char *_name, int private); 36 | int analysis_dumpall(void); 37 | int analysis_queue(analysis_t *ana, const char *name, const char *type, uint64_t _time); 38 | int analysis_private_create(const char *_name); 39 | int analysis_init(void); 40 | int analysis_dump(const char *tab, const char *name, char *buf); 41 | int analysis_private_queue(const char *_name, const char *type, uint64_t _time); 42 | void analysis_private_destroy(); 43 | void analysis_merge(void *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /ylib/include/array_table.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARRAY_TABLE_H__ 2 | #define __ARRAY_TABLE_H__ 3 | 4 | #include "ylock.h" 5 | 6 | struct atable_entry { 7 | sy_rwlock_t rwlock; 8 | void *value; 9 | }; 10 | 11 | typedef struct atable { 12 | int nr_array; 13 | int max_array; 14 | 15 | int array_no; 16 | int (*compare_func)(void *, void *); 17 | struct atable_entry array[0]; 18 | } *atable_t; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ylib/include/base64_urlsafe.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file re_base64.h Interface to Base64 encoding/decoding functions 3 | * 4 | * Copyright (C) 2010 Creytiv.com 5 | */ 6 | 7 | #ifndef B64_H_ 8 | #define B64_H_ (1) 9 | 10 | #include 11 | #include 12 | 13 | int b64_encode(const uint8_t *in, size_t ilen, char *out, size_t *olen); 14 | 15 | int b64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen); 16 | 17 | int urlsafe_b64_encode(const uint8_t *in, size_t ilen, char *out, size_t *olen); 18 | 19 | int urlsafe_b64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen); 20 | 21 | #endif // B64_H_ 22 | -------------------------------------------------------------------------------- /ylib/include/bh.h: -------------------------------------------------------------------------------- 1 | #ifndef __BITMAP_H__ 2 | #define __BITMAP_H__ 3 | 4 | #include "sdfs_conf.h" 5 | #include "dbg.h" 6 | 7 | int bh_init(); 8 | int bh_register(const char *name, int (*_exec)(void *), void *args, int step); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ylib/include/bmap.h: -------------------------------------------------------------------------------- 1 | #ifndef __BMAP_H 2 | #define __BMAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct { 9 | uint32_t nr_one; 10 | uint32_t size; 11 | uint32_t len; 12 | char *bits; 13 | } bmap_t; 14 | 15 | int bmap_create(bmap_t *bmap, uint32_t size); 16 | int bmap_destroy(bmap_t *bmap); 17 | int bmap_set(bmap_t *bmap, uint32_t off); 18 | int bmap_get(const bmap_t *bmap, uint32_t off); 19 | int bmap_del(bmap_t *bmap, uint32_t off); 20 | int bmap_full(const bmap_t *bmap); 21 | void bmap_load(bmap_t *bmap, char *opaque, int len); 22 | int bmap_get_empty(bmap_t *bmap); 23 | void bmap_clean(bmap_t *bmap); 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /ylib/include/errno_extern.h: -------------------------------------------------------------------------------- 1 | #ifndef __ERRNO_EXTERN_H__ 2 | #define __ERRNO_EXTERN_H__ 3 | 4 | #define EEOF 500 /*end of file*/ 5 | #define EANOTHER 501 /*try another*/ 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /ylib/include/fnotify.h: -------------------------------------------------------------------------------- 1 | #ifndef __FNOTIFY_H__ 2 | #define __FNOTIFY_H__ 3 | 4 | #include 5 | #include "sdfs_conf.h" 6 | 7 | typedef int (*fnotify_callback)(void *context, uint32_t mask); 8 | 9 | int fnotify_register(const char *path, fnotify_callback mod_callback, 10 | fnotify_callback del_callback, void *context); 11 | int fnotify_create(const char *path, const char *value, 12 | int (*callback)(const char *buf, uint32_t flag), 13 | uint32_t flag); 14 | int fnotify_unregister(const char *path); 15 | int fnotify_init(void); 16 | 17 | int quorum_fnotify_register(const char *path, fnotify_callback mod_callback, fnotify_callback del_callback, void *context); 18 | int quorum_fnotify_unregister(int md); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ylib/include/hash_table.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASH_TABLE_H__ 2 | #define __HASH_TABLE_H__ 3 | 4 | /* shamlessly stolean from http://www.sf.net/projects/sandiaportals/ */ 5 | 6 | #include 7 | 8 | #include "sdfs_conf.h" 9 | 10 | typedef struct hashtable_entry { 11 | uint32_t key; 12 | void *value; 13 | struct hashtable_entry *next; 14 | } *hashtable_entry_t; 15 | 16 | typedef struct hashtable { 17 | char name[MAX_NAME_LEN]; 18 | unsigned int size; 19 | unsigned int num_of_entries; 20 | int (*compare_func)(const void *, const void *); 21 | uint32_t (*key_func)(const void *); 22 | hashtable_entry_t *entries; 23 | } *hashtable_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /ylib/include/heap.h: -------------------------------------------------------------------------------- 1 | #ifndef __HEAP_H__ 2 | #define __HEAP_H__ 3 | 4 | #include "ylock.h" 5 | 6 | #define HEAP_MAX_SIZE 4096 7 | 8 | typedef int (*gt_func)(const void *, const void *); 9 | typedef int (*heap_drop_func)(const void *); 10 | typedef void (*heap_print_func)(const void *); 11 | 12 | struct heap_head_t { 13 | void *data; 14 | }; 15 | 16 | struct heap_t { 17 | gt_func gt; 18 | heap_drop_func drop; 19 | heap_print_func print; 20 | 21 | uint32_t capacity; 22 | 23 | uint32_t size; 24 | 25 | sy_rwlock_t size_rwlock; 26 | struct heap_head_t *element[HEAP_MAX_SIZE]; 27 | }; 28 | 29 | int heap_init(struct heap_t *heap, gt_func gt, heap_drop_func drop, 30 | heap_print_func print, uint32_t max_element, void *min); 31 | int heap_insert(struct heap_t *heap, void *data); 32 | int heap_pop(struct heap_t *heap, void **data); 33 | void heap_print(struct heap_t *heap); 34 | uint32_t heap_len(struct heap_t *heap); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ylib/include/htable.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTABLE_R_H__ 2 | #define __HTABLE_R_H__ 3 | 4 | #include "sdfs_list.h" 5 | #include "ylock.h" 6 | 7 | typedef struct { 8 | uint32_t curlen; 9 | sy_rwlock_t rwlock; 10 | struct list_head head; 11 | } htable_head_t; 12 | 13 | typedef struct { 14 | int (*cmp)(const void *,const void *); 15 | uint32_t (*hash)(const void *); 16 | uint32_t group; 17 | htable_head_t array[0]; 18 | } htable_t; 19 | 20 | int htable_insert(htable_t *htable, const void *key, void *value); 21 | int htable_create(htable_t **htable, uint32_t group, 22 | int (*cmp_func)(const void *,const void *), 23 | uint32_t (*hash_func)(const void *)); 24 | int htable_drop(htable_t *htable, const void *key, void **value); 25 | int htable_iterator_remove(htable_t *htable, int (*remove)(void *, void *), 26 | void *arg); 27 | int htable_get(htable_t *htable, const void *key, void **buf); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ylib/include/job_tracker.h: -------------------------------------------------------------------------------- 1 | #ifndef __JOBTRACKER_H__ 2 | #define __JOBTRACKER_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_list.h" 8 | #include "job.h" 9 | #include "analysis.h" 10 | #include "ylock.h" 11 | 12 | 13 | typedef struct { 14 | struct list_head list; 15 | void *parent; 16 | sem_t sem; 17 | sem_t exit_sem; 18 | int idx; 19 | int length; /* NOT required */ 20 | sy_spinlock_t lock; 21 | int pipe[2]; 22 | } job_head_t; 23 | 24 | typedef struct { 25 | int size; 26 | int running; 27 | char name[MAX_NAME_LEN]; 28 | job_head_t array[0]; 29 | } jobtracker_t; 30 | 31 | extern jobtracker_t *jobtracker; 32 | 33 | int jobtracker_create(jobtracker_t **jobtracker, int size, const char *name); 34 | int jobtracker_insert(job_t *job); 35 | int jobtracker_jobnum(jobtracker_t *jobtracker, uint32_t *jobnum); 36 | int jobtracker_exit_wait(jobtracker_t *jobtracker); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ylib/include/kv.h: -------------------------------------------------------------------------------- 1 | #ifndef __KV_H__ 2 | #define __KV_H__ 3 | 4 | #include "hash_table.h" 5 | #include "sdfs_lib.h" 6 | 7 | typedef struct { 8 | hashtable_t tab; 9 | struct list_head list; 10 | } kv_ctx_t; 11 | 12 | void kv_expire(kv_ctx_t *ctx); 13 | int kv_create(kv_ctx_t **_ctx); 14 | int kv_get(kv_ctx_t *ctx, const char *key, void *value, int *valuelen); 15 | int kv_set(kv_ctx_t *ctx, const char *key, const void *value, int valuelen, int flag, int ttl); 16 | void kv_destory(kv_ctx_t *ctx); 17 | void kv_iterator(kv_ctx_t *ctx, func1_t func, void *arg); 18 | 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /ylib/include/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef __MD5_H 2 | #define __MD5_H 3 | 4 | #include 5 | #include 6 | 7 | typedef unsigned char *POINTER; /* POINTER defines a generic pointer type */ 8 | typedef unsigned short int UINT2; /* UINT2 defines a two byte word */ 9 | typedef unsigned long int UINT4; /* UINT4 defines a four byte word */ 10 | 11 | typedef struct { 12 | UINT4 state[4]; /* state (ABCD) */ 13 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 14 | unsigned char buffer[64]; /* input buffer */ 15 | } MD5_CTX; 16 | 17 | //#define MAX_BUF_LEN (1024 * 64) 18 | 19 | void MD5Init (MD5_CTX *context); 20 | void MD5Update(MD5_CTX *context, unsigned char *input,unsigned int inputLen); 21 | void MD5Final (unsigned char digest[16], MD5_CTX *context); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /ylib/include/newdef.h: -------------------------------------------------------------------------------- 1 | #ifndef __NEWDEF_H__ 2 | #define __NEWDEF_H__ 3 | 4 | 5 | 6 | #define IO_WARN ((gloconf.rpc_timeout / 2) * 1000 * 1000) 7 | #define IO_INFO ((1) * 1000 * 1000) 8 | 9 | #if 0 10 | #define IO_FUNC __attribute__((section(".xiop"))) 11 | #else 12 | #define IO_FUNC 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ylib/include/nls.h: -------------------------------------------------------------------------------- 1 | #ifndef __NLS_H__ 2 | #define __NLS_H__ 3 | 4 | #include 5 | 6 | /* unicode character */ 7 | typedef uint16_t uchar_t; 8 | 9 | struct nls_table { 10 | char *charset; 11 | char *alias; 12 | 13 | int (*uni2char) (uchar_t uni, int boundlen, unsigned char *out, 14 | int *outlen); 15 | int (*char2uni) (const unsigned char *rawstring, int boundlen, 16 | uchar_t *uni, int *outlen); 17 | 18 | unsigned char *charset2lower; 19 | unsigned char *charset2upper; 20 | 21 | struct nls_table *next; 22 | }; 23 | 24 | /* this value hold the maximum octet of charset */ 25 | #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /ylib/include/nodectl.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODECTL_H__ 2 | #define __NODECTL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "fnotify.h" 10 | 11 | 12 | int nodectl_get_int(const char *key, const char *_default); 13 | int nodectl_get(const char *key, char *value, const char *_default); 14 | int nodectl_set(const char *key, const char *value); 15 | int nodectl_register(const char *key, const char *_default, fnotify_callback mod_callback, 16 | fnotify_callback del_callback, void *context); 17 | int nodectl_unregister(const char *key); 18 | void nodectl_unlink(const char *key); 19 | 20 | #endif 21 | 22 | 23 | -------------------------------------------------------------------------------- /ylib/include/pipe_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef __PIPE_POOL_H__ 2 | #define __PIPE_POOL_H__ 3 | 4 | #include 5 | #include 6 | 7 | 8 | extern int ppool(int idx, int io); 9 | int ppool_put(int *no, int len); 10 | int ppool_get(); 11 | int ppool_init(int size); 12 | void ppool_status(); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /ylib/include/plock.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLOCK_H__ 2 | #define __PLOCK_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_list.h" 8 | 9 | #if 1 10 | #define PLOCK_NEW 11 | #endif 12 | 13 | #ifdef PLOCK_NEW 14 | 15 | typedef struct { 16 | //pthread_rwlock_t lock; 17 | 18 | 19 | struct list_head queue; 20 | 21 | int writer; 22 | int readers; 23 | uint32_t priority; 24 | int thread; 25 | #if LOCK_DEBUG 26 | int32_t count; 27 | uint32_t last_unlock; 28 | char name[MAX_LOCK_NAME]; 29 | #endif 30 | } plock_t; 31 | 32 | #else 33 | 34 | typedef struct { 35 | pthread_rwlock_t lock; 36 | struct list_head queue; 37 | sy_spinlock_t spin; 38 | uint32_t priority; 39 | int thread; 40 | #if LOCK_DEBUG 41 | int32_t count; 42 | uint32_t last_unlock; 43 | #endif 44 | } plock_t; 45 | 46 | #endif 47 | 48 | /* plock.c */ 49 | extern int plock_init(plock_t *rwlock, const char *name); 50 | extern int plock_destroy(plock_t *rwlock); 51 | extern int plock_rdlock(plock_t *rwlock); 52 | extern int plock_tryrdlock(plock_t *rwlock); 53 | extern int plock_wrlock(plock_t *rwlock); 54 | extern int plock_trywrlock(plock_t *rwlock); 55 | extern void plock_unlock(plock_t *rwlock); 56 | extern int plock_timedwrlock(plock_t *rwlock, int sec); 57 | extern int plock_wrlock_prio(plock_t *rwlock, int prio); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /ylib/include/privilege.h: -------------------------------------------------------------------------------- 1 | #ifndef __PRIVILEGE_H__ 2 | #define __PRIVILEGE_H__ 3 | extern int grant(const char* username, const char *group); 4 | #endif 5 | -------------------------------------------------------------------------------- /ylib/include/proc.h: -------------------------------------------------------------------------------- 1 | #ifndef __PROC_H__ 2 | #define __PROC_H__ 3 | 4 | #include 5 | #include "sdfs_conf.h" 6 | 7 | #define PROC_MONITOR_ON 0 8 | 9 | typedef int (*proc_cb_fn)(void *, char *, uint32_t); 10 | 11 | typedef struct proc_node { 12 | int key; /* hash table key */ 13 | void *target; /* pointer to the variable */ 14 | char buf[1024]; /* current value of *target, in format char* */ 15 | uint32_t extra; /* extra arguments */ 16 | char path[MAX_PATH_LEN]; /* path of the file which to be monitored */ 17 | proc_cb_fn parse; /* funtion to parse value */ 18 | struct proc_node *next; /* pointer to next node */ 19 | } proc_node_t; 20 | 21 | typedef struct hash_table { 22 | proc_node_t **entrys; 23 | int size; 24 | int entrys_num; 25 | int (*hash)(int); 26 | } hash_table_t; 27 | 28 | extern int proc_init(); 29 | extern int proc_destroy(); 30 | extern int proc(char *path, void *target, char *buf, uint32_t extra, proc_cb_fn parse); 31 | 32 | extern int proc_log(const char *name); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /ylib/include/round_journal.h: -------------------------------------------------------------------------------- 1 | #ifndef __ROUND_JOURNAL_H__ 2 | #define __ROUND_JOURNAL_H__ 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /ylib/include/squeue.h: -------------------------------------------------------------------------------- 1 | #ifndef __SQUEUE_H__ 2 | #define __SQUEUE_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifndef __CYGWIN__ 9 | 10 | #endif 11 | 12 | #include "sdfs_list.h" 13 | #include "htable.h" 14 | #include "sdfs_id.h" 15 | #include "sdfs_conf.h" 16 | #include "dbg.h" 17 | 18 | typedef struct { 19 | htable_t *table; 20 | struct list_head list; 21 | } squeue_t; 22 | 23 | typedef struct { 24 | struct list_head hook; 25 | void *ent; 26 | } squeue_entry_t; 27 | 28 | int squeue_init(squeue_t *queue, int group, int (*cmp_func)(const void *,const void *), 29 | uint32_t (*hash_func)(const void *)); 30 | int squeue_insert(squeue_t *queue, const void *id, void *_ent); 31 | int squeue_get(squeue_t *queue, const void *id, void **_ent); 32 | int squeue_getfirst(squeue_t *queue, void **_ent); 33 | int squeue_remove(squeue_t *queue, const void *id, void **_ent); 34 | int squeue_move_tail(squeue_t *queue, const void *id); 35 | int squeue_pop(squeue_t *queue, void **_ent); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ylib/include/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIMER_H__ 2 | #define __TIMER_H__ 3 | 4 | #include "ytime.h" 5 | #include "worker.h" 6 | #include "adt.h" 7 | 8 | typedef int (*resume_func)(void *ctx, int retval); 9 | 10 | typedef int (*timer_exec_t)(void *); 11 | 12 | int timer_init(int private, int polling); 13 | void timer_destroy(); 14 | int timer_insert(const char *name, void *ctx, func_t func, suseconds_t usec); 15 | void timer_expire(void *ctx); 16 | 17 | int timer1_create(worker_handler_t *handler, const char *name, timer_exec_t exec, void *_ctx); 18 | 19 | int timer1_settime(const worker_handler_t *handler, uint64_t nsec); 20 | int timer1_settime_retry(const worker_handler_t *handler, uint64_t nsec, int retry); 21 | 22 | #if 0 23 | typedef struct { 24 | worker_handler_t handler; 25 | char name[MAX_NAME_LEN]; 26 | timer_exec_t func; 27 | void *arg; 28 | int free_arg; 29 | uint64_t nsec; 30 | int count; 31 | } easy_timer_t; 32 | 33 | int easy_timer_init(easy_timer_t *timer, const char *name, timer_exec_t func, void *arg, 34 | uint64_t nsec, int count, int free_arg); 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ylib/include/tpool.h: -------------------------------------------------------------------------------- 1 | #ifndef __TPOLL_H__ 2 | #define __TPOLL_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_list.h" 8 | #include "ylib.h" 9 | #include "ylock.h" 10 | 11 | typedef void *(*tpool_worker)(void *); 12 | 13 | typedef struct { 14 | sem_t sem; 15 | time_t last_left; 16 | sy_spinlock_t lock; 17 | int total; 18 | int left; 19 | int idle; 20 | time_t last_threads; 21 | char name[MAX_NAME_LEN]; 22 | tpool_worker worker; 23 | void *context; 24 | } tpool_t; 25 | 26 | 27 | int tpool_init(tpool_t *tpool, tpool_worker worker, void *context, const char *name, int idle_thread); 28 | int tpool_left(tpool_t *tpool); 29 | void tpool_return(tpool_t *tpool); 30 | void tpool_increase(tpool_t *tpool); 31 | int tpool_wait(tpool_t *tpool); 32 | 33 | #endif /* __TPOOL_H__ */ 34 | -------------------------------------------------------------------------------- /ylib/include/worker.h: -------------------------------------------------------------------------------- 1 | #ifndef __WORKER_H__ 2 | #define __WORKER_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_list.h" 8 | #include "job.h" 9 | #include "analysis.h" 10 | #include "ylock.h" 11 | 12 | #define WORKER_TYPE_TIMER 1 13 | #define WORKER_TYPE_SEM 2 14 | 15 | typedef struct { 16 | int fd; 17 | int type; 18 | } worker_handler_t; 19 | 20 | typedef int (*worker_exec_t)(void *); 21 | typedef int (*worker_queue_t)(void *, const void *); 22 | 23 | //extern worker_handler_t jobtracker; 24 | 25 | int worker_init(void); 26 | int worker_settime(const worker_handler_t *handler, uint64_t nsec); 27 | int worker_queue(const worker_handler_t *handler, const void *arg); 28 | int worker_post(const worker_handler_t *handler); 29 | int worker_create(worker_handler_t *handler, const char *name, 30 | worker_exec_t exec, worker_queue_t queue, void *ctx, 31 | int type, int multi); 32 | 33 | #endif 34 | 35 | 36 | -------------------------------------------------------------------------------- /ylib/include/ylock.h: -------------------------------------------------------------------------------- 1 | #ifndef __YLOCK_H__ 2 | #define __YLOCK_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "sdfs_list.h" 8 | #include "sdfs_id.h" 9 | 10 | #define MAX_LOCK_NAME 128 11 | 12 | extern int __sy_spin_lock(pthread_spinlock_t *lock, const char *name); 13 | 14 | #if 1 15 | 16 | #define sy_spinlock_t pthread_spinlock_t 17 | 18 | #define sy_spin_init(__spin__) \ 19 | pthread_spin_init(__spin__, PTHREAD_PROCESS_PRIVATE) 20 | 21 | #define sy_spin_destroy pthread_spin_destroy 22 | #if 0 23 | #define sy_spin_lock(lock) __sy_spin_lock(lock, __FUNCTION__) 24 | #else 25 | #define sy_spin_lock pthread_spin_lock 26 | #endif 27 | #define sy_spin_trylock pthread_spin_trylock 28 | #define sy_spin_unlock pthread_spin_unlock 29 | 30 | #endif 31 | 32 | 33 | 34 | #define SCHEDULE 35 | 36 | #ifdef SCHEDULE 37 | 38 | #if 1 39 | #define LOCK_DEBUG 0 40 | #endif 41 | 42 | typedef struct { 43 | pthread_rwlock_t lock; 44 | struct list_head queue; 45 | sy_spinlock_t spin; 46 | uint32_t priority; 47 | #ifdef LOCK_DEBUG 48 | int32_t count; 49 | uint32_t last_unlock; 50 | task_t writer; 51 | char name[MAX_LOCK_NAME]; 52 | #endif 53 | } sy_rwlock_t; 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /ylib/include/ylog.h: -------------------------------------------------------------------------------- 1 | #ifndef __YLOG_H__ 2 | #define __YLOG_H__ 3 | 4 | #include 5 | #ifndef __CYGWIN__ 6 | #include 7 | #endif 8 | #include 9 | 10 | #include "ylock.h" 11 | #include "sdfs_list.h" 12 | 13 | typedef enum { 14 | YLOG_STDERR, 15 | YLOG_FILE, 16 | YLOG_SYSLOG, 17 | } logmode_t; 18 | 19 | typedef struct { 20 | int logfd; 21 | int count; 22 | time_t time; 23 | sy_rwlock_t lock; 24 | logmode_t logmode; 25 | } ylog_t; 26 | 27 | typedef enum { 28 | YLOG_TYPE_STD, /*standard log optput*/ 29 | YLOG_TYPE_PERF, /*performance log optput*/ 30 | YLOG_TYPE_BALANCE, /*balance log type*/ 31 | YLOG_TYPE_RAMDISK, /*ramdisk log type, record each io crc */ 32 | YLOG_TYPE_MAX, 33 | } logtype_t; 34 | 35 | extern ylog_t *ylog; 36 | 37 | extern int ylog_init(logmode_t, const char *file); 38 | extern int ylog_destroy(void); 39 | extern int ylog_write(logtype_t type, const char *msg); 40 | 41 | #define YROC_ROOT "/dev/shm/uss/proc" 42 | #define FILEMODE (S_IREAD | S_IWRITE | S_IRGRP | S_IROTH) 43 | 44 | int yroc_create(const char *, int *); 45 | int yroc_write(int, const void *, size_t); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /ylib/include/ypath.h: -------------------------------------------------------------------------------- 1 | #ifndef __YPATH_H__ 2 | #define __YPATH_H__ 3 | 4 | #include "sdfs_list.h" 5 | 6 | typedef struct { 7 | struct list_head list; 8 | off_t d_off; 9 | char d_name[0]; 10 | } df_dir_list_t; 11 | 12 | #endif /* __YPATH_H__ */ 13 | -------------------------------------------------------------------------------- /ylib/include/ytime.h: -------------------------------------------------------------------------------- 1 | #ifndef __YTIME_H__ 2 | #define __YTIME_H__ 3 | 4 | #define ytime_t uint64_t /*time in microsecond*/ 5 | 6 | ytime_t ytime_gettime(); 7 | int ytime_getntime(struct timespec *ntime); 8 | void ytime_2ntime(ytime_t ytime, struct timespec *ntime); 9 | struct tm *localtime_safe(time_t *_time, struct tm *tm_time); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ylib/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${PROJECT_SOURCE_DIR}/parser/include 3 | ${PROJECT_SOURCE_DIR}/ylib/include 4 | ) 5 | link_directories(${PROJECT_BINARY_DIR}/lib) 6 | 7 | set(MOD_EXTRA_LIBS pthread aio) 8 | 9 | set(MOD_SRCS job_dock.c async.c aiowp.c auth.c array_table.c 10 | buffer.c bitmap.c cmp.c crc32.c crcrs.c daemon.c 11 | dbg.c hash.c hash_table.c htable.c itab.c itab1.c cache.c 12 | job_tracker.c journal.c lock.c mem.c nls.c nls/nls_cp936.c 13 | path.c pipe_pool.c skiplist.c shm.c stat.c str.c 14 | sysutil.c timer.c xdr.c ylog.c ypool.c ytime.c bmap.c 15 | dynarray.c privilege.c proc.c md5.c squeue.c round_journal.c 16 | analysis.c heap.c) 17 | 18 | # add_library(ylib ${MOD_SRCS}) 19 | # target_link_libraries(ylib ${MOD_EXTRA_LIBS}) 20 | 21 | add_library(ylib ${MOD_SRCS}) 22 | target_link_libraries(ylib ${MOD_EXTRA_LIBS}) 23 | # set_target_properties(ylib PROPERTIES OUTPUT_NAME "ylib") 24 | set_target_properties(ylib PROPERTIES VERSION 1.0 SOVERSION 1) 25 | 26 | install(TARGETS ylib 27 | ARCHIVE DESTINATION app/lib 28 | LIBRARY DESTINATION app/lib 29 | RUNTIME DESTINATION app/sbin 30 | ) 31 | -------------------------------------------------------------------------------- /ylib/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libylib.la 2 | 3 | libylib_la_SOURCES = \ 4 | job_dock.c \ 5 | config.c \ 6 | auth.c \ 7 | array_table.c \ 8 | buffer.c \ 9 | ec_isa_l.c \ 10 | bitmap.c \ 11 | cmp.c \ 12 | crc32.c \ 13 | crcrs.c \ 14 | daemon.c \ 15 | dbg.c \ 16 | hash.c \ 17 | hash_table.c \ 18 | htable.c \ 19 | cache.c \ 20 | job_tracker.c \ 21 | journal.c \ 22 | lock.c \ 23 | mem.c \ 24 | nls.c \ 25 | nls/nls_cp936.c \ 26 | path.c \ 27 | pipe_pool.c \ 28 | skiplist.c \ 29 | shm.c \ 30 | stat.c \ 31 | str.c \ 32 | sysutil.c \ 33 | timer.c \ 34 | xdr.c \ 35 | ylog.c \ 36 | tpool.c \ 37 | ytime.c \ 38 | bmap.c \ 39 | dynarray.c \ 40 | privilege.c \ 41 | md5.c \ 42 | squeue.c \ 43 | round_journal.c \ 44 | analysis.c \ 45 | heap.c \ 46 | mini_hashtb.c\ 47 | bh.c 48 | 49 | AM_LDFLAGS = @LDFLAGS@ \ 50 | -L../../parser/lib 51 | 52 | libylib_la_LIBADD = -lparser -laio -lisal 53 | 54 | -------------------------------------------------------------------------------- /ylib/lib/cmp.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define DBG_SUBSYS S_LIBYLIBSKIPLIST 4 | 5 | #include "sdfs_id.h" 6 | #include "ylib.h" 7 | #include "dbg.h" 8 | 9 | int nid_cmp(const nid_t *keyid, const nid_t *dataid) 10 | { 11 | int ret; 12 | 13 | if (keyid->id < dataid->id) 14 | ret = -1; 15 | else if (keyid->id > dataid->id) 16 | ret = 1; 17 | else { 18 | ret = 0; 19 | } 20 | 21 | return ret; 22 | } 23 | 24 | int verid64_cmp(const verid64_t *keyid, const verid64_t *dataid) 25 | { 26 | int ret; 27 | 28 | if (keyid->id < dataid->id) 29 | ret = -1; 30 | else if (keyid->id > dataid->id) 31 | ret = 1; 32 | else { 33 | ret = 0; 34 | } 35 | 36 | return ret; 37 | } 38 | 39 | 40 | int verid64_void_cmp(const void *keyid, const void *dataid) 41 | { 42 | 43 | return verid64_cmp((verid64_t *)keyid, (verid64_t *)dataid); 44 | } 45 | 46 | int nid_void_cmp(const void *keyid, const void *dataid) 47 | { 48 | return nid_cmp((nid_t *)keyid, (nid_t *)dataid); 49 | } 50 | -------------------------------------------------------------------------------- /ylib/lib/crcrs.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define DBG_SUBSYS S_LIBYLIB 4 | 5 | 6 | -------------------------------------------------------------------------------- /ylib/lib/hash.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | #define DBG_SUBSYS S_LIBYLIB 6 | 7 | #include "dbg.h" 8 | 9 | /* 10 | * the famous DJB hash function for strings 11 | */ 12 | uint32_t hash_str(const char *str) 13 | { 14 | uint32_t hash = 5381; 15 | const char *s; 16 | 17 | for (s = str; *s; s++) 18 | hash = ((hash << 5) + hash) + *s; 19 | 20 | hash &= ~(1 << 31); /* strip the highest bit */ 21 | 22 | return hash; 23 | } 24 | 25 | uint32_t hash_mem(const void *mem, int size) 26 | { 27 | uint32_t hash = 5381; 28 | const char *s = mem; 29 | int i; 30 | 31 | for (i = 0; i < size; i++) 32 | hash = ((hash << 5) + hash) + s[i]; 33 | 34 | hash &= ~(1 << 31); 35 | 36 | return hash; 37 | } 38 | -------------------------------------------------------------------------------- /ylib/lib/nls.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define DBG_SUBSYS S_LIBYLIBNLS 4 | 5 | #include 6 | 7 | #include "sysutil.h" 8 | #include "nls.h" 9 | #include "dbg.h" 10 | 11 | struct nls_table *nls_tables = NULL; 12 | 13 | inline void nls_register(struct nls_table *nls) 14 | { 15 | nls->next = nls_tables; 16 | nls_tables = nls; 17 | } 18 | 19 | extern struct nls_table *nls_cp936; 20 | 21 | int nls_loadall(void) 22 | { 23 | nls_register(nls_cp936); 24 | 25 | return 0; 26 | }; 27 | 28 | int nls_getable(char *charset, struct nls_table **t) 29 | { 30 | int ret; 31 | struct nls_table *nls; 32 | 33 | for (nls = nls_tables; nls; nls = nls->next) { 34 | if (_strcmp(nls->charset, charset) == 0) 35 | break; 36 | 37 | if (nls->alias && (_strcmp(nls->alias, charset))) 38 | break; 39 | } 40 | 41 | if (nls == NULL) { 42 | ret = ENOENT; 43 | GOTO(err_ret, ret); 44 | } 45 | 46 | *t = nls; 47 | 48 | return 0; 49 | err_ret: 50 | return ret; 51 | } 52 | -------------------------------------------------------------------------------- /ylib/lib/privilege.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define DBG_SUBSYS S_LIBYLIB 10 | 11 | #include "sysutil.h" 12 | #include "privilege.h" 13 | #include "dbg.h" 14 | 15 | int grant(const char *username, const char* group) 16 | { 17 | struct passwd *pwd; 18 | struct group *grp; 19 | uid_t user_id; 20 | gid_t group_id; 21 | int ret; 22 | 23 | if(_strcmp(username, "") == 0 || _strcmp(group, "") == 0) { 24 | ret = EINVAL; 25 | GOTO(err_ret, ret); 26 | } 27 | 28 | if(((pwd = getpwnam(username)) == NULL) || ((grp = getgrnam(group)) == NULL)) { 29 | ret = ENOENT; 30 | GOTO(err_ret, ret); 31 | } 32 | 33 | user_id = pwd->pw_uid; 34 | group_id = grp->gr_gid; 35 | 36 | if(setgid(group_id) || setegid(group_id) || setuid(user_id) || seteuid(user_id)) { 37 | ret = errno; 38 | GOTO(err_ret, ret); 39 | } 40 | 41 | return 0; 42 | err_ret: 43 | return ret; 44 | } 45 | -------------------------------------------------------------------------------- /ylib/lib/ytime.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define DBG_SUBSYS S_LIBYLIB 9 | 10 | #include "ylib.h" 11 | #include "ytime.h" 12 | #include "dbg.h" 13 | 14 | #define TIME_ZONE 8 15 | 16 | ytime_t ytime_gettime() 17 | { 18 | int ret; 19 | struct timeval tv; 20 | 21 | ret = _gettimeofday(&tv, NULL); 22 | if (ret) 23 | YASSERT(0); 24 | 25 | return tv.tv_sec * 1000000 + tv.tv_usec; 26 | } 27 | 28 | int ytime_getntime(struct timespec *ntime) 29 | { 30 | int ret; 31 | struct timeval tv; 32 | 33 | ret = _gettimeofday(&tv, NULL); 34 | if (ret) 35 | GOTO(err_ret, ret); 36 | 37 | ntime->tv_sec = tv.tv_sec; 38 | ntime->tv_nsec = tv.tv_usec * 1000; 39 | 40 | return 0; 41 | err_ret: 42 | return ret; 43 | } 44 | 45 | void ytime_2ntime(ytime_t ytime, struct timespec *ntime) 46 | { 47 | ntime->tv_sec = ytime / 1000000; 48 | ntime->tv_nsec = (ytime % 1000000) * 1000; 49 | } 50 | -------------------------------------------------------------------------------- /ylib/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = \ 2 | path \ 3 | crc32 \ 4 | cmd_test 5 | 6 | crc32_SOURCES = crc32.c 7 | 8 | path_SOURCES = path.c 9 | 10 | cmd_test_SOURCES = cmd_test.c 11 | #splice_SOURCES = splice.c 12 | 13 | heap_test_SOURCES = heap_test.c 14 | 15 | AM_LDFLAGS = @LDFLAGS@ \ 16 | -L../../parser/lib -lparser \ 17 | -L../lib -lylib \ 18 | -lpthread -lcrypto -lcrypt -luuid -laio -lssl 19 | -------------------------------------------------------------------------------- /ylib/tests/skiplist_test.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "skiplist_row.h" 11 | 12 | //#define MAX_LEVEL 48 13 | 14 | SKIPLIST_CREATE(int, uint64_t, NULL, 10); 15 | 16 | int main() 17 | { 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /ynet/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /ynet/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([ynet],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -W -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../ylib/include" 21 | 22 | LIBS=-lpthread 23 | 24 | AC_CHECK_FUNCS([pthread_rwlock_init]) 25 | 26 | subdirs=" \ 27 | include \ 28 | build \ 29 | " 30 | 31 | AC_SUBST(subdirs) 32 | 33 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 34 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 35 | 36 | AC_CONFIG_FILES([ \ 37 | Makefile \ 38 | include/Makefile \ 39 | build/Makefile \ 40 | tests/Makefile \ 41 | ]) 42 | 43 | AC_OUTPUT 44 | -------------------------------------------------------------------------------- /ynet/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/ynet/include/Makefile.am -------------------------------------------------------------------------------- /ynet/include/conn.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONN_H__ 2 | #define __CONN_H__ 3 | 4 | int conn_init(); 5 | int conn_retry(const nid_t *_nid); 6 | int conn_register(); 7 | int conn_getinfo(const nid_t *nid, ynet_net_info_t *info); 8 | int conn_setinfo(); 9 | int conn_online(const nid_t *nid, int timeout); 10 | int conn_faultdomain(int *_total, int *_online); 11 | int conn_listnode(nid_t *array, int *_count); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /ynet/include/main_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_LOOP_H__ 2 | #define __MAIN_LOOP_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "net_proto.h" 9 | #include "../sock/ynet_sock.h" 10 | #include "ylock.h" 11 | 12 | extern int __main_loop_hold__; 13 | 14 | void main_loop_start(); 15 | int main_loop_create(int threads); 16 | void main_loop_hold(); 17 | int main_loop_check(); 18 | 19 | int main_loop_request(void (*exec)(void *buf), void *buf, const char *name); 20 | int main_loop_event(int sd, int event, int op); 21 | 22 | #if 1 23 | #define main_loop_hold() \ 24 | do { \ 25 | int __i__ = 0; \ 26 | while (__main_loop_hold__) { \ 27 | sleep(1); \ 28 | DINFO("main_loop_hold %u\n", __i__++); \ 29 | } \ 30 | } while (0); 31 | #else 32 | #define main_loop_hold() 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ynet/include/maping.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAPING_H__ 2 | #define __MAPING_H__ 3 | 4 | /*from maping.c*/ 5 | 6 | #include "ynet_net.h" 7 | 8 | #define HOST2NID "network/host2nid" 9 | #define NID2NETINFO "network/nid2netinfo" 10 | #define NAME2NID "storage/name2nid" 11 | #define ID2NID "storage/id2nid" 12 | #define ROOT "storage/root" 13 | #define ID2NAME "storage/id2name" 14 | #define NAME2ADDR "storage/name2addr" 15 | #define MAPING_MISC "misc" 16 | 17 | int maping_init(void); 18 | int maping_nid2netinfo(const nid_t *nid, ynet_net_info_t *info); 19 | int maping_cleanup(const char *type); 20 | int maping_host2nid(const char *hostname, nid_t *nid); 21 | int maping_addr2nid(const char *addr, nid_t *nid); 22 | int maping_nid2host(const nid_t *nid, char *hostname); 23 | int maping_getmaster(nid_t *nid, int force); 24 | int maping_set(const char *type, const char *_key, const char *value); 25 | int maping_get(const char *type, const char *_key, char *value, time_t *ctime); 26 | int maping_drop(const char *type, const char *_key); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /ynet/include/msgqueue.h: -------------------------------------------------------------------------------- 1 | #ifndef __MSGQUEUE_H__ 2 | #define __MSGQUEUE_H__ 3 | 4 | #include "net_proto.h" 5 | 6 | #define MSGQUEUE_SEG_LEN 10485760 7 | #define MSGQUEUE_SEG_COUNT_MAX 64 8 | 9 | typedef struct { 10 | int fd; 11 | uint32_t woff; 12 | uint32_t roff; 13 | } msgqueue_seg_t; 14 | 15 | typedef struct { 16 | sy_rwlock_t rwlock; 17 | ynet_net_nid_t nid; 18 | char home[MAX_PATH_LEN]; 19 | uint32_t idx; 20 | msgqueue_seg_t seg[MSGQUEUE_SEG_COUNT_MAX]; 21 | } msgqueue_t; 22 | 23 | typedef struct { 24 | uint32_t len; 25 | uint32_t crc; 26 | char buf[0]; 27 | } msgqueue_msg_t; 28 | 29 | #define msg_for_each(msg, left) \ 30 | for (; left && (unsigned)left > msg->len; \ 31 | left -= (msg->len + sizeof(msgqueue_msg_t)), \ 32 | msg = (void *)msg + msg->len + sizeof(msgqueue_msg_t)) 33 | 34 | 35 | int msgqueue_init(msgqueue_t *queue, const char *path, const nid_t *nid); 36 | int msgqueue_push(msgqueue_t *queue, const void *_msg, uint32_t len); 37 | int msgqueue_get(msgqueue_t *queue, void *msg, uint32_t len); 38 | int msgqueue_pop(msgqueue_t *queue, void *msg, uint32_t len); 39 | int msgqueue_load(msgqueue_t *queue, const char *path, const nid_t *nid); 40 | int msgqueue_empty(msgqueue_t *queue); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /ynet/include/netbios_passive.h: -------------------------------------------------------------------------------- 1 | #ifndef __NETBIOS_PASSIVE_H__ 2 | #define __NETBIOS_PASSIVE_H__ 3 | 4 | #include 5 | 6 | #include "job.h" 7 | #include "sdevent.h" 8 | 9 | extern int netbios_tcp_passive(uint32_t *port); 10 | void netbios_procedure_register(const char *name, net_request_handler handler); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /ynet/include/netbios_reply.h: -------------------------------------------------------------------------------- 1 | #ifndef __NETBIOS_REPLY_H__ 2 | #define __NETBIOS_REPLY_H__ 3 | 4 | #include "job.h" 5 | #include "netbios_proto.h" 6 | #include "xdr.h" 7 | 8 | int netbios_reply_prep1(job_t *job, void **buf, int wc, int bc, int status); 9 | int netbios_reply_send(job_t *job, buffer_t *buf, mbuffer_op_t op); 10 | int netbios_reply_error(job_t *job, int retval); 11 | int netbios_andx_reply_prep(job_t *job); 12 | int netbios_andx_reply_append_word(job_t *job, void *buf, int add); 13 | int netbios_andx_reply_append_byte(job_t *job, int count, ...); 14 | void netbios_andx_reply_setree(job_t *job, int treeid); 15 | int netbios_reply_prep(job_t *job, smb_head_t **_head); 16 | int netbios_reply_append(job_t *job, void **ptr, int add); 17 | int netbios_reply_append_word(job_t *job, void **ptr, int add); 18 | int netbios_reply_append_byte(job_t *job, void **ptr, int add); 19 | int netbios_reply_append1(job_t *job, void **word, char wc, 20 | void **byte, uint16_t bc); 21 | #endif 22 | -------------------------------------------------------------------------------- /ynet/include/network.h: -------------------------------------------------------------------------------- 1 | #ifndef __NETWORK_H__ 2 | #define __NETWORK_H__ 3 | 4 | #include 5 | 6 | #include "ynet_net.h" 7 | #include "job_dock.h" 8 | #include "adt.h" 9 | #include "etcd.h" 10 | #include "sdfs_conf.h" 11 | #include "net_global.h" 12 | 13 | /*network.c*/ 14 | int network_init(void); 15 | 16 | int network_connect_mond(int force); 17 | int network_connect(const nid_t *nid, time_t *_ltime, int _timeout, int force); 18 | int network_connect_wait(const nid_t *nid, time_t *_ltime, int _timeout, int force); 19 | 20 | int network_connect_byname(const char *name, nid_t *nid); 21 | 22 | void network_ltime_reset(const nid_t *nid, time_t ltime, const char *why); 23 | int network_ltime(const nid_t *nid, time_t *ltime); 24 | time_t network_ltime1(const nid_t *nid); 25 | 26 | const char *network_rname(const nid_t *nid); 27 | int network_rname1(const nid_t *nid, char *name); 28 | 29 | void network_close(const nid_t *nid, const char *why, const time_t *ltime); 30 | 31 | //just for compatible, will be removed 32 | int network_connect2(const net_handle_t *nh, int force); 33 | int network_connect1(const nid_t *nid); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ynet/include/nodeid.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODEID__ 2 | #define __NODEID__ 3 | 4 | #include 5 | 6 | typedef uint32_t nodeid_t; //instence id 7 | #define NODEID_MAX (UINT16_MAX * 4) 8 | 9 | //int nodeid_newid(nodeid_t *id, const char *name); 10 | int nodeid_drop(nodeid_t id); 11 | int nodeid_used(nodeid_t id); 12 | int nodeid_init(nodeid_t *_id, const char *name); 13 | int nodeid_load(nodeid_t *_id); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ynet/include/sunrpc_passive.h: -------------------------------------------------------------------------------- 1 | #ifndef __SUNRPC_PASSIVE_H__ 2 | #define __SUNRPC_PASSIVE_H__ 3 | 4 | //#include 5 | 6 | #include "job.h" 7 | #include "sdevent.h" 8 | 9 | extern int sunrpc_tcp_passive(const char *port); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ynet/include/sunrpc_reply.h: -------------------------------------------------------------------------------- 1 | #ifndef __SUNRPC_REPLY_H__ 2 | #define __SUNRPC_REPLY_H__ 3 | 4 | #include "job.h" 5 | #include "xdr.h" 6 | 7 | int sunrpc_reply(const sockid_t *sockid, const sunrpc_request_t *req, 8 | int state, void *res, xdr_ret_t xdr_ret); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ynet/include/ynet.h: -------------------------------------------------------------------------------- 1 | #ifndef __YNET_H__ 2 | #define __YNET_H__ 3 | 4 | #include "ynet_conf.h" 5 | #include "ynet_net.h" 6 | #include "ynet_rpc.h" 7 | #include "network.h" 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /ynet/include/ynet_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YNET_CONF_H__ 2 | #define __YNET_CONF_H__ 3 | 4 | #define MAX_NODENAME_LEN 16 5 | #define MAX_SERVICENAME_LEN 16 6 | 7 | #define YNET_QLEN 256 8 | 9 | #define RPC_EPOLL_SIZE 8192 10 | 11 | #define YNET_LOCALHOST "127.0.0.1" 12 | 13 | #define YNET_TRANSPORT "tcp" 14 | 15 | #define YNET_RPC_NONBLOCK 1 16 | #define YNET_RPC_BLOCK 0 17 | 18 | #define YNET_RPC_TUNNING 1 19 | #define YNET_RPC_NONTUNNING 0 20 | 21 | #define YNET_SOCK_MAX 10 22 | 23 | #define YNET_NID_NULL 0 24 | #define YNET_VERSION_NULL 0 25 | #define YNET_NID_ERROR (-2) 26 | 27 | /* 28 | * http://www.iana.org/assignments/port-numbers 29 | * 30 | * The Dynamic and/or Private Ports are those from 49152 through 65535 31 | */ 32 | 33 | #define YNET_SERVICE_BASE 49152 34 | 35 | #define YNET_SERVICE_RANGE (65535 - 49152) 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /ynet/net/heartbeat.h: -------------------------------------------------------------------------------- 1 | #ifndef __HEART_BEAT_H__ 2 | #define __HEART_BEAT_H__ 3 | 4 | #include "ynet_net.h" 5 | 6 | int heartbeat_add(const sockid_t *sockid, const nid_t *parent, suseconds_t timeout, time_t ltime); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /ynet/net/net_events.h: -------------------------------------------------------------------------------- 1 | #ifndef __NET_EVENTS_H__ 2 | #define __NET_EVENTS_H__ 3 | 4 | #include "sdevent.h" 5 | 6 | int net_events_handle_read(void *sock, void *ctx); 7 | int net_events_handle_write(event_t *ev, void *ctx); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ynet/net/net_rpc.h: -------------------------------------------------------------------------------- 1 | #ifndef __NET_RPC_H__ 2 | #define __NET_RPC_H__ 3 | 4 | #include "job_dock.h" 5 | #include "net_global.h" 6 | 7 | int net_rpc_heartbeat(const sockid_t *sockid, uint64_t seq); 8 | int net_rpc_coreinfo(const nid_t *nid, char *infobuf, int *infobuflen); 9 | int net_rpc_init(void); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ynet/net/net_xmit.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define DBG_SUBSYS S_LIBYNET 8 | 9 | #include "../sock/ynet_sock.h" 10 | #include "job.h" 11 | #include "job_dock.h" 12 | #include "net_table.h" 13 | #include "configure.h" 14 | #include "net_global.h" 15 | #include "ynet_net.h" 16 | #include "dbg.h" 17 | 18 | #if 0 19 | inline int net_recv_sd(int sd, void **rep, int timeout) 20 | { 21 | return sock_recv_sd_malloc(sd, rep, timeout); 22 | } 23 | 24 | inline int net_peek_sd_sync(int sd, char *buf, uint32_t buflen, int timeout) 25 | { 26 | return sock_peek_sd_sync(sd, buf, buflen, timeout); 27 | } 28 | 29 | inline int net_discard_sd_sync(int sd, uint32_t len, int timeout) 30 | { 31 | return sock_discard_sd_sync(sd, len, timeout); 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /ynet/net/net_xnect.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | #define DBG_SUBSYS S_LIBYNET 7 | 8 | #include "../sock/ynet_sock.h" 9 | #include "net_global.h" 10 | #include "ynet_net.h" 11 | #include "xnect.h" 12 | #include "ylib.h" 13 | #include "configure.h" 14 | #include "net_table.h" 15 | #include "dbg.h" 16 | 17 | inline int net_hostconnect(int *sd, const char *host, const char *service, int nonblock) 18 | { 19 | return sock_hostconnect(sd, host, service, nonblock, gloconf.rpc_timeout / 3); 20 | } 21 | 22 | inline int net_info2nid(net_handle_t *nh, const ynet_net_info_t *info) 23 | { 24 | return netable_connect_info(nh, info, 1); 25 | } 26 | 27 | int net_nid2info(ynet_net_info_t *info, uint32_t *buflen, const net_handle_t *nid) 28 | { 29 | int ret; 30 | 31 | ret = netable_getinfo(&nid->u.nid, info, buflen); 32 | if (ret) 33 | GOTO(err_ret, ret); 34 | 35 | return 0; 36 | err_ret: 37 | return ret; 38 | } 39 | -------------------------------------------------------------------------------- /ynet/net/xnect.h: -------------------------------------------------------------------------------- 1 | #ifndef __XNECT_H__ 2 | #define __XNECT_H__ 3 | 4 | #include "ynet_net.h" 5 | 6 | int net_accept(net_handle_t *nh, ynet_net_info_t *info, const net_proto_t *proto); 7 | int net_connect(net_handle_t *nh, const ynet_net_info_t *info, int timeout); 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ynet/rpc/rpc_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __RPC_PROTO_H__ 2 | #define __RPC_PROTO_H__ 3 | 4 | #include "sdevent.h" 5 | #include "mem_cache.h" 6 | #include "job.h" 7 | 8 | typedef struct { 9 | nid_t nid; 10 | sockid_t sockid; 11 | msgid_t msgid; 12 | buffer_t buf; 13 | void *ctx; 14 | } rpc_request_t; 15 | 16 | int rpc_pack_handler(const nid_t *nid, const sockid_t *sockid, buffer_t *buf); 17 | int rpc_pack_len(void *buf, uint32_t len, int *msg_len, int *io_len); 18 | 19 | typedef int (*__request_handler_func__)(const sockid_t *sockid, const msgid_t *msgid, buffer_t *buf); 20 | #define __RPC_HANDLER_NAME__ 128 21 | 22 | inline static void request_trans(void *arg, nid_t *nid, sockid_t *sockid, msgid_t *msgid, buffer_t *buf, void **ctx) 23 | { 24 | rpc_request_t *rpc_request; 25 | 26 | rpc_request = arg; 27 | YASSERT(rpc_request->sockid.addr); 28 | //YASSERT(rpc_request->sockid.sd); 29 | //YASSERT(rpc_request->sockid.seq); 30 | 31 | mbuffer_init(buf, 0); 32 | mbuffer_merge(buf, &rpc_request->buf); 33 | *msgid = rpc_request->msgid; 34 | *sockid = rpc_request->sockid; 35 | 36 | if (nid) 37 | *nid = rpc_request->nid; 38 | if (ctx) 39 | *ctx = rpc_request->ctx; 40 | 41 | mem_cache_free(MEM_CACHE_128, rpc_request); 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /ynet/sock/sock_udp.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOCK_UDP_H__ 2 | #define __SOCK_UDP_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "ynet_sock.h" 9 | 10 | int udp_sock_listen(int *srv_sd, const char *host, const char *service, int nonblock); 11 | int udp_sock_broadcast(int sd, uint32_t net, uint32_t mask, uint32_t port, const void *buf, int buflen); 12 | int udp_sock_connect(int *srv_sd, const char *host, const char *service, int nonblock); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ynet/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = \ 2 | msgqueue_cp \ 3 | msgqueue_write \ 4 | msgqueue_read 5 | 6 | 7 | #test_proxy_SOURCES = proxy.c 8 | #test_listener_SOURCES = listener.c 9 | #test_speaker_SOURCES = speaker.c 10 | msgqueue_cp_SOURCES = msgqueue_cp.c 11 | msgqueue_write_SOURCES = msgqueue_write.c 12 | msgqueue_read_SOURCES = msgqueue_read.c 13 | 14 | AM_LDFLAGS = @LDFLAGS@ \ 15 | -L../../ynet/build -lynet \ 16 | -L../../ylib/lib -lylib \ 17 | -lpthread -lcrypt -luuid -laio -lssl 18 | -------------------------------------------------------------------------------- /yweb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(src) 2 | -------------------------------------------------------------------------------- /yweb/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = @subdirs@ 2 | 3 | EXTRA_DIST = \ 4 | README* 5 | -------------------------------------------------------------------------------- /yweb/configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT([yweb],[0.0.1]) 2 | AC_CANONICAL_TARGET 3 | AM_INIT_AUTOMAKE 4 | AC_CONFIG_HEADERS([include/config.h]) 5 | 6 | AC_PROG_CC 7 | AC_PROG_LIBTOOL 8 | AC_PROG_INSTALL 9 | 10 | case $target_os in 11 | *linux*) arch=linux;; 12 | *bsd*) arch=bsd;; 13 | *) arch=unknown;; 14 | esac 15 | 16 | if test "$ac_env_CFLAGS_set" != set; then 17 | CFLAGS="-Wall -W -g" 18 | fi 19 | 20 | CPPFLAGS="$CPPFLAGS -W -Wall -D_GNU_SOURCE -D_REENTRANT -I../../parser/include -I../../ynet/include -I../../ylib/include/ -I../../yfs/include/" 21 | 22 | subdirs=" \ 23 | include \ 24 | src \ 25 | " 26 | 27 | AC_SUBST(subdirs) 28 | 29 | AM_CONDITIONAL(LINUX, test "$arch" = linux) 30 | AM_CONDITIONAL(BSD, test "$arch" = bsd) 31 | 32 | AC_CONFIG_FILES([ \ 33 | Makefile \ 34 | include/Makefile \ 35 | src/Makefile \ 36 | ]) 37 | 38 | AC_OUTPUT 39 | -------------------------------------------------------------------------------- /yweb/include/Makefile.am: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yweb/include/Makefile.am -------------------------------------------------------------------------------- /yweb/include/http_state_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef __YWEB_STATUS_MACHINE_H__ 2 | #define __YWEB_STATUS_MACHINE_H__ 3 | 4 | #include "chk_proto.h" 5 | #include "yfs_chunk.h" 6 | #include "net_global.h" 7 | 8 | typedef enum { 9 | HTTP_REQ_COMING, 10 | HTTP_REQ_READING, 11 | HTTP_REP_GET 12 | } yweb_status; 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /yweb/include/yweb_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __YWEB_CONF_H__ 2 | #define __YWEB_CONF_H__ 3 | 4 | #define YWEB_SERVICE_DEF "80" 5 | #define YWEB_QLEN_DEF 256 6 | 7 | #define YWEB_LOCKFILE "/dev/shm/uss/yweb/lock/yweb" 8 | #define YWEB_PIDFILE "/dev/shm/uss/yweb/lock/yweb.pid" 9 | 10 | #define YWEB_LOGFILE "/var/log/yweb.log" 11 | 12 | #define YWEB_EPOLL_SIZE 1024 13 | 14 | #define YWEB_THR_MAX 1024 15 | 16 | /* "\012" "\n" */ 17 | /* "\015" "\r" */ 18 | 19 | #define HTTP_REQ_END1 "\015\012\015\012" 20 | #define HTTP_REQ_END2 "\012\012" 21 | 22 | #define YWEB_CHARSET_DEF "iso-8859-1" 23 | 24 | #define SERVER_SOFTWARE "httpd/uss-1.9.10" 25 | #define SERVER_URL "http://www.meidisen.com/" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /yweb/src/Makefile.am: -------------------------------------------------------------------------------- 1 | sbin_PROGRAMS=yweb_server 2 | 3 | yweb_server_SOURCES = \ 4 | mime.c \ 5 | str.c \ 6 | match.c \ 7 | tdate_parse.c \ 8 | request.c \ 9 | response.c \ 10 | http_ops.c \ 11 | http_proto.c \ 12 | http_readdir.c \ 13 | main.c \ 14 | http_state_machine.c 15 | 16 | AM_LDFLAGS = @LDFLAGS@ \ 17 | -L../../parser/lib -lparser \ 18 | -L../../yfs/build -lyfs \ 19 | -L../../ynet/build -lynet \ 20 | -L../../ylib/lib -lylib \ 21 | -lpthread -lcrypt -luuid -laio -lssl 22 | 23 | mime.c: mime_encodings.h mime_types.h 24 | 25 | mime_encodings.h: mime_encodings.txt 26 | rm -f mime_encodings.h 27 | sed < mime_encodings.txt > mime_encodings.h \ 28 | -e 's/#.*//' -e 's/[ ]*$$//' -e '/^$$/d' \ 29 | -e 's/[ ][ ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/' 30 | 31 | mime_types.h: mime_types.txt 32 | rm -f mime_types.h 33 | sed < mime_types.txt > mime_types.h \ 34 | -e 's/#.*//' -e 's/[ ]*$$//' -e '/^$$/d' \ 35 | -e 's/[ ][ ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/' 36 | -------------------------------------------------------------------------------- /yweb/src/http_ops.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_OPS_H__ 2 | #define __HTTP_OPS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "request.h" 9 | #include "job.h" 10 | 11 | /** send general response to client. 12 | * @param code response code 13 | * @param sd client socket 14 | */ 15 | extern int http_send_response(struct http_request *req, int code, buffer_t *rep); 16 | 17 | extern int http_send_ok(struct http_request *req, char *me, char *mt, 18 | struct stat *st, buffer_t *rep); 19 | extern int http_send_nomod(struct http_request *req, char *me, char *mt, 20 | time_t mtime, buffer_t *rep); 21 | extern int http_send_error(struct http_request *req, int err, char* title, 22 | char* extra_header, char* text, buffer_t *rep); 23 | extern int http_send_badreq(struct http_request *req, buffer_t *rep); 24 | extern int http_reply_send(job_t *job, buffer_t *buf, mbuffer_op_t op); 25 | 26 | extern void add_listhead(struct http_request *req, buffer_t *rep); 27 | 28 | extern void add_listbody(char *filename, char *date, uint64_t size, buffer_t *rep); 29 | 30 | extern void add_errtail(struct http_request *req, buffer_t *rep); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /yweb/src/http_proto.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_PROTO_H__ 2 | #define __HTTP_PROTO_H__ 3 | 4 | extern int http_listen(const char* port, int nonblock); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /yweb/src/http_state_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_STATE_MACHINE__ 2 | #define __HTTP_STATE_MACHINE__ 3 | 4 | #include "request.h" 5 | #include "ynet_rpc.h" 6 | 7 | 8 | typedef struct { 9 | fileid_t fileid; 10 | struct aiocb iocb; 11 | buffer_t buf; 12 | //char buf[MAX_BUF_LEN];/*request buf*/ 13 | struct http_request http_req; 14 | off_t offset; 15 | off_t size; 16 | } http_job_context_t; 17 | 18 | 19 | enum { 20 | HTTP_GET_BEGIN, 21 | HTTP_GET_READ, 22 | HTTP_GET_WAIT_READ, 23 | HTTP_GET_WAIT_SEND, 24 | HTTP_GET_DONE, 25 | HTTP_GET_ERROR, 26 | }; 27 | 28 | extern int http_state_machine_get(job_t *job, char *); 29 | extern int http_state_machine_error(job_t *, char *); 30 | #endif 31 | -------------------------------------------------------------------------------- /yweb/src/match.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yweb/src/match.h -------------------------------------------------------------------------------- /yweb/src/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef __MIME_H__ 2 | #define __MIME_H__ 3 | 4 | struct mime_entry { 5 | char *ext; 6 | size_t ext_len; 7 | char *val; 8 | size_t val_len; 9 | }; 10 | 11 | extern void mime_init(void); 12 | extern void mime_getype(char* name, char* me, size_t me_size, char **type); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /yweb/src/mime_encodings.txt: -------------------------------------------------------------------------------- 1 | # mime_encodings.txt 2 | # 3 | # A list of file extensions followed by the corresponding MIME encoding. 4 | # Extensions not found in the table proceed to the mime_types table. 5 | 6 | Z compress 7 | gz gzip 8 | uu x-uuencode 9 | -------------------------------------------------------------------------------- /yweb/src/response.h: -------------------------------------------------------------------------------- 1 | #ifndef __RESPONSE_H__ 2 | #define __RESPONSE_H__ 3 | 4 | #include 5 | 6 | struct http_response { 7 | uint32_t size; 8 | uint32_t len; 9 | uint32_t idx; 10 | char *buf; 11 | }; 12 | 13 | extern void start_response(struct http_response *rep); 14 | extern int append_response(struct http_response *rep, char *buf, uint32_t len); 15 | extern int send_response(struct http_response *rep, int sd); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /yweb/src/str.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | #define DBG_SUBSYS S_YWEB 6 | 7 | #include "dbg.h" 8 | 9 | static int hexit(char c) 10 | { 11 | if (c >= '0' && c <= '9') 12 | return c - '0'; 13 | 14 | if (c >= 'a' && c <= 'f') 15 | return c - 'a' + 10; 16 | 17 | if (c >= 'A' && c <= 'F') 18 | return c - 'A' + 10; 19 | 20 | return 0; 21 | } 22 | 23 | void str_decode(char *to, char *from) 24 | { 25 | for (; *from != '\0'; ++to, ++from) { 26 | if (from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) { 27 | *to = hexit(from[1]) * 16 + hexit(from[2]); 28 | from += 2; 29 | } else 30 | *to = *from; 31 | } 32 | 33 | *to = '\0'; 34 | } 35 | -------------------------------------------------------------------------------- /yweb/src/str.h: -------------------------------------------------------------------------------- 1 | #ifndef __STR_H__ 2 | #define __STR_H__ 3 | 4 | /* 5 | * copies and decodes a string 6 | * it's ok for 'from' and 'to' to be the same string 7 | */ 8 | extern void str_decode(char *to, char *from); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /yweb/src/tdate_parse.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fusionstack/sdfs/505735b61e5c1924dd1c8637993d56d4a23be715/yweb/src/tdate_parse.h -------------------------------------------------------------------------------- /yweb/tests/wget.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | while [ 1 ]; do 4 | curl --connect-timeout 8 --tcp-nodelay --output /dev/null \ 5 | --url http://192.168.1.1[3-5]:8080/[1-9].jpg 6 | done 7 | --------------------------------------------------------------------------------