From: Michal L. <lu...@us...> - 2006-09-23 09:29:49
|
Update of /cvsroot/mysqlfs/mysqlfs In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv472 Modified Files: pool.c query.c query.h schema.sql ChangeLog Log Message: 2006-09-23 Michal Ludvig <mi...@lo...> * Create root directory on startup if it doesn't exist. * Changed timestamp fields in 'inodes' table to 'int unsigned' to avoid conversion between MYSQL timestamp and Unix timestamp in a number of queries. * Updated schema.sql. Now with autocreating '/' it's enough to use 'mysqldump -d' i.e. dump just the schema without data. Index: query.h =================================================================== RCS file: /cvsroot/mysqlfs/mysqlfs/query.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** query.h 13 Sep 2006 02:58:23 -0000 1.7 --- query.h 23 Sep 2006 09:29:44 -0000 1.8 *************** *** 36,37 **** --- 36,38 ---- int query_purge_deleted(MYSQL *mysql, long inode); + int query_fsck(MYSQL *mysql); Index: schema.sql =================================================================== RCS file: /cvsroot/mysqlfs/mysqlfs/schema.sql,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** schema.sql 13 Sep 2006 02:58:23 -0000 1.4 --- schema.sql 23 Sep 2006 09:29:44 -0000 1.5 *************** *** 3,7 **** -- Host: localhost Database: mysqlfs -- ------------------------------------------------------ ! -- Server version 5.0.22-Debian_0ubuntu6.06.2-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; --- 3,7 ---- -- Host: localhost Database: mysqlfs -- ------------------------------------------------------ ! -- Server version 5.0.22-Debian_0ubuntu6.06.2 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; *************** *** 25,39 **** `data` longblob NOT NULL, PRIMARY KEY (`inode`) ! ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ! ! -- ! -- Dumping data for table `data` ! -- ! ! ! /*!40000 ALTER TABLE `data` DISABLE KEYS */; ! LOCK TABLES `data` WRITE; ! UNLOCK TABLES; ! /*!40000 ALTER TABLE `data` ENABLE KEYS */; -- --- 25,29 ---- `data` longblob NOT NULL, PRIMARY KEY (`inode`) ! ) ENGINE=MyISAM DEFAULT CHARSET=binary; -- *************** *** 46,69 **** `inuse` int(11) NOT NULL default '0', `deleted` tinyint(4) NOT NULL default '0', ! `mode` int(11) default NULL, `uid` int(10) unsigned NOT NULL default '0', `gid` int(10) unsigned NOT NULL default '0', ! `atime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, ! `mtime` timestamp NOT NULL default '0000-00-00 00:00:00', ! `ctime` timestamp NOT NULL default '0000-00-00 00:00:00', `size` bigint(20) NOT NULL default '0', ! PRIMARY KEY (`inode`) ! ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ! ! -- ! -- Dumping data for table `inodes` ! -- ! ! ! /*!40000 ALTER TABLE `inodes` DISABLE KEYS */; ! LOCK TABLES `inodes` WRITE; ! INSERT INTO `inodes` VALUES (1,0,0,16895,0,0,'2006-09-12 05:25:03','0000-00-00 00:00:00','0000-00-00 00:00:00',0); ! UNLOCK TABLES; ! /*!40000 ALTER TABLE `inodes` ENABLE KEYS */; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; --- 36,49 ---- `inuse` int(11) NOT NULL default '0', `deleted` tinyint(4) NOT NULL default '0', ! `mode` int(11) NOT NULL default '0', `uid` int(10) unsigned NOT NULL default '0', `gid` int(10) unsigned NOT NULL default '0', ! `atime` int(10) unsigned NOT NULL default '0', ! `mtime` int(10) unsigned NOT NULL default '0', ! `ctime` int(10) unsigned NOT NULL default '0', `size` bigint(20) NOT NULL default '0', ! PRIMARY KEY (`inode`), ! KEY `inode` (`inode`,`inuse`,`deleted`) ! ) ENGINE=MyISAM DEFAULT CHARSET=binary; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; *************** *** 85,101 **** `name` varchar(255) NOT NULL, UNIQUE KEY `name` (`name`,`parent`), ! KEY `inode` (`inode`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; - - -- - -- Dumping data for table `tree` - -- - - - /*!40000 ALTER TABLE `tree` DISABLE KEYS */; - LOCK TABLES `tree` WRITE; - INSERT INTO `tree` VALUES (1,NULL,'/'); - UNLOCK TABLES; - /*!40000 ALTER TABLE `tree` ENABLE KEYS */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; --- 65,71 ---- `name` varchar(255) NOT NULL, UNIQUE KEY `name` (`name`,`parent`), ! KEY `inode` (`inode`), ! KEY `parent` (`parent`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; Index: query.c =================================================================== RCS file: /cvsroot/mysqlfs/mysqlfs/query.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** query.c 13 Sep 2006 10:54:37 -0000 1.14 --- query.c 23 Sep 2006 09:29:44 -0000 1.15 *************** *** 41,45 **** snprintf(sql, SQL_MAX, ! "SELECT inode, mode, uid, gid, UNIX_TIMESTAMP(atime), UNIX_TIMESTAMP(mtime) " "FROM inodes WHERE inode=%ld", inode); --- 41,45 ---- snprintf(sql, SQL_MAX, ! "SELECT inode, mode, uid, gid, atime, mtime " "FROM inodes WHERE inode=%ld", inode); *************** *** 249,265 **** char *name, esc_name[PATH_MAX * 2]; ! name = strrchr(path, '/'); ! if (!name || *++name == '\0') ! return -ENOENT; ! mysql_real_escape_string(mysql, esc_name, name, strlen(name)); ! snprintf(sql, SQL_MAX, ! "INSERT INTO tree (name, parent) VALUES ('%s', %ld)", ! esc_name, parent); ! log_printf(LOG_D_SQL, "sql=%s\n", sql); ! ret = mysql_query(mysql, sql); ! if(ret) ! goto err_out; new_inode_number = mysql_insert_id(mysql); --- 249,275 ---- char *name, esc_name[PATH_MAX * 2]; ! if (path[0] == '/' && path[1] == '\0') { ! snprintf(sql, SQL_MAX, ! "INSERT INTO tree (name, parent) VALUES ('/', NULL)"); ! log_printf(LOG_D_SQL, "sql=%s\n", sql); ! ret = mysql_query(mysql, sql); ! if(ret) ! goto err_out; ! } else { ! name = strrchr(path, '/'); ! if (!name || *++name == '\0') ! return -ENOENT; ! mysql_real_escape_string(mysql, esc_name, name, strlen(name)); ! snprintf(sql, SQL_MAX, ! "INSERT INTO tree (name, parent) VALUES ('%s', %ld)", ! esc_name, parent); ! ! log_printf(LOG_D_SQL, "sql=%s\n", sql); ! ret = mysql_query(mysql, sql); ! if(ret) ! goto err_out; ! } new_inode_number = mysql_insert_id(mysql); *************** *** 267,271 **** snprintf(sql, SQL_MAX, "INSERT INTO inodes(inode, mode, uid, gid, atime, ctime, mtime)" ! "VALUES(%ld, %d, %d, %d, NOW(), NOW(), NOW())", new_inode_number, mode, fuse_get_context()->uid, fuse_get_context()->gid); --- 277,282 ---- snprintf(sql, SQL_MAX, "INSERT INTO inodes(inode, mode, uid, gid, atime, ctime, mtime)" ! "VALUES(%ld, %d, %d, %d, UNIX_TIMESTAMP(NOW()), " ! "UNIX_TIMESTAMP(NOW()), UNIX_TIMESTAMP(NOW()))", new_inode_number, mode, fuse_get_context()->uid, fuse_get_context()->gid); *************** *** 385,389 **** snprintf(sql, SQL_MAX, "UPDATE inodes " ! "SET atime=FROM_UNIXTIME(%ld), mtime=FROM_UNIXTIME(%ld) " "WHERE inode=%lu", time->actime, time->modtime, inode); --- 396,400 ---- snprintf(sql, SQL_MAX, "UPDATE inodes " ! "SET atime=%ld, mtime=%ld " "WHERE inode=%lu", time->actime, time->modtime, inode); *************** *** 695,696 **** --- 706,712 ---- } + int query_fsck(MYSQL *mysql) + { + // See TODO file for what should be here... + return 0; + } Index: pool.c =================================================================== RCS file: /cvsroot/mysqlfs/mysqlfs/pool.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pool.c 17 Sep 2006 11:09:32 -0000 1.9 --- pool.c 23 Sep 2006 09:29:44 -0000 1.10 *************** *** 18,23 **** --- 18,25 ---- #include <pthread.h> + #include <fuse/fuse.h> #include <mysql/mysql.h> + #include "query.h" #include "pool.h" #include "log.h" *************** *** 76,79 **** --- 78,113 ---- } + static int pool_check_mysql_setup(MYSQL *mysql) + { + int ret = 0; + + /* Check the server version. */ + unsigned long mysql_version; + mysql_version = mysql_get_server_version(mysql); + if (mysql_version < MYSQL_MIN_VERSION) { + log_printf(LOG_ERROR, "Your server version is %s. " + "Version %lu.%lu.%lu or higher is required.\n", + mysql_get_server_info(mysql), + MYSQL_MIN_VERSION/10000L, + (MYSQL_MIN_VERSION%10000L)/100, + MYSQL_MIN_VERSION%100L); + ret = -ENOENT; + goto out; + } + + /* Create root directory if it doesn't exist. */ + ret = query_inode_full(mysql, "/", NULL, 0, NULL, NULL, NULL); + if (ret == -ENOENT) + ret = query_mkdir(mysql, "/", 0755, 0); + if (ret < 0) + goto out; + + /* Cleanup. */ + ret = query_fsck(mysql); + + out: + return ret; + } + /****************************************** * Pool DB-independent (almost) functions * *************** *** 130,134 **** int pool_init(struct mysqlfs_opt *opt_arg) { ! int i; log_printf(LOG_D_POOL, "%s()\n", __func__); --- 164,168 ---- int pool_init(struct mysqlfs_opt *opt_arg) { ! int i, ret; log_printf(LOG_D_POOL, "%s()\n", __func__); *************** *** 149,168 **** } ! /* Check the server version and some required records. */ ! unsigned long mysql_version; ! mysql_version = mysql_get_server_version(mysql); ! if (mysql_version < MYSQL_MIN_VERSION) { ! log_printf(LOG_ERROR, "Your server version is %s. " ! "Version %lu.%lu.%lu or higher is required.\n", ! mysql_get_server_info(mysql), ! MYSQL_MIN_VERSION/10000L, ! (MYSQL_MIN_VERSION%10000L)/100, ! MYSQL_MIN_VERSION%100L); ! pool_put(mysql); ! return -ENOENT; ! } pool_put(mysql); ! return 0; } --- 183,191 ---- } ! ret = pool_check_mysql_setup(mysql); ! pool_put(mysql); ! return ret; } Index: ChangeLog =================================================================== RCS file: /cvsroot/mysqlfs/mysqlfs/ChangeLog,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ChangeLog 17 Sep 2006 11:21:16 -0000 1.12 --- ChangeLog 23 Sep 2006 09:29:44 -0000 1.13 *************** *** 1,2 **** --- 1,12 ---- + 2006-09-23 Michal Ludvig <mi...@lo...> + + * Create root directory on startup if it doesn't exist. + * Changed timestamp fields in 'inodes' table to 'int + unsigned' to avoid conversion between MYSQL timestamp and + Unix timestamp in a number of queries. + * Updated schema.sql. Now with autocreating '/' it's enough + to use 'mysqldump -d' i.e. dump just the schema without + data. + 2006-09-17 Michal Ludvig <mi...@lo...> |